aws-samples / bedrock-claude-chat

AWS-native chatbot using Bedrock + Claude (+Mistral)
MIT No Attribution
883 stars 316 forks source link

[BUG] Issue when calling API's #465

Closed Alexg61 closed 2 months ago

Alexg61 commented 3 months ago

Describe the bug

When created API to call custom BOT, /api/health is returning ok but when calling /api/conversation and provide the example in the API document always receiving this error:

{
    "detail": [
        {
            "type": "model_attributes_type",
            "loc": [
                "body"
            ],
            "msg": "Input should be a valid dictionary or object to extract fields from",
            "input": "{\n    \"conversationId\": null,\n    \"message\": {\n        \"content\": [\n            {\n                \"contentType\": \"text\",\n                \"mediaType\": \"string\",\n                \"body\": \"what is RAG?\"\n            }\n        ],\n        \"model\": \"claude-v3-sonnet\"\n    },\n    \"continueGenerate\": false\n}",
            "url": "https://errors.pydantic.dev/2.7/v/model_attributes_type"
        }
    ]
}

below is the payload i am sending:

{
    "conversationId": null,
    "message": {
        "content": [
            {
                "contentType": "text",
                "mediaType": "string",
                "body": "what is RAG?"
            }
        ],
        "model": "claude-v3-sonnet"
    },
    "continueGenerate": false
}

Can you provide examples how to use each API

Yukinobu-Mine commented 3 months ago

@Alexg61 I tried the payload you provided, but could not reproduce the failure.

Request

curl -v -X POST -H "Content-Type: application/json" -H "X-API-KEY: xxxxxxxx" -d '{"conversationId": null, "message": {"content": [{"contentType": "text", "mediaType": "string", "body": "what is RAG?"}], "model": "claude-v3-sonnet"}, "continueGenerate": false}' https://xxxx.execute-api.ap-northeast-1.amazonaws.com/api/conversation

Response

{
  "conversationId": "xxxx",
  "messageId": "yyyy"
}

Secondary request

curl -v -H "X-API-KEY: xxxxxxxx" https://xxxx.execute-api.ap-northeast-1.amazonaws.com/api/conversation/xxxx/yyyy

Response

{
  "conversationId": "xxxx",
  "message": {
    "role": "assistant",
    "content": [
      {
        "contentType": "text",
        "mediaType": null,
        "fileName": null,
        "body": "RAG stands for Retrieval-Augmented Generation. It is an approach in natural language processing (NLP) that combines the capabilities of large language models with information retrieval from external knowledge sources.\n\nThe key idea behind RAG is to first retrieve relevant information from a knowledge base or corpus of documents, and then use that retrieved information along with the language model's knowledge to generate a final output response.\n\nThe process typically involves:\n\n1) Encoding the input query using the language model.\n\n2) Retrieving relevant documents/passages from a knowledge source based on the encoded query representation.\n\n3) Conditioning the language model on the retrieved knowledge along with the original query to generate the final output.\n\nThis allows language models to go beyond just relying on their pre-trained knowledge and incorporate relevant external information when producing responses. RAG models have shown improved performance on knowledge-intensive NLP tasks like open-domain question answering compared to using just the language model alone.\n\nSome examples of RAG models include RAG from Facebook AI, ColBERT from Stanford, and DPR from Facebook AI Research. The approach is an active area of research aimed at making language models more knowledgeable and factual."
      }
    ],
    "model":"claude-v3-sonnet",
    "children": [],
    "feedback": null,
    "usedChunks": null,
    "parent": "xxxx"
  },
  "createTime": 1721706201289.0
}
github-actions[bot] commented 2 months ago

This issue has been closed due to no response within 14 days after labeled as "stale", 14 days after last reopened, and 14 days after last commented.