-
-
Notifications
You must be signed in to change notification settings - Fork 595
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
generator blog post #230
generator blog post #230
Conversation
WalkthroughThe recent updates introduce a new contributor, Anmol Jawandha, and a comprehensive blog post discussing Python generators and their integration with LLM streaming via the Instructor library. The post delves into the benefits of generators, such as memory efficiency and lazy evaluation, and showcases their application in real-time e-commerce product recommendation scenarios, emphasizing the performance gains when using the Instructor library for structured data extraction. Changes
TipsChat with CodeRabbit Bot (
|
from typing import Iterable | ||
from pydantic import BaseModel | ||
|
||
client = instructor.patch(OpenAI(), mode=instructor.function_calls.Mode.JSON) |
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.
interesting, not function calling?
docs/blog/posts/generator.md
Outdated
```python | ||
for recommendation in recommendations_stream: | ||
assert isinstance(recommendation, ProductRecommendation) | ||
print(f"Recommended Product: {recommendation.product_name}") |
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.
It would be nice to conclude by highlighting that your web application now displays results faster. Even a 100ms improvement can lead to a 1% increase in revenue. These improvements are significant. We can even utilize the previous benchmarking code to demonstrate the increased speed in obtaining the first result.
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
docs/blog/posts/generator.md
Outdated
# Set your OpenAI API key | ||
openai.api_key = 'your-api-key' | ||
|
||
response_generator = openai.ChatCompletion.create( |
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.
response_generator = openai.ChatCompletion.create( | |
response_generator = client.chat.completions.create |
wrong client
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.
i actualy just wanted to show the vanilla open ai generator here
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.
well this is just a different sdk right? like this code won't run effectively
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- docs/blog/.authors.yml (1 hunks)
- docs/blog/posts/generator.md (1 hunks)
Files skipped from review due to trivial changes (1)
- docs/blog/.authors.yml
Additional comments: 3
docs/blog/posts/generator.md (3)
188-188: The previous comment regarding function calling is outdated as the code now uses the Instructor library to patch the OpenAI client, which is a valid approach.
110-110: The previous comment about the vanilla OpenAI generator has been addressed, as the code snippet correctly demonstrates its usage.
1-261: The blog post is well-written, informative, and technically accurate, providing a good balance of explanation, code examples, and real-world application. It is consistent with the rest of the documentation and encourages reader engagement.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- docs/blog/posts/generator.md (1 hunks)
Additional comments: 8
docs/blog/posts/generator.md (8)
16-20: The introduction provides a clear context for the importance of streaming and generators in enhancing user experience in applications like eCommerce and chat services.
24-24: The explanation of Python generators is accurate and highlights their benefits for handling large data sets and stream processing.
45-48: The advantages listed for generators are well-explained and relevant to the topic of the blog post.
106-125: The code example using the OpenAI API is correct and demonstrates the streaming capability effectively.
192-192: The previous comment about the function call has been addressed by the user's response, indicating their intention to show the vanilla OpenAI generator.
183-199: The use of the
Instructor
library for structured extraction from a real-time stream is a practical demonstration of the concepts discussed in the blog post.227-249: The comparison between streaming and non-streaming approaches for generating product recommendations is insightful and well-presented with benchmarks.
255-261: The key takeaways section succinctly summarizes the main points of the blog post and provides a call to action for readers to check out the GitHub repository.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- docs/blog/posts/generator.md (1 hunks)
Additional comments: 1
docs/blog/posts/generator.md (1)
- 1-267: The article is well-structured, informative, and provides a comprehensive overview of Python generators and their application in LLM streaming. The code examples are relevant and demonstrate the concepts effectively. The use of the Instructor library for real-time data validation and extraction is a practical example that adds value to the article. The metadata, including the draft status, publication date, tags, and author information, are all correctly formatted and ready for publication. The article is ready for publication as it stands.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- docs/blog/index.md (1 hunks)
- docs/blog/posts/generator.md (1 hunks)
Files skipped from review due to trivial changes (1)
- docs/blog/index.md
Additional comments: 2
docs/blog/posts/generator.md (2)
195-195: The use of
instructor.patch
with theOpenAI
client is correct and aligns with the intended use of the Instructor library for JSON mode function calls. This allows for structured extraction from the LLM stream.1-272: The article is well-written, provides clear explanations, and the code examples are correct. It effectively demonstrates the use of Python generators and the Instructor library for LLM streaming, particularly in the context of e-commerce product recommendations. The article is ready for publication.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- docs/blog/posts/generator.md (1 hunks)
Additional comments: 1
docs/blog/posts/generator.md (1)
- 1-274: The article provides a clear and comprehensive explanation of Python generators and their application in LLM streaming, with correct and functional code examples. The explanations are technically accurate, and the article is well-formatted and free of grammatical errors. It also adheres to best practices and does not contain any outdated information, factual inaccuracies, or security vulnerabilities. The code examples are optimized and do not exhibit any performance issues, data races, inconsistencies, error handling issues, maintainability issues, or complexity issues. Overall, the article is a valuable resource for understanding and applying Python generators in real-world scenarios.
Summary by CodeRabbit