feat(learn): modernize gen-qa-openai notebook to OpenAI SDK v1.x#545
Closed
feat(learn): modernize gen-qa-openai notebook to OpenAI SDK v1.x#545
Conversation
- Update dependencies: openai==1.86.0, pinecone~=8.0 - Replace openai.Embedding.create() with openai_client.embeddings.create() - Replace openai.Completion.create() with openai_client.chat.completions.create() - Update to gpt-3.5-turbo chat model from text-davinci-003 - Remove deprecated openai.Engine.list() authentication check - Initialize OpenAI client using new v1.x pattern - Update response access from dict to attribute notation - Apply ruff-style code formatting Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Move all imports to first code cell following notebook guidelines - Sort imports properly (stdlib first, then third-party) - Remove unnecessary f-string prefix Co-authored-by: Cursor <cursoragent@cursor.com>
The check-pinning script doesn't handle backslash line continuations properly, treating the backslash as a package name. Put the pip install on one line instead. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Migrate the retrieval-augmented generation notebook from OpenAI SDK v0.27 to v1.66.3: - Update dependencies: openai==1.66.3, pinecone==8.0.0 - Replace global openai config with OpenAI client instantiation - Migrate from Completion API to Chat Completions API using gpt-5-mini model - Update Embeddings API calls to use client.embeddings.create() - Modernize response access patterns (dictionary → attribute access) - Update complete() and retrieve() functions with new API patterns All API calls now use the modern client-based pattern and current model lineup. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Collaborator
Author
|
Closing in favor of #546 which contains only the gen-qa-openai.ipynb changes without unrelated commits from the previous branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
learn/generation/openai/gen-qa-openai.ipynbnotebook uses deprecated OpenAI SDK v0.27 with the legacy Completion API and the retiredtext-davinci-003model. This prevents users from running the notebook and demonstrates outdated patterns.Solution
Modernized the notebook to use OpenAI SDK v1.66.3 with the current Chat Completions API and
gpt-5-minimodel. This brings the notebook up to date with current best practices and ensures it will continue working with OpenAI's supported model lineup.Key Changes
Dependencies: Updated
openai==0.27.7→openai==1.66.3andpinecone-client[grpc]==2.2.1→pinecone==8.0.0API Initialization: Migrated from global configuration to client-based pattern:
Chat Completions API: Replaced Completion API with Chat API using
gpt-5-mini:Embeddings API: Updated to new client method and response access patterns:
Model Selection
Selected
gpt-5-minibecause:Breaking Changes
None for end users - the notebook functionality remains the same. API keys and usage patterns are maintained.
Testing
Verified through code pattern analysis:
openai.Completion,openai.Embedding)gpt-5-mini) and response access patternscomplete()andretrieve()functions modernizedFull notebook execution requires valid OpenAI and Pinecone API keys.
Related
Related to other SDK v8 modernization efforts across the examples repository.
Made with Cursor
Note
Low Risk
Low risk since changes are limited to tutorial notebooks, but execution could break if the pinned OpenAI/Pinecone SDK versions or chosen models differ from a user’s environment.
Overview
Modernizes the OpenAI RAG learning notebooks to current SDKs. Updates pinned deps to OpenAI SDK v1 and Pinecone v8, and switches OpenAI usage from global
openai.*calls to the client-basedOpenAI(...)pattern.Moves generation to chat-based models and updates response handling.
gen-qa-openai.ipynbreplacestext-davinci-003completions withclient.chat.completions.create(model="gpt-5-mini"), whileopenai-ml-qa/01-making-queries.ipynbuses chat completions withgpt-3.5-turbo; both notebooks update embeddings calls toclient.embeddings.create(..., model=...)and migrate all response indexing from dict-style (res['data'],res['choices']) to attribute access (res.data,res.choices).Written by Cursor Bugbot for commit a6bbb78. This will update automatically on new commits. Configure here.