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
질문됨 6달 전316회 조회
1개 답변
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
답변함 6달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠