fix: support chat without stream#409
Conversation
There was a problem hiding this comment.
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
streamparameter is added to thechatandachatmethods inagent.pyto control streaming behavior. - Parameter Propagation: The
streamparameter is passed down to the_chat_completionand_achat_completionmethods. - Constructor Update: The
PraisonAIAgentsclass constructor inagents.pynow accepts astreamparameter. - Method Update: The
_get_multimodal_messagemethod inagents.pynow includes thestreamparameter when calling the agent'schatmethod.
Changelog
- src/praisonai-agents/praisonaiagents/agent/agent.py
- Added
streamparameter tochatmethod (line 716). - Passed
streamparameter to_chat_completioninchatmethod (line 845). - Passed
streamparameter to_chat_completionwhen function returns an empty output (line 882). - Added
streamparameter toachatmethod (line 987). - Removed unused variable
formatted_tools(line 1132).
- Added
- src/praisonai-agents/praisonaiagents/agents/agents.py
- Added
streamparameter toPraisonAIAgentsconstructor (line 48). - Initialized
self.streamwith the providedstreamvalue (line 80). - Added
streamparameter to the agent'schatmethod call in_get_multimodal_message(line 670).
- Added
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
-
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. ↩
There was a problem hiding this comment.
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
streamparameter 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
achatmethod: Theachatmethod contains aTODOcomment indicating that it requires syncing with thechatmethod. 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.
| 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.""" |
There was a problem hiding this comment.
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.
| 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.""" |
48fa01f to
fab4aca
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
| 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): |
There was a problem hiding this comment.
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.
"""|
@yugasun Thank you for your contribution! Can you please review above suggestion
|
@MervinPraison Done |
…ning stream=True as default
No description provided.