Skip to content
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

Merged
merged 18 commits into from
Nov 28, 2023
Merged

generator blog post #230

merged 18 commits into from
Nov 28, 2023

Conversation

Anmol6
Copy link
Contributor

@Anmol6 Anmol6 commented Nov 27, 2023

Summary by CodeRabbit

  • Documentation
    • Added a new contributor, Anmol Jawandha, to the blog's authors list.
    • Published a new blog post detailing the use of Python generators for efficient data handling and their integration with LLM streaming for real-time applications.
    • Discussed the advantages of Python generators, including lazy evaluation and memory efficiency.
    • Provided practical examples and benchmarks demonstrating the performance of generators in e-commerce product recommendation scenarios.
    • Introduced the Instructor library's role in enhancing LLM streaming capabilities.
    • Updated the blog index to include the new post "How can I stream models to improve latency?"

Copy link
Contributor

coderabbitai bot commented Nov 27, 2023

Walkthrough

The 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

File Path Change Summary
docs/blog/.authors.yml Added new contributor Anmol Jawandha with details and avatar.
docs/blog/posts/generator.md Introduced blog post on Python generators and LLM streaming with the Instructor library, including real-world e-commerce examples, code snippets, and performance benchmarks. Authored by jxnl and anmol.
docs/blog/index.md Added a new blog post titled "How can I stream models to improve latency?".

🐇✨
In the blog's garden, a new flower blooms,
Anmol joins the ranks, with knowledge that looms.
Generators stream, with lazy grace,
In Python's embrace, they find their place. 🌼📜


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

docs/blog/posts/generator.md Outdated Show resolved Hide resolved
docs/blog/posts/generator.md Outdated Show resolved Hide resolved
docs/blog/posts/generator.md Outdated Show resolved Hide resolved
docs/blog/posts/generator.md Outdated Show resolved Hide resolved
from typing import Iterable
from pydantic import BaseModel

client = instructor.patch(OpenAI(), mode=instructor.function_calls.Mode.JSON)
Copy link
Owner

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 Show resolved Hide resolved
docs/blog/posts/generator.md Outdated Show resolved Hide resolved
```python
for recommendation in recommendations_stream:
assert isinstance(recommendation, ProductRecommendation)
print(f"Recommended Product: {recommendation.product_name}")
Copy link
Owner

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.

Anmol6 and others added 8 commits November 27, 2023 12:21
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>
# Set your OpenAI API key
openai.api_key = 'your-api-key'

response_generator = openai.ChatCompletion.create(
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
response_generator = openai.ChatCompletion.create(
response_generator = client.chat.completions.create

wrong client

Copy link
Contributor Author

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

Copy link
Owner

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

@Anmol6 Anmol6 marked this pull request as ready for review November 28, 2023 04:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 634d20e and 7b109db.
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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between ffe7933 and 33e0fc3.
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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 33e0fc3 and ef781fd.
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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between ef781fd and 82354df.
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 the OpenAI 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 82354df and 2042a1a.
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.

@jxnl jxnl merged commit 1851385 into jxnl:main Nov 28, 2023
4 checks passed
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.

2 participants