aws-samples / Serverless-Retrieval-Augmented-Generation-RAG-on-AWS

A full-stack serverless RAG workflow. This is thought for running PoCs, prototypes and bootstrap your MVP.
MIT No Attribution
44 stars 17 forks source link

Chat History Management #36

Closed giusedroid closed 2 months ago

giusedroid commented 2 months ago

Issue #35 , if available:

Description of changes:

Front-end, Back-end and prompt changes to enable users chat history management.
This only makes use of Local Storage.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

kirtandudhatra commented 2 months ago

Overall very useful change!!

My suggestion:

[
        {
          role: "user",
          content: [{ text: "first question" }],
        },
        {
          role: "agent",
          content: [{ text: "first answer" }],
        },
        {
          role: "user",
          content: [{ text: "second question" }],
        },
        {
          role: "agent",
          content: [{ text: "second answer" }],
        },
];

And pass this array to the lambda.

    const conversation = [
        {
          role: "system", <- BY defining this, LLM will understand that this is the ultimate task we want to achieve
          content: [{ text: "prompt without any mention about history" }],
        },
    ];
    conversation = conversation.push(...history)

This approach will take advantage of the existing ability of the converse API instead of doing that work on our side.

giusedroid commented 2 months ago

ah interesting! I'll try to make these changes asap :D

giusedroid commented 2 months ago

bumping into this error: An error occurred while invoking the selected model. 1 validation error detected: Value 'system' at 'messages.1.member.role' failed to satisfy constraint: Member must satisfy enum value set: [user, assistant]

Having a look. Looks like system is not supproted 🤔 maybe I need to upgrade the bedrock sdk or something?

giusedroid commented 2 months ago

Implemented 😸

kirtandudhatra commented 2 months ago

https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#conversation-inference-examples

converse api supports system prompt as one of the argument. Neat!