Skip to content

Commit

Permalink
Fix Notebook 04 for invoke_async with context variables (#672)
Browse files Browse the repository at this point in the history
### Motivation and Context
New Python API changes the signature for invoke_async.

This aligns it and makes it clearer that the context passed into
invoke_async are context variables.

This fixes the current issue where the chat function will just repeat
back the user input instead of actually chatting

---------

Co-authored-by: Abby Harrison <54643756+awharrison-28@users.noreply.github.com>
  • Loading branch information
alexchaomander and awharrison-28 committed Apr 28, 2023
1 parent 7c9a462 commit f4758ff
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions samples/notebooks/python/04-context-variables-chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
"metadata": {},
"outputs": [],
"source": [
"context = sk.ContextVariables()\n",
"context[\"history\"] = \"\""
"context_variables = sk.ContextVariables()\n",
"context_variables[\"history\"] = \"\""
]
},
{
Expand All @@ -127,8 +127,8 @@
"metadata": {},
"outputs": [],
"source": [
"context[\"user_input\"] = \"Hi, I'm looking for book suggestions\"\n",
"bot_answer = await chat_function.invoke_async(input=context)\n",
"context_variables[\"user_input\"] = \"Hi, I'm looking for book suggestions\"\n",
"bot_answer = await chat_function.invoke_async(variables=context_variables)\n",
"print(bot_answer)"
]
},
Expand All @@ -147,8 +147,8 @@
"metadata": {},
"outputs": [],
"source": [
"context[\"history\"] += f\"\\nUser: {context['user_input']}\\nChatBot: {bot_answer}\\n\"\n",
"print(context[\"history\"])"
"context_variables[\"history\"] += f\"\\nUser: {context_variables['user_input']}\\nChatBot: {bot_answer}\\n\"\n",
"print(context_variables[\"history\"])"
]
},
{
Expand All @@ -169,16 +169,16 @@
"async def chat(input_text: str) -> None:\n",
" # Save new message in the context variables\n",
" print(f\"User: {input_text}\")\n",
" context[\"user_input\"] = input_text\n",
" context_variables[\"user_input\"] = input_text\n",
"\n",
" # Process the user message and get an answer\n",
" answer = await chat_function.invoke_async(context)\n",
" answer = await chat_function.invoke_async(variables=context_variables)\n",
"\n",
" # Show the response\n",
" print(f\"ChatBot: {answer}\")\n",
"\n",
" # Append the new interaction to the chat history\n",
" context[\"history\"] += f\"\\nUser: {input_text}\\nChatBot: {answer}\\n\""
" context_variables[\"history\"] += f\"\\nUser: {input_text}\\nChatBot: {answer}\\n\""
]
},
{
Expand Down Expand Up @@ -243,4 +243,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit f4758ff

Please sign in to comment.