Simplified based on latest Gradio, and added PC fix for audio playback

This commit is contained in:
Edward Donner
2024-10-29 20:44:22 -04:00
parent d752c86cfa
commit 86763f2fcb
3 changed files with 156 additions and 89 deletions

View File

@@ -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()"
]
},
{