praisonaiagents 0.0.118__py3-none-any.whl → 0.0.119__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -229,6 +229,39 @@ class LLM:
229
229
 
230
230
  return any(endpoint in base_url or endpoint in api_base for endpoint in ollama_endpoints)
231
231
 
232
+ def _process_stream_delta(self, delta, response_text: str, tool_calls: List[Dict], formatted_tools: Optional[List] = None) -> tuple:
233
+ """
234
+ Process a streaming delta chunk to extract content and tool calls.
235
+
236
+ Args:
237
+ delta: The delta object from a streaming chunk
238
+ response_text: The accumulated response text so far
239
+ tool_calls: The accumulated tool calls list so far
240
+ formatted_tools: Optional list of formatted tools for tool call support check
241
+
242
+ Returns:
243
+ tuple: (updated_response_text, updated_tool_calls)
244
+ """
245
+ # Process content
246
+ if delta.content:
247
+ response_text += delta.content
248
+
249
+ # Capture tool calls from streaming chunks if provider supports it
250
+ if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
251
+ for tc in delta.tool_calls:
252
+ if tc.index >= len(tool_calls):
253
+ tool_calls.append({
254
+ "id": tc.id,
255
+ "type": "function",
256
+ "function": {"name": "", "arguments": ""}
257
+ })
258
+ if tc.function.name:
259
+ tool_calls[tc.index]["function"]["name"] = tc.function.name
260
+ if tc.function.arguments:
261
+ tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
262
+
263
+ return response_text, tool_calls
264
+
232
265
  def _parse_tool_call_arguments(self, tool_call: Dict, is_ollama: bool = False) -> tuple:
233
266
  """
234
267
  Safely parse tool call arguments with proper error handling
@@ -651,23 +684,11 @@ class LLM:
651
684
  ):
652
685
  if chunk and chunk.choices and chunk.choices[0].delta:
653
686
  delta = chunk.choices[0].delta
687
+ response_text, tool_calls = self._process_stream_delta(
688
+ delta, response_text, tool_calls, formatted_tools
689
+ )
654
690
  if delta.content:
655
- response_text += delta.content
656
691
  live.update(display_generating(response_text, current_time))
657
-
658
- # Capture tool calls from streaming chunks if provider supports it
659
- if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
660
- for tc in delta.tool_calls:
661
- if tc.index >= len(tool_calls):
662
- tool_calls.append({
663
- "id": tc.id,
664
- "type": "function",
665
- "function": {"name": "", "arguments": ""}
666
- })
667
- if tc.function.name:
668
- tool_calls[tc.index]["function"]["name"] = tc.function.name
669
- if tc.function.arguments:
670
- tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
671
692
  else:
672
693
  # Non-verbose streaming
673
694
  for chunk in litellm.completion(
@@ -681,22 +702,9 @@ class LLM:
681
702
  ):
682
703
  if chunk and chunk.choices and chunk.choices[0].delta:
683
704
  delta = chunk.choices[0].delta
684
- if delta.content:
685
- response_text += delta.content
686
-
687
- # Capture tool calls from streaming chunks if provider supports it
688
- if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
689
- for tc in delta.tool_calls:
690
- if tc.index >= len(tool_calls):
691
- tool_calls.append({
692
- "id": tc.id,
693
- "type": "function",
694
- "function": {"name": "", "arguments": ""}
695
- })
696
- if tc.function.name:
697
- tool_calls[tc.index]["function"]["name"] = tc.function.name
698
- if tc.function.arguments:
699
- tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
705
+ response_text, tool_calls = self._process_stream_delta(
706
+ delta, response_text, tool_calls, formatted_tools
707
+ )
700
708
 
701
709
  response_text = response_text.strip()
702
710
 
@@ -1297,24 +1305,12 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
1297
1305
  ):
1298
1306
  if chunk and chunk.choices and chunk.choices[0].delta:
1299
1307
  delta = chunk.choices[0].delta
1308
+ response_text, tool_calls = self._process_stream_delta(
1309
+ delta, response_text, tool_calls, formatted_tools
1310
+ )
1300
1311
  if delta.content:
1301
- response_text += delta.content
1302
1312
  print("\033[K", end="\r")
1303
1313
  print(f"Generating... {time.time() - start_time:.1f}s", end="\r")
1304
-
1305
- # Capture tool calls from streaming chunks if provider supports it
1306
- if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
1307
- for tc in delta.tool_calls:
1308
- if tc.index >= len(tool_calls):
1309
- tool_calls.append({
1310
- "id": tc.id,
1311
- "type": "function",
1312
- "function": {"name": "", "arguments": ""}
1313
- })
1314
- if tc.function.name:
1315
- tool_calls[tc.index]["function"]["name"] = tc.function.name
1316
- if tc.function.arguments:
1317
- tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
1318
1314
  else:
1319
1315
  # Non-verbose streaming
1320
1316
  async for chunk in await litellm.acompletion(
@@ -1328,22 +1324,9 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
1328
1324
  ):
1329
1325
  if chunk and chunk.choices and chunk.choices[0].delta:
1330
1326
  delta = chunk.choices[0].delta
1331
- if delta.content:
1332
- response_text += delta.content
1333
-
1334
- # Capture tool calls from streaming chunks if provider supports it
1335
- if formatted_tools and self._supports_streaming_tools() and hasattr(delta, 'tool_calls') and delta.tool_calls:
1336
- for tc in delta.tool_calls:
1337
- if tc.index >= len(tool_calls):
1338
- tool_calls.append({
1339
- "id": tc.id,
1340
- "type": "function",
1341
- "function": {"name": "", "arguments": ""}
1342
- })
1343
- if tc.function.name:
1344
- tool_calls[tc.index]["function"]["name"] = tc.function.name
1345
- if tc.function.arguments:
1346
- tool_calls[tc.index]["function"]["arguments"] += tc.function.arguments
1327
+ response_text, tool_calls = self._process_stream_delta(
1328
+ delta, response_text, tool_calls, formatted_tools
1329
+ )
1347
1330
 
1348
1331
  response_text = response_text.strip()
1349
1332
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: praisonaiagents
3
- Version: 0.0.118
3
+ Version: 0.0.119
4
4
  Summary: Praison AI agents for completing complex tasks with Self Reflection Agents
5
5
  Author: Mervin Praison
6
6
  Requires-Python: >=3.10
@@ -16,7 +16,7 @@ praisonaiagents/knowledge/__init__.py,sha256=xL1Eh-a3xsHyIcU4foOWF-JdWYIYBALJH9b
16
16
  praisonaiagents/knowledge/chunking.py,sha256=G6wyHa7_8V0_7VpnrrUXbEmUmptlT16ISJYaxmkSgmU,7678
17
17
  praisonaiagents/knowledge/knowledge.py,sha256=OKPar-XGyAp1ndmbOOdCgqFnTCqpOThYVSIZRxZyP58,15683
18
18
  praisonaiagents/llm/__init__.py,sha256=6lTeQ8jWi1-KiwjCDCmkHo2e-bRLq2dP0s5iJWqjO3s,1421
19
- praisonaiagents/llm/llm.py,sha256=1AGCRpriOx_c3h_Bn6_DNzI1HHz0PM6jieq7RDysA68,109172
19
+ praisonaiagents/llm/llm.py,sha256=mfEUXbjT-0jQmiQ3qqgsyDbzgVpWq_s26VSe6l-heEw,106565
20
20
  praisonaiagents/llm/openai_client.py,sha256=0JvjCDHoH8I8kIt5vvObARkGdVaPWdTIv_FoEQ5EQPA,48973
21
21
  praisonaiagents/mcp/__init__.py,sha256=ibbqe3_7XB7VrIcUcetkZiUZS1fTVvyMy_AqCSFG8qc,240
22
22
  praisonaiagents/mcp/mcp.py,sha256=-fFx4MHffnN2woLnnV7Pzx3-1SFkn2j8Gp5F5ZIwKJ0,19698
@@ -53,7 +53,7 @@ praisonaiagents/tools/xml_tools.py,sha256=iYTMBEk5l3L3ryQ1fkUnNVYK-Nnua2Kx2S0dxN
53
53
  praisonaiagents/tools/yaml_tools.py,sha256=uogAZrhXV9O7xvspAtcTfpKSQYL2nlOTvCQXN94-G9A,14215
54
54
  praisonaiagents/tools/yfinance_tools.py,sha256=s2PBj_1v7oQnOobo2fDbQBACEHl61ftG4beG6Z979ZE,8529
55
55
  praisonaiagents/tools/train/data/generatecot.py,sha256=H6bNh-E2hqL5MW6kX3hqZ05g9ETKN2-kudSjiuU_SD8,19403
56
- praisonaiagents-0.0.118.dist-info/METADATA,sha256=AmgmO7hID63By-em4e2hDiWT10KeiXDpTL39qpxCDQY,1669
57
- praisonaiagents-0.0.118.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
58
- praisonaiagents-0.0.118.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
59
- praisonaiagents-0.0.118.dist-info/RECORD,,
56
+ praisonaiagents-0.0.119.dist-info/METADATA,sha256=O1WvcOBDN5jvW1BAbhYat4usg_Lq6lIbVGR6fTxA2fE,1669
57
+ praisonaiagents-0.0.119.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
58
+ praisonaiagents-0.0.119.dist-info/top_level.txt,sha256=_HsRddrJ23iDx5TTqVUVvXG2HeHBL5voshncAMDGjtA,16
59
+ praisonaiagents-0.0.119.dist-info/RECORD,,