-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade OpenAI SDK to v1 #1017
Upgrade OpenAI SDK to v1 #1017
Conversation
…ome redundant methods
…object and remove it from the approach constructors (and all the logic that went with it)
Re tests- they did post some example mocks: |
… in the chat or embeddings methods
thanks, I've done something very similar. Most of the remaining work is because the old SDK used to return dictionaries and the new one returns typed pydantic models |
…ls for streaming responses.
…ions. Update the iterator to pass pydantic model validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Krista says that we should use model to specify deployment, so you can use a single client, which I think is better for code complexity.
@tonybaloney I tested it and discovered an issue with follow-up questions. Previously, an event choice would either have a content string or have no content property at all, but now it can have "content": None. I've adjusted the code and test fixture to account for that. |
I tested it with non-Azure OpenAI with an existing environment and there's an issue due to this new logic in the approaches:
The problem is that AZURE_OPENAI_CHATGPT_DEPLOYMENT has a value even if you're using non-Azure OpenAI (defaults to "chat"). One way around that is to clear out the relevant variables in app.py, before they get passed into the approaches. This change worked for me:
The error can't be replicated in test, by the way, as it's an error from the server that the model "chat" cannot be found. |
I added the |
@tonybaloney You could remove "and content" now, since my line takes care of that (so that in operator works). But we'd need to keep the line that turns it into an empty string. |
Good spot. Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with my deploy tests and code review. No big items, just minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Update version ranges for 1.3.5 openai lib * Update the embeddings library in scripts to use OpenAI 1.3.5 remove some redundant methods * Update the embedding response to use a typed model * Rewrite test_prepdocs to patch out OpenAI v1 models and responses * Update approaches to use new APIs * Update backend service and read approaches to use new SDK * Fix get_search_query. Update RRR approach tests * Update search manager tests * Change patching for app tests * Use deployment ID only in the constructor of the Azure OpenAI Client object and remove it from the approach constructors (and all the logic that went with it) * Explicitly include aiohttp in prepdocs requirements * Use two clients because the new SDK doesn't support a deployment name in the chat or embeddings methods * Ruff ruff * Simplify typing constructor * Update types for message history * Convert RRR to dict before returning * Bend the rules of physics to get mypy to pass * Run black over scripts again * Fix content filtering, update snapshot tests, implement pydantic models for streaming responses. * Update the snapshots with the new required fields for chunked completions. Update the iterator to pass pydantic model validation * Force keyword arguments as the list of arguments is long and complicated * Refactor to have a single client object * Drop argument * Type the chat message builder with pydantic * Rebuild requirements from merge conflicts * Update formatting * Fix issue with follow-up questions * Simplify content check * Don't use deployment field for non azure * Update requirements.in * Remove upper bound * Remove dependabot constraint * Merge the clients again * Fix test_app client name * Inline the ternary statement to pick either a model or deployment name for the OpenAI SDK calls --------- Co-authored-by: Pamela Fox <pamela.fox@gmail.com> Co-authored-by: Pamela Fox <pamelafox@microsoft.com>
Summary of changes
TODO List
Reviewers : please test as many bits of functionality as you can. I've tested this locally and deployed it to test in a production instance, but many hands find more bugs :-)