Error i get:
ImportError: cannot import name 'AsyncOpenAI' from 'openai' (/usr/local/lib/python3.9/site-packages/openai/__init__.py)
Hi in the last cell of the notebook of the course, Isabel tell us to make some tests and changes to understand better the lesson.
So im trying to use async call to OpenAi api, because its more effective… but seems that notebooks are also limited:
"""
Demonstrates how to use the `ChatInterface` to create a chatbot using
OpenAI's with async/await.
"""
import panel as pn
from openai import AsyncOpenAI
pn.extension()
async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
response = await aclient.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": contents}],
stream=True,
)
message = ""
async for chunk in response:
part = chunk.choices[0].delta.content
if part is not None:
message += part
yield message
aclient = AsyncOpenAI()
chat_interface = pn.chat.ChatInterface(callback=callback, callback_user="ChatGPT")
chat_interface.send(
"Send a message to get a reply from ChatGPT!", user="System", respond=False
)
chat_interface.servable()
Original font; OpenAI - Panel Chat Examples
Im also trying to imporve the Chat interface.