Skip to content

Conversation

@drshrey
Copy link

@drshrey drshrey commented Dec 2, 2023

Fixed a bunch of errors that was breaking the demo. Almost all of it is around handle updated data structures in the openai sdk.

(credits to @jmtame for pairing on this together)

Copy link
Contributor

@lazeratops lazeratops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drshrey, @jmtame - thank you very much for your contribution! I've tagged Chad and Moishe, who are the brains behind this demo, for a review. In the meantime I've had a quick pass through the code and left some quick interim feedback.

import openai
from openai import OpenAI

client = OpenAI()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to only be used from AzureAIService; if so I'd suggest making it a class variable.

import os
from openai import OpenAI

client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to only be used from OpenAIService; if so, I'd suggest making it a class variable. It also looks like our earlier reference to the key was using the variable name OPEN_AI_KEY - was this meant to be that?

image = client.images.generate(api_type = 'openai',
api_version = '2020-11-07',
api_base = "https://api.openai.com/v1",
api_key = os.getenv("OPEN_AI_KEY"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we specify the API key when constructing the client, I'd presume this might no longer be needed. (let's clean up the indentation as well!)

if chunk["choices"][0]["delta"]["content"] != {}: #streaming a content chunk
next_chunk = chunk["choices"][0]["delta"]["content"]
if chunk.choices[0].delta.content:
if chunk.choices[0].delta.content != {}: #streaming a content chunk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a note for us to follow up on as I realize it is not in scope of this PR (so more for @chadbailey59 and @Moishe maybe!), but the repeated list and property access here is redundant - I suggest, in a follow-up PR, accessing the required elements once for reuse (here and below). e.g.:

choices = chunk.choices
if len(choices):
    continue
delta = chunk.choices[0].delta
if delta.content:
    //... etc

(Hastily written just to give an idea of what I mean)

stream=stream,
messages=messages
)
response = client.chat.completions.create(api_type = 'azure',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest just cleaning up the indentation here for readability (and below)

@kwindla
Copy link

kwindla commented Dec 4, 2023

It's great to have this updated code.

I'm testing locally and the OPEN_AI_KEY from my local .env file isn't getting passed through. I'll dig a little more after my next meeting to see what's going on.

EDIT: @lazeratops already noted this: https://github.com/daily-demos/llm-talk/pull/13/files#r1412789861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants