Skip to content

Commit fea00ad

Browse files
fix: complete streaming fix for all LLM providers and improve console handling
- Fix custom LLM streaming (Gemini/Vertex AI) in llm.py by removing verbose condition - Improve console parameter consistency when streaming is enabled - Ensures streaming works for stream=True regardless of verbose setting - Maintains full backward compatibility Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent f194073 commit fea00ad

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/praisonai-agents/praisonaiagents/agent/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ def _chat_completion(self, messages, temperature=0.2, tools=None, stream=True, r
11401140
tools=formatted_tools, # Already formatted for OpenAI
11411141
execute_tool_fn=self.execute_tool,
11421142
stream=stream,
1143-
console=self.console if self.verbose else None,
1143+
console=self.console if (self.verbose or stream) else None,
11441144
display_fn=display_generating if stream else None,
11451145
reasoning_steps=reasoning_steps,
11461146
verbose=self.verbose,

src/praisonai-agents/praisonaiagents/llm/llm.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,18 +2417,14 @@ def response(
24172417
)
24182418

24192419
if stream:
2420-
if verbose:
2421-
with Live(display_generating("", start_time), console=console or self.console, refresh_per_second=4) as live:
2422-
for chunk in litellm.completion(**completion_params):
2423-
content = self._process_streaming_chunk(chunk)
2424-
if content:
2425-
response_text += content
2426-
live.update(display_generating(response_text, start_time))
2427-
else:
2420+
with Live(display_generating("", start_time), console=console or self.console, refresh_per_second=4) as live:
24282421
for chunk in litellm.completion(**completion_params):
24292422
content = self._process_streaming_chunk(chunk)
24302423
if content:
24312424
response_text += content
2425+
live.update(display_generating(response_text, start_time))
2426+
if content:
2427+
response_text += content
24322428
else:
24332429
response = litellm.completion(**completion_params)
24342430
response_text = response.choices[0].message.content.strip() if response.choices[0].message.content else ""
@@ -2517,18 +2513,14 @@ async def aresponse(
25172513
)
25182514

25192515
if stream:
2520-
if verbose:
2521-
with Live(display_generating("", start_time), console=console or self.console, refresh_per_second=4) as live:
2522-
async for chunk in await litellm.acompletion(**completion_params):
2523-
content = self._process_streaming_chunk(chunk)
2524-
if content:
2525-
response_text += content
2526-
live.update(display_generating(response_text, start_time))
2527-
else:
2516+
with Live(display_generating("", start_time), console=console or self.console, refresh_per_second=4) as live:
25282517
async for chunk in await litellm.acompletion(**completion_params):
25292518
content = self._process_streaming_chunk(chunk)
25302519
if content:
25312520
response_text += content
2521+
live.update(display_generating(response_text, start_time))
2522+
if content:
2523+
response_text += content
25322524
else:
25332525
response = await litellm.acompletion(**completion_params)
25342526
response_text = response.choices[0].message.content.strip() if response.choices[0].message.content else ""

0 commit comments

Comments
 (0)