Open Jon-AtAWS opened 1 day ago
One mystery solved. If I add a sleep statement after loading the data and after creating the memory, then I get the same error as I get in dev tools:
Traceback (most recent call last):
File "/Users/handler/code/gdata/converse.py", line 184, in <module>
response = os_client.search(index='converse', body=
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/client/utils.py", line 176, in _wrapped
return func(*args, params=params, headers=headers, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/client/__init__.py", line 2364, in search
return self.transport.perform_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/transport.py", line 455, in perform_request
raise e
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/transport.py", line 416, in perform_request
status, headers_response, data = connection.perform_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/connection/http_urllib3.py", line 308, in perform_request
self._raise_error(
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/connection/base.py", line 315, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
opensearchpy.exceptions.TransportError: TransportError(500, 'runtime_exception', 'Context text not found in search hit {\n "_index" : "converse",\n "_id" : "oW58A5IBrpFbJSuYGAC0",\n "_score" : 13.451588,\n "_source" : {\n "question_id" : "Tx1S3K9MJ9OVLJI",\n "question_text" : "Is andi faded blue",\n "asin" : "B004G9Q83E",\n "bullet_point1" : "Sits below waist",\n "bullet_point2" : "Slim through seat and thigh",\n "bullet_point3" : "Boot cut leg",\n "bullet_point4" : "",\n "bullet_point5" : "",\n "product_description" : "",\n "brand_name" : "Levi\'s",\n "item_name" : "Levi\'s Mens 527 Bootcut Jean, Andi, 30-32",\n "question_type" : "yes-no",\n "answer_aggregated" : "no",\n "answers" : [\n {\n "answer_text" : "It is more of a navy. It looks a little faded, but is not light."\n },\n {\n "answer_text" : "no"\n },\n {\n "answer_text" : "No, these are a dark wash"\n }\n ]\n }\n}')
Second mystery solved. I changed the definition of the search pipeline to use 'question_text' in the context_field_list
.
response = os_client.transport.perform_request('PUT', f'/_search/pipeline/rag_pipeline',
body={
"response_processors": [
{
"retrieval_augmented_generation": {
"tag": "conversation demo",
"description": "Demo pipeline Using Bedrock Connector",
"model_id": f"{model_id}",
"context_field_list": ["question_text"],
"system_prompt": "You are a helpful assistant",
"user_instructions": "Generate a concise and informative answer in less than 100 words for the given question"
}
}
]
})
Now I get this error
Traceback (most recent call last):
File "/Users/handler/code/gdata/converse.py", line 184, in <module>
response = os_client.search(index='converse', body=
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/client/utils.py", line 176, in _wrapped
return func(*args, params=params, headers=headers, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/client/__init__.py", line 2364, in search
return self.transport.perform_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/transport.py", line 455, in perform_request
raise e
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/transport.py", line 416, in perform_request
status, headers_response, data = connection.perform_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/connection/http_urllib3.py", line 308, in perform_request
self._raise_error(
File "/Users/handler/code/gdata/.venv/lib/python3.11/site-packages/opensearchpy/connection/base.py", line 315, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
opensearchpy.exceptions.RequestError: RequestError(400, 'status_exception', 'Error validating input schema: Validation failed: [$.parameters: required property \'inputs\' not found] for instance: {"algorithm":"REMOTE","parameters":{"messages":"[{\\"role\\":\\"system\\",\\"content\\":\\"You are a helpful assistant\\"},{\\"role\\":\\"user\\",\\"content\\":\\"Generate a concise and informative answer in less than 100 words for the given question\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 1: Is andi faded blue\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 2: I can\'t tell from the photos if these jeans are a faded black or a faded blue?\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 3: Looking for slightly faded jeans for casual Friday at the office - not dark blue. Any suggestions?\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 4: Which color is the darkest without faded streaks or faded wrinkles \\\\\\\\\\\\\\"?\\\\\\\\\\\\\\"\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 5: Are any of the denim blue colors solid rather than faded in spots like is so popular now?\\"},{\\"role\\":\\"user\\",\\"content\\":\\"QUESTION: faded old blue jeans\\"},{\\"role\\":\\"user\\",\\"content\\":\\"ANSWER:\\"}]","model":"anthropic.claude-v2"},"action_type":null} with schema: {\n "type": "object",\n "properties": {\n "parameters": {\n "type": "object",\n "properties": {\n "inputs": {\n "type": "string"\n }\n },\n "required": [\n "inputs"\n ]\n }\n },\n "required": [\n "parameters"\n ]\n}')
So it's correctly pulling the context. Looks like I need inputs.
One more turn on this... it's confusing, I used the bedrock connector blueprint from here, but that one's wrong for conversational search. Anyway, there's no parameters.inputs there. So I changed the connector to look like the one on the docs page, by changing the request body to:
request_body = json.dumps({
"model": "${parameters.model}",
"messages": "${parameters.messages}",
"temperature": "${parameters.temperature}"
})
And the connector to
response = os_client.transport.perform_request('POST', '/_plugins/_ml/connectors/_create',
body={
"name": "Amazon Bedrock",
"description": "Test connector for Amazon Bedrock",
"version": 1,
"protocol": "aws_sigv4",
"credential": {
"access_key": session['Credentials']['AccessKeyId'],
"secret_key": session['Credentials']['SecretAccessKey'],
"session_token": session['Credentials']['SessionToken']
},
"parameters": {
"region": f"{REGION}",
"service_name": "bedrock",
"model": "anthropic.claude-v2"
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"headers": {
"content-type": "application/json"
},
"url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke",
"request_body": request_body
}
]
})
But that gives:
opensearchpy.exceptions.RequestError: RequestError(400, 'status_exception', 'Error validating input schema: Validation failed: [$.parameters: required property \'inputs\' not found] for instance: {"algorithm":"REMOTE","parameters":{"messages":"[{\\"role\\":\\"system\\",\\"content\\":\\"You are a helpful assistant\\"},{\\"role\\":\\"user\\",\\"content\\":\\"Generate a concise and informative answer in less than 100 words for the given question\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 1: Is andi faded blue\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 2: I can\'t tell from the photos if these jeans are a faded black or a faded blue?\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 3: Looking for slightly faded jeans for casual Friday at the office - not dark blue. Any suggestions?\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 4: Which color is the darkest without faded streaks or faded wrinkles \\\\\\\\\\\\\\"?\\\\\\\\\\\\\\"\\"},{\\"role\\":\\"user\\",\\"content\\":\\"SEARCH RESULT 5: Are any of the denim blue colors solid rather than faded in spots like is so popular now?\\"},{\\"role\\":\\"user\\",\\"content\\":\\"QUESTION: faded old blue jeans\\"},{\\"role\\":\\"user\\",\\"content\\":\\"ANSWER:\\"}]","model":"anthropic.claude-v2"},"action_type":null} with schema: {\n "type": "object",\n "properties": {\n "parameters": {\n "type": "object",\n "properties": {\n "inputs": {\n "type": "string"\n }\n },\n "required": [\n "inputs"\n ]\n }\n },\n "required": [\n "parameters"\n ]\n}')
Hi @Jon-AtAWS ! You are receiving this error because model interface for anthropic.claude-v2
model requires that inputs
parameter must be specified. I am running with the DEBUG mode, and find the actual response is:
{
"algorithm" : "REMOTE",
"parameters" : {
"messages" : "[{\"role\":\"system\",\"content\":[{\"type\":\"text\",\"text\":\"You are a helpful assistant\"}]},{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"Generate a concise and informative answer in less than 100 words for the given question\"},{\"type\":\"text\",\"text\":\"QUESTION: faded old blue jeans\\n\"},{\"type\":\"text\",\"text\":\"ANSWER:\"}]}]",
"model" : "anthropic.claude-v2"
},
"action_type" : null
}
This response is formatted from generative_qa_parameters
, namely the JAVA class GenerativeQAResponseProcessor
.
According to https://github.com/opensearch-project/ml-commons/blob/2.x/docs/remote_inference_blueprints/bedrock_connector_anthropic_claude_blueprint.md, it is correct to require inputs
for the claude v2 model. Taking a deep dive into the GenerativeQAResponseProcessor
.
I found the root cause. The requests will be formatted from chatCompletionInput
into a Map within function getInputParameters
. Since OpenAI models and other model APIs differ in request format, getInputParameters
treated them differently according to modelProvider. Unfortunately, anthropic.claude-v2
are classified into the OpenAI models.
@Jon-AtAWS , I think you should use
"generative_qa_parameters": {
"llm_model": "bedrock/claude",
@Jon-AtAWS I would suggest a quick workaround:
response = os_client.search(index='converse', body=
{
"query": {
"match": {
"question_text": "old faded blue jeans",
}
},
"ext": {
"generative_qa_parameters": {
"llm_model": "anthropic.claude-v2",
"llm_question": "faded old blue jeans",
"context_size": 5,
"message_size": 5,
"timeout": 15,
"llm_response_field": "completion"
}
}
})
What is the bug? This query:
Gives the following error
I followed the documentation here: https://opensearch.org/docs/latest/search-plugins/conversational-search/ and created the following code:
How can one reproduce the bug? Steps to reproduce the behavior: The above code will reproduce the error. The data came from https://registry.opendata.aws/amazon-pqa/
What is the expected behavior? I should get a text response from the model
What is your host/environment?
Do you have any screenshots? N/A
Additional context If I run the following in Dev Tools, I get a different error