Skip to content

Commit

Permalink
Fix openai
Browse files Browse the repository at this point in the history
ahuang11 committed Nov 30, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
mmarchini mary marchini
1 parent 3ab4e71 commit 6b19176
Showing 6 changed files with 21 additions and 11 deletions.
6 changes: 4 additions & 2 deletions docs/examples/openai/openai_async_chat.py
Original file line number Diff line number Diff line change
@@ -17,8 +17,10 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
)
message = ""
async for chunk in response:
message += chunk["choices"][0]["delta"].get("content", "")
yield message
part = chunk.choices[0].delta.content
if part is not None:
message += part
yield message


aclient = AsyncOpenAI()
6 changes: 4 additions & 2 deletions docs/examples/openai/openai_authentication.py
Original file line number Diff line number Diff line change
@@ -49,8 +49,10 @@ async def callback(
)
message = ""
async for chunk in response:
message += chunk["choices"][0]["delta"].get("content", "")
yield message
part = chunk.choices[0].delta.content
if part is not None:
message += part
yield message


aclient = AsyncOpenAI()
6 changes: 4 additions & 2 deletions docs/examples/openai/openai_chat.py
Original file line number Diff line number Diff line change
@@ -17,8 +17,10 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
)
message = ""
for chunk in response:
message += chunk["choices"][0]["delta"].get("content", "")
yield message
part = chunk.choices[0].delta.content
if part is not None:
message += part
yield message


client = OpenAI()
6 changes: 4 additions & 2 deletions docs/examples/openai/openai_hvplot.py
Original file line number Diff line number Diff line change
@@ -45,8 +45,10 @@ async def respond_with_openai(contents: Union[pd.DataFrame, str]):
)
message = ""
async for chunk in response:
message += chunk["choices"][0]["delta"].get("content", "")
yield {"user": "ChatGPT", "object": message}
part = chunk.choices[0].delta.content
if part is not None:
message += part
yield {"user": "ChatGPT", "object": message}


async def respond_with_executor(code: str):
2 changes: 1 addition & 1 deletion docs/examples/openai/openai_image_generation.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

def callback(contents: str, user: str, instance: pn.chat.ChatInterface):
response = client.images.generate(prompt=contents, n=1, size="256x256")
image_url = response["data"][0]["url"]
image_url = response.data[0].url
return pn.pane.Image(image_url, width=256, height=256)


6 changes: 4 additions & 2 deletions docs/examples/openai/openai_two_bots.py
Original file line number Diff line number Diff line change
@@ -31,8 +31,10 @@ async def callback(
)
message = ""
async for chunk in response:
message += chunk["choices"][0]["delta"].get("content", "")
yield {"user": callback_user, "avatar": callback_avatar, "object": message}
part = chunk.choices[0].delta.content
if part is not None:
message += part
yield {"user": callback_user, "avatar": callback_avatar, "object": message}

if len(instance.objects) % 6 == 0: # stop at every 6 messages
instance.send(

0 comments on commit 6b19176

Please sign in to comment.