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

fix: error in streaming #665

Merged
merged 13 commits into from
May 17, 2024
Merged

fix: error in streaming #665

merged 13 commits into from
May 17, 2024

Conversation

Hizeros
Copy link
Collaborator

@Hizeros Hizeros commented May 16, 2024

test:Add stream unit test.
fix:Fixed error report without content attribute in stream output
fix:Fixed the problem that chunk has no choice attribute when stream=Ture

docs:Add readme usage documents for `chatbot.py` files;Simplify the introduction to streamlit in math-application notebook
fix:Fixed error report without content attribute in stream output
Copy link

coderabbitai bot commented May 16, 2024

Walkthrough

The recent updates bring significant improvements to the Promptulate library, focusing on enhancing streaming capabilities and refining message handling. Changes include adding streaming response support in chat.py, updating data extraction in _litellm.py, integrating hooks in base.py, adjusting test cases, and modifying example scripts. Dependencies have been streamlined in requirements.txt.

Changes

File Path Change Summary
promptulate/chat.py Added a check for stream in run() to return response directly if true.
promptulate/llms/_litellm.py Updated data extraction in parse_content and _predict for improved streaming support.
promptulate/llms/base.py Included a hook call before returning the result in the predict method.
tests/test_chat.py Enhanced tests for streaming responses and message handling.
example/.../build-math-application-with-agent.ipynb Changed model instantiation to use LLMFactory.build and updated imports.
example/.../chatbot.py Replaced ChatOpenAI with LLMFactory.build for model instantiation.
example/.../readme.md Provided instructions for configuring and running the chatbot.
requirements.txt Removed several dependencies, keeping only zipp.

In code we trust, with streams we flow,
With hooks and tests, our features grow.
Models built with factory's might,
Dependencies trimmed, our code's more light.
🐇✨ CodeRabbit's joy, in changes bright!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 34dec24 and cc7884c.
Files selected for processing (3)
  • promptulate/chat.py (1 hunks)
  • promptulate/llms/_litellm.py (1 hunks)
  • tests/test_chat.py (3 hunks)
Additional comments not posted (5)
promptulate/llms/_litellm.py (2)

28-29: Ensure chunk[1] is the correct way to access content.

Please verify that chunk[1] is the correct way to access the content. If chunk is a list or tuple, this should be fine. Otherwise, it might lead to errors.


28-29: LGTM! Ensure all function calls match the new signature.

Verification successful

All instances of parse_content match the new signature.

  • promptulate/llms/_litellm.py
  • promptulate/llms/zhipu/platform.py
  • promptulate/llms/qianfan/platform.py
  • promptulate/schema.py
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `parse_content` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python $'parse_content'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify all function calls to `parse_content` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py parse_content

Length of output: 960



Script:

#!/bin/bash
# Description: Verify all function definitions and calls to `parse_content` match the new signature.

# Test: Search for the function definitions and calls. Expect: Only occurrences of the new signature.
rg --type py 'def parse_content\(chunk\) -> \(str, str\):'
rg --type py 'parse_content\(chunk\)'

Length of output: 698

tests/test_chat.py (2)

30-44: LGTM! The changes correctly handle streaming responses.


163-179: LGTM! The changes correctly test streaming responses.

promptulate/chat.py (1)

158-160: LGTM! The changes correctly handle streaming responses.

Copy link

@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cc7884c and b8712ad.
Files selected for processing (1)
  • tests/test_chat.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_chat.py

@Undertone0809 Undertone0809 changed the title Hizeros/streaming fix: error in streaming May 16, 2024
Copy link

@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.

Actionable comments posted: 6

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b8712ad and 4581569.
Files selected for processing (5)
  • example/build-math-application-with-agent/build-math-application-with-agent.ipynb (12 hunks)
  • example/build-math-application-with-agent/chatbot.py (4 hunks)
  • example/build-math-application-with-agent/readme.md (1 hunks)
  • promptulate/chat.py (1 hunks)
  • promptulate/llms/_litellm.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • promptulate/chat.py
Additional comments not posted (20)
example/build-math-application-with-agent/readme.md (3)

1-1: No issues found.


2-2: No issues found.


4-4: No issues found.

promptulate/llms/_litellm.py (2)

29-29: LGTM! The change correctly handles the chunk object.


45-48: LGTM! The change correctly adds the stream parameter to the function call.

example/build-math-application-with-agent/chatbot.py (3)

81-82: LGTM! The change correctly updates the model to gpt-4-1106-preview.


99-99: LGTM! The change correctly updates the model to gpt-4-1106-preview.


109-109: LGTM! The link to the source code is appropriate and useful.

example/build-math-application-with-agent/build-math-application-with-agent.ipynb (12)

7-7: LGTM! The description is appropriate and aligns with the PR objectives.


12-12: LGTM! The link to the image is appropriate and useful.


28-32: LGTM! The instructions for installing necessary libraries are appropriate and useful.


51-52: LGTM! The metadata for the code cell is appropriate and useful for tracking execution time.


Line range hint 81-82: LGTM! The change correctly updates the model to gpt-4-1106-preview.


153-153: LGTM! The initialization of the LLM model is appropriate and aligns with the PR objectives.


290-291: LGTM! The change correctly updates the model to gpt-4-1106-preview.


323-340: LGTM! The output of the agent's response is appropriate and useful for understanding the agent's behavior.


376-376: LGTM! The description of the Streamlit application is appropriate and aligns with the PR objectives.


378-387: LGTM! The instructions for installing necessary libraries are appropriate and useful.


389-389: LGTM! The command to change the directory is appropriate and useful.


391-391: LGTM! The command to run the Streamlit application is appropriate and useful.

@@ -0,0 +1,11 @@
# The `chatbot.py` is an example of building a mathematical chatbot using streamlit and promptulate

# How to run?
Copy link

Choose a reason for hiding this comment

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

Avoid using multiple top-level headings in the same document.

Consider using subheadings (e.g., ## How to run?) instead.


# How to run?

1. First configure the package
Copy link

Choose a reason for hiding this comment

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

Surround lists with blank lines for better readability.

5c5
< 1. First configure the package
---
> 
> 1. First configure the package

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

1. First configure the package

# How to run?

1. First configure the package
- `pip install -r requirements.txt`
Copy link

Choose a reason for hiding this comment

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

Surround lists with blank lines for better readability.

6c6
< - `pip install -r requirements.txt`
---
> 
> - `pip install -r requirements.txt`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- `pip install -r requirements.txt`
- `pip install -r requirements.txt`

1. First configure the package
- `pip install -r requirements.txt`

2. Switch to the directory where `chatbot.py` is located
Copy link

Choose a reason for hiding this comment

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

Surround lists with blank lines for better readability.

8c8
< 2. Switch to the directory where `chatbot.py` is located
---
> 
> 2. Switch to the directory where `chatbot.py` is located

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
2. Switch to the directory where `chatbot.py` is located
2. Switch to the directory where `chatbot.py` is located

- `pip install -r requirements.txt`

2. Switch to the directory where `chatbot.py` is located
- cd `promptulate/example/build-math-application-with-agent`
Copy link

Choose a reason for hiding this comment

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

Surround lists with blank lines for better readability.

9c9
< - cd `promptulate/example/build-math-application-with-agent`
---
> 
> - cd `promptulate/example/build-math-application-with-agent`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- cd `promptulate/example/build-math-application-with-agent`
- cd `promptulate/example/build-math-application-with-agent`

2. Switch to the directory where `chatbot.py` is located
- cd `promptulate/example/build-math-application-with-agent`

3. Run the `streamlit run chatbot.py` command
Copy link

Choose a reason for hiding this comment

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

Surround lists with blank lines for better readability.

11c11
< 3. Run the `streamlit run chatbot.py`  command
---
> 
> 3. Run the `streamlit run chatbot.py`  command

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
3. Run the `streamlit run chatbot.py` command
3. Run the `streamlit run chatbot.py` command

Copy link

@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4581569 and b5d709d.
Files selected for processing (4)
  • promptulate/chat.py (2 hunks)
  • promptulate/llms/base.py (1 hunks)
  • requirements.txt (1 hunks)
  • tests/test_chat.py (3 hunks)
Files not reviewed due to errors (1)
  • promptulate/llms/base.py (no review received)
Files skipped from review due to trivial changes (1)
  • requirements.txt
Files skipped from review as they are similar to previous changes (2)
  • promptulate/chat.py
  • tests/test_chat.py

class FakeLLM(BaseLLM):
llm_type: str = "fake"

def __init__(self, *args, **kwargs):
print(33333)
Copy link
Owner

Choose a reason for hiding this comment

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

remove useless log output

Copy link

@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b5d709d and fbbf113.
Files selected for processing (2)
  • promptulate/chat.py (2 hunks)
  • tests/test_chat.py (4 hunks)
Files skipped from review due to trivial changes (1)
  • promptulate/chat.py
Files skipped from review as they are similar to previous changes (1)
  • tests/test_chat.py

@Undertone0809
Copy link
Owner

lgtm

@Undertone0809 Undertone0809 merged commit 4de130a into main May 17, 2024
25 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