Simplified based on latest Gradio, and added PC fix for audio playback
This commit is contained in:
@@ -60,16 +60,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# This function looks rather simpler than the one from my video, because we're taking advantage of the latest Gradio updates\n",
|
||||
"\n",
|
||||
"def chat(message, history):\n",
|
||||
" messages = [{\"role\": \"system\", \"content\": system_message}]\n",
|
||||
" for human, assistant in history:\n",
|
||||
" messages.append({\"role\": \"user\", \"content\": human})\n",
|
||||
" messages.append({\"role\": \"assistant\", \"content\": assistant})\n",
|
||||
" messages.append({\"role\": \"user\", \"content\": message})\n",
|
||||
" messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n",
|
||||
" response = openai.chat.completions.create(model=MODEL, messages=messages)\n",
|
||||
" return response.choices[0].message.content\n",
|
||||
"\n",
|
||||
"gr.ChatInterface(fn=chat).launch()"
|
||||
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -175,11 +173,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def chat(message, history):\n",
|
||||
" messages = [{\"role\": \"system\", \"content\": system_message}]\n",
|
||||
" for human, assistant in history:\n",
|
||||
" messages.append({\"role\": \"user\", \"content\": human})\n",
|
||||
" messages.append({\"role\": \"assistant\", \"content\": assistant})\n",
|
||||
" messages.append({\"role\": \"user\", \"content\": message})\n",
|
||||
" messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n",
|
||||
" response = openai.chat.completions.create(model=MODEL, messages=messages, tools=tools)\n",
|
||||
"\n",
|
||||
" if response.choices[0].finish_reason==\"tool_calls\":\n",
|
||||
@@ -221,7 +215,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gr.ChatInterface(fn=chat).launch()"
|
||||
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user