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: support chat without stream #409

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yugasun
Copy link

@yugasun yugasun commented Mar 10, 2025

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @yugasun, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request modifies the chat and achat methods in src/praisonai-agents/praisonaiagents/agent/agent.py and the __init__ and _get_multimodal_message methods in src/praisonai-agents/praisonaiagents/agents/agents.py to include a stream parameter. This allows the chat functionality to operate without streaming, providing more flexibility in how chat responses are handled. The stream parameter is added to both synchronous and asynchronous versions of the chat methods.

Highlights

  • Feature Addition: The stream parameter is added to the chat and achat methods in agent.py to control streaming behavior.
  • Parameter Propagation: The stream parameter is passed down to the _chat_completion and _achat_completion methods.
  • Constructor Update: The PraisonAIAgents class constructor in agents.py now accepts a stream parameter.
  • Method Update: The _get_multimodal_message method in agents.py now includes the stream parameter when calling the agent's chat method.

Changelog

  • src/praisonai-agents/praisonaiagents/agent/agent.py
    • Added stream parameter to chat method (line 716).
    • Passed stream parameter to _chat_completion in chat method (line 845).
    • Passed stream parameter to _chat_completion when function returns an empty output (line 882).
    • Added stream parameter to achat method (line 987).
    • Removed unused variable formatted_tools (line 1132).
  • src/praisonai-agents/praisonaiagents/agents/agents.py
    • Added stream parameter to PraisonAIAgents constructor (line 48).
    • Initialized self.stream with the provided stream value (line 80).
    • Added stream parameter to the agent's chat method call in _get_multimodal_message (line 670).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A parameter added, a stream now controlled,
Flexibility's gained, a story unfolds.
No longer bound by constant flow,
The agent's chat, can start and go.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a stream parameter to enable or disable streaming in chat functionalities. The changes seem straightforward, but there are a few points to consider regarding potential breaking changes and the synchronization of asynchronous methods.

Summary of Findings

  • Parameter addition without default value: The stream parameter was added to several methods without a default value, potentially breaking existing calls that don't provide this argument. This could lead to unexpected behavior or errors in existing integrations.
  • TODO comment in achat method: The achat method contains a TODO comment indicating that it requires syncing with the chat method. This suggests that the asynchronous version may not be fully aligned with the synchronous version, potentially leading to inconsistencies.

Merge Readiness

The pull request introduces a new feature by adding the stream parameter to several methods. While the changes seem relatively straightforward, the potential breaking change due to the added parameter without a default value in some methods needs to be carefully considered. Additionally, the TODO comment in the achat method raises concerns about the consistency between synchronous and asynchronous versions. I recommend addressing these issues before merging. I am unable to approve this pull request, and users should have others review and approve this code before merging.

Comment on lines 987 to 988
async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, stream=True):
"""Async version of chat method. TODO: Requires Syncing with chat method."""

Choose a reason for hiding this comment

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

medium

The stream parameter is added without a default value, similar to the chat method. Also, there's a TODO comment indicating that this method requires syncing with the chat method. Ensure that the asynchronous version is fully aligned with the synchronous version to avoid inconsistencies.

Suggested change
async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, stream=True):
"""Async version of chat method. TODO: Requires Syncing with chat method."""
async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, stream=True):
"""Async version of chat method. Requires Syncing with chat method."""

@yugasun yugasun force-pushed the fix/support-chat-without-stream branch from 48fa01f to fab4aca Compare March 10, 2025 08:00
@MervinPraison
Copy link
Owner

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a stream parameter to the chat methods, allowing for non-streaming responses. This is a useful addition for cases where streaming is not desired or supported. The changes look good overall.

Merge Readiness

The code changes seem correct and address the issue of supporting chat without streaming. I recommend merging this pull request after addressing the review comments. I am unable to approve the pull request, and users should have others review and approve this code before merging.

@@ -713,7 +713,7 @@ def _chat_completion(self, messages, temperature=0.2, tools=None, stream=True, r
display_error(f"Error in chat completion: {e}")
return None

def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False):
def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, stream=True):

Choose a reason for hiding this comment

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

medium

Consider adding a docstring that briefly explains the purpose of the stream parameter. This will improve the discoverability and usability of the function.

    def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pydantic=None, reasoning_steps=False, stream=True):
        """Chats with the agent.

        Args:
            prompt: The prompt to send to the agent.
            temperature: The temperature to use for the chat completion.
            tools: The tools to use for the chat completion.
            output_json: Whether to output the response as JSON.
            output_pydantic: Whether to output the response as a Pydantic model.
            reasoning_steps: Whether to include reasoning steps in the response.
            stream: Whether to stream the response.
        """

@MervinPraison
Copy link
Owner

@yugasun Thank you for your contribution!

Can you please review above suggestion

Parameter addition without default value: The stream parameter was added to several methods without a default value, potentially breaking existing calls that don't provide this argument. This could lead to unexpected behavior or errors in existing integrations

@yugasun
Copy link
Author

yugasun commented Mar 11, 2025

@yugasun Thank you for your contribution!

Can you please review above suggestion

Parameter addition without default value: The stream parameter was added to several methods without a default value, potentially breaking existing calls that don't provide this argument. This could lead to unexpected behavior or errors in existing integrations

@MervinPraison Done

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