From b073571de658e2623ad1a68fa417004d9e0146cd Mon Sep 17 00:00:00 2001 From: Nathalie Jonathan Date: Tue, 7 Jan 2025 16:01:38 -0800 Subject: [PATCH] Added ML create, update, get, search message, and get message traces APIs, updated max_score schema type and test description in memory/update.yaml. Signed-off-by: Nathalie Jonathan --- CHANGELOG.md | 2 +- spec/namespaces/ml.yaml | 209 +++++++++++++++++++- spec/schemas/ml._common.yaml | 103 +++++++++- tests/plugins/ml/ml/memory/update.yaml | 2 +- tests/plugins/ml/ml/message/create.yaml | 35 ++++ tests/plugins/ml/ml/message/get.yaml | 50 +++++ tests/plugins/ml/ml/message/get_traces.yaml | 41 ++++ tests/plugins/ml/ml/message/search.yaml | 58 ++++++ tests/plugins/ml/ml/message/update.yaml | 46 +++++ 9 files changed, 540 insertions(+), 6 deletions(-) create mode 100644 tests/plugins/ml/ml/message/create.yaml create mode 100644 tests/plugins/ml/ml/message/get.yaml create mode 100644 tests/plugins/ml/ml/message/get_traces.yaml create mode 100644 tests/plugins/ml/ml/message/search.yaml create mode 100644 tests/plugins/ml/ml/message/update.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 360b30618..67fc0dc14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `GET /_plugins/_ml/connectors/{connector_id}`, `_search`, `POST /_plugins/_ml/connectors/_search`, and `PUT /_plugins/_ml/connectors/{connector_id}` ([#764](https://github.com/opensearch-project/opensearch-api-specification/pull/764)) - Added the ability to skip an individual chapter test ([#765](https://github.com/opensearch-project/opensearch-api-specification/pull/765)) - Added uploading of test spec logs ([#767](https://github.com/opensearch-project/opensearch-api-specification/pull/767)) -- Added `POST /_plugins/_ml/memory`, `PUT /_plugins/_ml/memory/{memory_id}`, `GET /_plugins/_ml/memory`, `GET /_plugins/_ml/memory/{memory_id}`, `_search`, `POST /_plugins/_ml/memory/_search`, and `DELETE /_plugins/_ml/memory/{memory_id}` ([#771](https://github.com/opensearch-project/opensearch-api-specification/pull/771)) +- Added `POST /_plugins/_ml/memory`, `POST /_plugins/_ml/memory/_search`, `{memory_id}/_search`, `{memory_id}/messages`, `PUT /_plugins/_ml/memory/{memory_id}`, `message/{message_id}`, `GET /_plugins/_ml/memory`, `GET /_plugins/_ml/memory/{memory_id}`, `_search`, `message/{message_id}`, `{memory_id}/messages`, `{memory_id}/_search`, `message/{message_id}/traces`, and `DELETE /_plugins/_ml/memory/{memory_id}` ([#771](https://github.com/opensearch-project/opensearch-api-specification/pull/771)) ### Removed - Removed unsupported `_common.mapping:SourceField`'s `mode` field and associated `_common.mapping:SourceFieldMode` enum ([#652](https://github.com/opensearch-project/opensearch-api-specification/pull/652)) diff --git a/spec/namespaces/ml.yaml b/spec/namespaces/ml.yaml index 262de7fcb..f4cef1311 100644 --- a/spec/namespaces/ml.yaml +++ b/spec/namespaces/ml.yaml @@ -332,6 +332,88 @@ paths: responses: '200': $ref: '#/components/responses/ml.search_memory@200' + /_plugins/_ml/memory/{memory_id}/messages: + get: + operationId: ml.get_message.0 + x-operation-group: ml.get_message + x-version-added: '2.12' + description: Get a message. + parameters: + - $ref: '#/components/parameters/ml.get_message::path.memory_id' + responses: + '200': + $ref: '#/components/responses/ml.get_message@200' + post: + operationId: ml.create_message.0 + x-operation-group: ml.create_message + x-version-added: '2.12' + description: Create a message. + parameters: + - $ref: '#/components/parameters/ml.create_message::path.memory_id' + requestBody: + $ref: '#/components/requestBodies/ml.create_message' + responses: + '200': + $ref: '#/components/responses/ml.create_message@200' + /_plugins/_ml/memory/message/{message_id}: + get: + operationId: ml.get_message.1 + x-operation-group: ml.get_message + x-version-added: '2.12' + description: Get a message. + parameters: + - $ref: '#/components/parameters/ml.get_message::path.message_id' + responses: + '200': + $ref: '#/components/responses/ml.get_message@200' + put: + operationId: ml.update_message.0 + x-operation-group: ml.update_message + x-version-added: '2.12' + description: Update a message. + parameters: + - $ref: '#/components/parameters/ml.update_message::path.message_id' + requestBody: + $ref: '#/components/requestBodies/ml.update_message' + responses: + '200': + $ref: '#/components/responses/ml.update_message@200' + /_plugins/_ml/memory/{memory_id}/_search: + get: + operationId: ml.search_message.0 + x-operation-group: ml.search_message + x-version-added: '2.12' + description: Search messages. + parameters: + - $ref: '#/components/parameters/ml.search_message::path.memory_id' + requestBody: + $ref: '#/components/requestBodies/ml.search_message' + responses: + '200': + $ref: '#/components/responses/ml.search_message@200' + post: + operationId: ml.search_message.1 + x-operation-group: ml.search_message + x-version-added: '2.12' + description: Search messages. + parameters: + - $ref: '#/components/parameters/ml.search_message::path.memory_id' + requestBody: + $ref: '#/components/requestBodies/ml.search_message' + responses: + '200': + $ref: '#/components/responses/ml.search_message@200' + /_plugins/_ml/memory/message/{message_id}/traces: + get: + operationId: ml.get_message_traces.0 + x-operation-group: ml.get_message_traces + x-version-added: '2.12' + description: Get a message traces. + parameters: + - $ref: '#/components/parameters/ml.get_message_traces::path.message_id' + responses: + '200': + $ref: '#/components/responses/ml.get_message_traces@200' components: requestBodies: ml.register_model_group: @@ -671,6 +753,63 @@ components: items: $ref: '../schemas/ml._common.yaml#/components/schemas/SortMemory' description: The sort order. + ml.create_message: + content: + application/json: + schema: + type: object + properties: + input: + type: string + description: The question in the message. + prompt_template: + type: string + description: The prompt template. + response: + type: string + description: The answer to the question. + origin: + type: string + description: The system name that generated the response. + additional_info: + $ref: '../schemas/ml._common.yaml#/components/schemas/AdditionalInfo' + ml.update_message: + content: + application/json: + schema: + type: object + properties: + input: + type: string + description: The question in the message. + prompt_template: + type: string + description: The prompt template. + response: + type: string + description: The answer to the question. + origin: + type: string + description: The system name that generated the response. + additional_info: + $ref: '../schemas/ml._common.yaml#/components/schemas/AdditionalInfo' + ml.search_message: + content: + application/json: + schema: + type: object + properties: + query: + $ref: '../schemas/ml._common.yaml#/components/schemas/Query' + size: + type: integer + format: int64 + description: The number of messages to return. + sort: + type: array + items: + $ref: '../schemas/ml._common.yaml#/components/schemas/SortMessage' + description: The sort order. responses: ml.register_model_group@200: content: @@ -818,7 +957,9 @@ components: type: object properties: memory_id: - type: string + $ref: '../schemas/_common.yaml#/components/schemas/Name' + required: + - memory_id ml.update_memory@200: content: application/json: @@ -840,6 +981,36 @@ components: application/json: schema: $ref: '../schemas/ml._common.yaml#/components/schemas/SearchMemoryResponse' + ml.create_message@200: + content: + application/json: + schema: + type: object + properties: + message_id: + $ref: '../schemas/_common.yaml#/components/schemas/Name' + required: + - message_id + ml.get_message@200: + content: + application/json: + schema: + $ref: '../schemas/ml._common.yaml#/components/schemas/GetMessageResponse' + ml.update_message@200: + content: + application/json: + schema: + $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' + ml.search_message@200: + content: + application/json: + schema: + $ref: '../schemas/ml._common.yaml#/components/schemas/SearchMessageResponse' + ml.get_message_traces@200: + content: + application/json: + schema: + $ref: '../schemas/ml._common.yaml#/components/schemas/GetMessageTracesResponse' parameters: ml.get_model_group::path.model_group_id: name: model_group_id @@ -953,5 +1124,41 @@ components: name: memory_id in: path required: true + schema: + type: string + ml.create_message::path.memory_id: + name: memory_id + in: path + required: true + schema: + type: string + ml.get_message::path.memory_id: + name: memory_id + in: path + required: true + schema: + type: string + ml.get_message::path.message_id: + name: message_id + in: path + required: true + schema: + type: string + ml.update_message::path.message_id: + name: message_id + in: path + required: true + schema: + type: string + ml.search_message::path.memory_id: + name: memory_id + in: path + required: true + schema: + type: string + ml.get_message_traces::path.message_id: + name: message_id + in: path + required: true schema: type: string \ No newline at end of file diff --git a/spec/schemas/ml._common.yaml b/spec/schemas/ml._common.yaml index 213ffd634..9c416c9a2 100644 --- a/spec/schemas/ml._common.yaml +++ b/spec/schemas/ml._common.yaml @@ -33,8 +33,7 @@ components: items: $ref: '#/components/schemas/SearchHitsHit' max_score: - type: number - format: float + type: ['null', number] description: The maximum score. required: - hits @@ -224,6 +223,26 @@ components: user: type: string description: The username of the user. + input: + type: ['null', string] + description: The question in the message. + memory_id: + $ref: '_common.yaml#/components/schemas/Name' + trace_number: + type: ['null', string] + description: The trace number. + response: + type: ['null', string] + description: The answer to the question. + origin: + type: ['null', string] + description: The system name that generated the response. + parent_message_id: + type: ['null', string] + description: The parent message ID. + prompt_template: + type: ['null', string] + description: The prompt template. ModelConfig: type: object properties: @@ -382,6 +401,8 @@ components: properties: bool: $ref: '#/components/schemas/BoolQuery' + match: + $ref: '#/components/schemas/Match' match_all: $ref: '#/components/schemas/MatchAllQuery' term: @@ -605,6 +626,30 @@ components: $ref: '#/components/schemas/SortOrder' _seq_no: $ref: '#/components/schemas/SortOrder' + SortMessage: + type: object + description: The sort message query. + properties: + additional_info: + $ref: '#/components/schemas/SortOrder' + create_time: + $ref: '#/components/schemas/SortOrder' + memory_id: + $ref: '#/components/schemas/SortOrder' + origin: + $ref: '#/components/schemas/SortOrder' + parent_message_id: + $ref: '#/components/schemas/SortOrder' + trace_number: + $ref: '#/components/schemas/SortOrder' + _id: + $ref: '#/components/schemas/SortOrder' + _index: + $ref: '#/components/schemas/SortOrder' + _score: + $ref: '#/components/schemas/SortOrder' + _seq_no: + $ref: '#/components/schemas/SortOrder' SortOrder: type: object description: The order of the sort. @@ -622,6 +667,7 @@ components: description: type: string description: The description. + additionalProperties: true TrainParameters: type: object properties: @@ -870,6 +916,7 @@ components: type: object description: Additional information query. properties: {} + additionalProperties: true ToolItems: type: object properties: @@ -932,4 +979,54 @@ components: format: int64 description: The index of the first memory in the sorted list of memories. SearchMemoryResponse: - $ref: '#/components/schemas/SearchResponse' \ No newline at end of file + $ref: '#/components/schemas/SearchResponse' + Message: + type: object + properties: + memory_id: + $ref: '_common.yaml#/components/schemas/Name' + message_id: + $ref: '_common.yaml#/components/schemas/Name' + create_time: + type: string + format: date-time + description: The create time. + input: + type: ['null', string] + description: The question in the message. + prompt_template: + type: ['null', string] + description: The prompt template. + response: + type: ['null', string] + description: The answer to the question. + origin: + type: ['null', string] + description: The system name that generated the response. + additional_info: + $ref: '#/components/schemas/AdditionalInfo' + parent_message_id: + type: ['null', string] + description: The parent message ID. + trace_number: + type: integer + format: int64 + description: The trace number. + GetMessageResponse: + oneOf: + - $ref: '#/components/schemas/Message' + - type: object + properties: + messages: + type: array + items: + $ref: '#/components/schemas/Message' + SearchMessageResponse: + $ref: '#/components/schemas/SearchResponse' + GetMessageTracesResponse: + type: object + properties: + traces: + type: array + items: + $ref: '#/components/schemas/Message' \ No newline at end of file diff --git a/tests/plugins/ml/ml/memory/update.yaml b/tests/plugins/ml/ml/memory/update.yaml index 61e20d7dd..d26131c1f 100644 --- a/tests/plugins/ml/ml/memory/update.yaml +++ b/tests/plugins/ml/ml/memory/update.yaml @@ -1,6 +1,6 @@ $schema: ../../../../../json_schemas/test_story.schema.yaml -description: Test updating of a memory. +description: Test updating a memory. version: '>= 2.12' prologues: - path: /_plugins/_ml/memory diff --git a/tests/plugins/ml/ml/message/create.yaml b/tests/plugins/ml/ml/message/create.yaml new file mode 100644 index 000000000..5ec9cd64b --- /dev/null +++ b/tests/plugins/ml/ml/message/create.yaml @@ -0,0 +1,35 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test the creation of a message. +version: '>= 2.12' +prologues: + - path: /_plugins/_ml/memory + id: create_memory + method: POST + request: + payload: + name: Test memory + output: + memory_id: payload.memory_id +epilogues: + - path: /_plugins/_ml/memory/{memory_id} + method: DELETE + status: [200, 404] + parameters: + memory_id: ${create_memory.memory_id} +chapters: + - synopsis: Create a message. + path: /_plugins/_ml/memory/{memory_id}/messages + method: POST + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + input: What is the best selling novel of all time? + prompt_template: Hello OpenAI, can you answer this question? + response: Hello, this is OpenAI. Here is the answer to your question. + origin: MyFirstOpenAIWrapper + additional_info: + suggestion: api.openai.com + response: + status: 200 diff --git a/tests/plugins/ml/ml/message/get.yaml b/tests/plugins/ml/ml/message/get.yaml new file mode 100644 index 000000000..2868c6189 --- /dev/null +++ b/tests/plugins/ml/ml/message/get.yaml @@ -0,0 +1,50 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test the retrieval of a message by ID and all messages. +version: '>= 2.12' +warnings: + multiple-paths-detected: false +prologues: + - path: /_plugins/_ml/memory + id: create_memory + method: POST + request: + payload: + name: Test memory + output: + memory_id: payload.memory_id + - path: /_plugins/_ml/memory/{memory_id}/messages + id: create_message + method: POST + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + input: What is the best selling novel of all time? + prompt_template: Hello OpenAI, can you answer this question? + response: Hello, this is OpenAI. Here is the answer to your question. + additional_info: + suggestion: api.openai.com + output: + message_id: payload.message_id +epilogues: + - path: /_plugins/_ml/memory/{memory_id} + method: DELETE + status: [200, 404] + parameters: + memory_id: ${create_memory.memory_id} +chapters: + - synopsis: Get a message by ID. + path: /_plugins/_ml/memory/message/{message_id} + method: GET + parameters: + message_id: ${create_message.message_id} + response: + status: 200 + - synopsis: Get all messages. + path: /_plugins/_ml/memory/{memory_id}/messages + method: GET + parameters: + memory_id: ${create_memory.memory_id} + response: + status: 200 diff --git a/tests/plugins/ml/ml/message/get_traces.yaml b/tests/plugins/ml/ml/message/get_traces.yaml new file mode 100644 index 000000000..8e267fe54 --- /dev/null +++ b/tests/plugins/ml/ml/message/get_traces.yaml @@ -0,0 +1,41 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test the retrieval of message trace. +version: '>= 2.12' +prologues: + - path: /_plugins/_ml/memory + id: create_memory + method: POST + request: + payload: + name: Test memory + output: + memory_id: payload.memory_id + - path: /_plugins/_ml/memory/{memory_id}/messages + id: create_message + method: POST + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + input: What is the best selling novel of all time? + prompt_template: Hello OpenAI, can you answer this question? + response: Hello, this is OpenAI. Here is the answer to your question. + additional_info: + suggestion: api.openai.com + output: + message_id: payload.message_id +epilogues: + - path: /_plugins/_ml/memory/{memory_id} + method: DELETE + status: [200, 404] + parameters: + memory_id: ${create_memory.memory_id} +chapters: + - synopsis: Get a message trace. + path: /_plugins/_ml/memory/message/{message_id}/traces + method: GET + parameters: + message_id: ${create_message.message_id} + response: + status: 200 \ No newline at end of file diff --git a/tests/plugins/ml/ml/message/search.yaml b/tests/plugins/ml/ml/message/search.yaml new file mode 100644 index 000000000..03b6d7013 --- /dev/null +++ b/tests/plugins/ml/ml/message/search.yaml @@ -0,0 +1,58 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test the search of messages. +version: '>= 2.12' +prologues: + - path: /_plugins/_ml/memory + id: create_memory + method: POST + request: + payload: + name: Test memory + output: + memory_id: payload.memory_id + - path: /_plugins/_ml/memory/{memory_id}/messages + id: create_message + method: POST + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + input: What is the best selling novel of all time? + prompt_template: Hello OpenAI, can you answer this question? + response: Hello, this is OpenAI. Here is the answer to your question. + additional_info: + suggestion: api.openai.com + output: + message_id: payload.message_id +epilogues: + - path: /_plugins/_ml/memory/{memory_id} + method: DELETE + status: [200, 404] + parameters: + memory_id: ${create_memory.memory_id} +chapters: + - synopsis: Search message. + path: /_plugins/_ml/memory/{memory_id}/_search + method: GET + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + query: + match_all: {} + size: 1000 + response: + status: 200 + - synopsis: Search message by matching input. + path: /_plugins/_ml/memory/{memory_id}/_search + method: POST + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + query: + match: + input: novel + response: + status: 200 \ No newline at end of file diff --git a/tests/plugins/ml/ml/message/update.yaml b/tests/plugins/ml/ml/message/update.yaml new file mode 100644 index 000000000..129f354cb --- /dev/null +++ b/tests/plugins/ml/ml/message/update.yaml @@ -0,0 +1,46 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test updating a message. +version: '>= 2.12' +prologues: + - path: /_plugins/_ml/memory + id: create_memory + method: POST + request: + payload: + name: Test memory + output: + memory_id: payload.memory_id + - path: /_plugins/_ml/memory/{memory_id}/messages + id: create_message + method: POST + parameters: + memory_id: ${create_memory.memory_id} + request: + payload: + input: What is the best selling novel of all time? + prompt_template: Hello OpenAI, can you answer this question? + response: Hello, this is OpenAI. Here is the answer to your question. + origin: MyFirstOpenAIWrapper + additional_info: + suggestion: api.openai.com + output: + message_id: payload.message_id +epilogues: + - path: /_plugins/_ml/memory/{memory_id} + method: DELETE + status: [200, 404] + parameters: + memory_id: ${create_memory.memory_id} +chapters: + - synopsis: Update a message. + path: /_plugins/_ml/memory/message/{message_id} + method: PUT + parameters: + message_id: ${create_message.message_id} + request: + payload: + additional_info: + feedback: positive + response: + status: 200