Skip to content

Commit

Permalink
Added better prompt template and role aliases for Titan.
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Sep 14, 2023
1 parent 77abc34 commit b467fce
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions 04_Chatbot/00_Chatbot_Titan.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,16 @@
"from langchain.memory import ConversationBufferMemory\n",
"\n",
"titan_llm = Bedrock(model_id=\"amazon.titan-tg1-large\", client=boto3_bedrock)\n",
"titan_llm.model_kwargs = {'temperature': 0.5, \"maxTokenCount\": 700}\n",
"\n",
"memory = ConversationBufferMemory()\n",
"memory.human_prefix = \"User\"\n",
"memory.ai_prefix = \"Bot\"\n",
"\n",
"conversation = ConversationChain(\n",
" llm=titan_llm, verbose=True, memory=memory\n",
")\n",
"conversation.prompt.template = \"\"\"System: The following is a friendly conversation between a knowledgeable helpful assistant and a customer. The assistant is talkative and provides lots of specific details from it's context.\\n\\nCurrent conversation:\\n{history}\\nUser: {input}\\nBot:\"\"\"\n",
"\n",
"print_ww(conversation.predict(input=\"Hi there!\"))"
]
Expand Down Expand Up @@ -247,10 +253,15 @@
"\n",
"chat_history = []\n",
"\n",
"memory=ConversationBufferMemory()\n",
"memory.human_prefix = \"User\"\n",
"memory.ai_prefix = \"Bot\"\n",
"\n",
"# turn verbose to true to see the full logs and documents\n",
"qa= ConversationChain(\n",
" llm=titan_llm, verbose=False, memory=ConversationBufferMemory() #memory_chain\n",
" llm=titan_llm, verbose=False, memory=memory #memory_chain\n",
")\n",
"qa.prompt.template = \"\"\"System: The following is a friendly conversation between a knowledgeable helpful assistant and a customer. The assistant is talkative and provides lots of specific details from it's context.\\n\\nCurrent conversation:\\n{history}\\nUser: {input}\\nBot:\"\"\"\n",
"\n",
"print(f\"ChatBot:DEFAULT:PROMPT:TEMPLATE: is ={qa.prompt.template}\")"
]
Expand Down Expand Up @@ -1212,9 +1223,9 @@
],
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science 3.0)",
"display_name": "conda_python3",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-west-2:236514542706:image/sagemaker-data-science-310-v1"
"name": "conda_python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1226,7 +1237,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit b467fce

Please sign in to comment.