How to correctly build up a conversation using the Invoke API

0

Hi,

I'm getting going using the AWS Bedrock API and am having difficulty mapping the concepts from OpenAI's API to this API, specifically building up a conversation between a bot. For instance, here's a prompt I'm submitting: "prompt": f'\n\nHuman: Pretend your name is robert.\n\nAssistant: My name is robert.\n\nHuman: {query}\n\nAssistant:', My goal here is to prep a prompt so that Jurassic-2 (in this case, but will ultimately need to rely on multiple LLMs for this project) knows that it should call itself "Robert" however in invoking Jurassic-2 with the query "what is your name?" gets this output: "text": " My name is Robert.\nWhat can I do for you, Robert?" Taking the first part of what I sent re: the assistant, but then completely ignoring the first "human" prompt.

What I'd like to do is something like OpenAI does with its conversation API: https://platform.openai.com/docs/guides/text-generation/chat-completions-api

What am I doing wrong?

Any help is appreciated.

Mike M
asked 6 months ago306 views
1 Answer
0

Hey! Thanks for your question. This case looks like it can be solved with creating a "role" for your bot, as well as ensuring it has chat memory. The "role" your bot will play can be contained in the prompt similar to your example outlined above. Whereas the "chat memory" can be created with the Langchain library.

I would highly suggest you check out this notebook within our Bedrock workshop. It uses AI21 labs + Langchain to created a chatbot: https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/04_Chatbot/00_Chatbot_AI21.ipynb

In particular I would look at the section called "Chatbot with Persona" for a code sample similar to your use case.

Specifically the code I will outline below:

'''

memory = ConversationBufferMemory()

memory.chat_memory.add_user_message("Context:You will be acting as a career coach. Your goal is to give career advice to users")

memory.chat_memory.add_ai_message("I am career coach and give career advice") ai21_llm = Bedrock(model_id="ai21.j2-ultra-v1",client=boto3_bedrock)

conversation = ConversationChain(

 llm=ai21_llm, verbose=True, memory=memory

)

print_ww(conversation.predict(input="What are the career options in AI?")

'''

We can look at the line

"memory.chat_memory.add_user_message("Context:You will be acting as a career coach. Your goal is to give career advice to users")"

Here is where you can set your bot's name to "Robert" and outline how it should behave accordingly.

Please let me know if this solution works I will be more than happy to continue helping.

-Moh

mtahsin
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions