langroid 0.50.5__py3-none-any.whl → 0.50.7__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.
@@ -362,90 +362,88 @@ class ChatDocument(Document):
362
362
  oai_tool_calls = None
363
363
  tool_id = "" # for OpenAI Assistant
364
364
  chat_document_id: str = ""
365
- if isinstance(message, ChatDocument):
366
- content = message.content or to_string(message.content_any) or ""
367
- fun_call = message.function_call
368
- oai_tool_calls = message.oai_tool_calls
369
- if message.metadata.sender == Entity.USER and fun_call is not None:
370
- # This may happen when a (parent agent's) LLM generates a
371
- # a Function-call, and it ends up being sent to the current task's
372
- # LLM (possibly because the function-call is mis-named or has other
373
- # issues and couldn't be handled by handler methods).
374
- # But a function-call can only be generated by an entity with
375
- # Role.ASSISTANT, so we instead put the content of the function-call
376
- # in the content of the message.
377
- content += " " + str(fun_call)
378
- fun_call = None
379
- if message.metadata.sender == Entity.USER and oai_tool_calls is not None:
380
- # same reasoning as for function-call above
381
- content += " " + "\n\n".join(str(tc) for tc in oai_tool_calls)
382
- oai_tool_calls = None
383
- sender_name = message.metadata.sender_name
384
- tool_ids = message.metadata.tool_ids
385
- tool_id = tool_ids[-1] if len(tool_ids) > 0 else ""
386
- chat_document_id = message.id()
387
- if message.metadata.sender == Entity.SYSTEM:
388
- sender_role = Role.SYSTEM
389
- if (
390
- message.metadata.parent is not None
391
- and message.metadata.parent.function_call is not None
365
+ if isinstance(message, str):
366
+ message = ChatDocument.from_str(message)
367
+ content = message.content or to_string(message.content_any) or ""
368
+ fun_call = message.function_call
369
+ oai_tool_calls = message.oai_tool_calls
370
+ if message.metadata.sender == Entity.USER and fun_call is not None:
371
+ # This may happen when a (parent agent's) LLM generates a
372
+ # a Function-call, and it ends up being sent to the current task's
373
+ # LLM (possibly because the function-call is mis-named or has other
374
+ # issues and couldn't be handled by handler methods).
375
+ # But a function-call can only be generated by an entity with
376
+ # Role.ASSISTANT, so we instead put the content of the function-call
377
+ # in the content of the message.
378
+ content += " " + str(fun_call)
379
+ fun_call = None
380
+ if message.metadata.sender == Entity.USER and oai_tool_calls is not None:
381
+ # same reasoning as for function-call above
382
+ content += " " + "\n\n".join(str(tc) for tc in oai_tool_calls)
383
+ oai_tool_calls = None
384
+ sender_name = message.metadata.sender_name
385
+ tool_ids = message.metadata.tool_ids
386
+ tool_id = tool_ids[-1] if len(tool_ids) > 0 else ""
387
+ chat_document_id = message.id()
388
+ if message.metadata.sender == Entity.SYSTEM:
389
+ sender_role = Role.SYSTEM
390
+ if (
391
+ message.metadata.parent is not None
392
+ and message.metadata.parent.function_call is not None
393
+ ):
394
+ # This is a response to a function call, so set the role to FUNCTION.
395
+ sender_role = Role.FUNCTION
396
+ sender_name = message.metadata.parent.function_call.name
397
+ elif oai_tools is not None and len(oai_tools) > 0:
398
+ pending_tool_ids = [tc.id for tc in oai_tools]
399
+ # The ChatAgent has pending OpenAI tool-call(s),
400
+ # so the current ChatDocument contains
401
+ # results for some/all/none of them.
402
+
403
+ if len(oai_tools) == 1:
404
+ # Case 1:
405
+ # There was exactly 1 pending tool-call, and in this case
406
+ # the result would be a plain string in `content`
407
+ return [
408
+ LLMMessage(
409
+ role=Role.TOOL,
410
+ tool_call_id=oai_tools[0].id,
411
+ content=content,
412
+ chat_document_id=chat_document_id,
413
+ )
414
+ ]
415
+
416
+ elif (
417
+ message.metadata.oai_tool_id is not None
418
+ and message.metadata.oai_tool_id in pending_tool_ids
392
419
  ):
393
- # This is a response to a function call, so set the role to FUNCTION.
394
- sender_role = Role.FUNCTION
395
- sender_name = message.metadata.parent.function_call.name
396
- elif oai_tools is not None and len(oai_tools) > 0:
397
- pending_tool_ids = [tc.id for tc in oai_tools]
398
- # The ChatAgent has pending OpenAI tool-call(s),
399
- # so the current ChatDocument contains
400
- # results for some/all/none of them.
401
-
402
- if len(oai_tools) == 1:
403
- # Case 1:
404
- # There was exactly 1 pending tool-call, and in this case
405
- # the result would be a plain string in `content`
406
- return [
407
- LLMMessage(
408
- role=Role.TOOL,
409
- tool_call_id=oai_tools[0].id,
410
- content=content,
411
- chat_document_id=chat_document_id,
412
- )
413
- ]
414
-
415
- elif (
416
- message.metadata.oai_tool_id is not None
417
- and message.metadata.oai_tool_id in pending_tool_ids
418
- ):
419
- # Case 2:
420
- # ChatDocument.content has result of a single tool-call
421
- return [
422
- LLMMessage(
423
- role=Role.TOOL,
424
- tool_call_id=message.metadata.oai_tool_id,
425
- content=content,
426
- chat_document_id=chat_document_id,
427
- )
428
- ]
429
- elif message.oai_tool_id2result is not None:
430
- # Case 2:
431
- # There were > 1 tool-calls awaiting response,
432
- assert (
433
- len(message.oai_tool_id2result) > 1
434
- ), "oai_tool_id2result must have more than 1 item."
435
- return [
436
- LLMMessage(
437
- role=Role.TOOL,
438
- tool_call_id=tool_id,
439
- content=result,
440
- chat_document_id=chat_document_id,
441
- )
442
- for tool_id, result in message.oai_tool_id2result.items()
443
- ]
444
- elif message.metadata.sender == Entity.LLM:
445
- sender_role = Role.ASSISTANT
446
- else:
447
- # LLM can only respond to text content, so extract it
448
- content = message
420
+ # Case 2:
421
+ # ChatDocument.content has result of a single tool-call
422
+ return [
423
+ LLMMessage(
424
+ role=Role.TOOL,
425
+ tool_call_id=message.metadata.oai_tool_id,
426
+ content=content,
427
+ chat_document_id=chat_document_id,
428
+ )
429
+ ]
430
+ elif message.oai_tool_id2result is not None:
431
+ # Case 2:
432
+ # There were > 1 tool-calls awaiting response,
433
+ assert (
434
+ len(message.oai_tool_id2result) > 1
435
+ ), "oai_tool_id2result must have more than 1 item."
436
+ return [
437
+ LLMMessage(
438
+ role=Role.TOOL,
439
+ tool_call_id=tool_id,
440
+ content=result,
441
+ chat_document_id=chat_document_id,
442
+ )
443
+ for tool_id, result in message.oai_tool_id2result.items()
444
+ ]
445
+ elif message.metadata.sender == Entity.LLM:
446
+ sender_role = Role.ASSISTANT
449
447
 
450
448
  return [
451
449
  LLMMessage(
@@ -55,8 +55,7 @@ class WebSearchResult:
55
55
  try:
56
56
  # First check headers only to get content length and type
57
57
  head_response: Response = requests.head(self.link, timeout=5)
58
- if head_response.status_code != 200:
59
- return f"Error: HTTP {head_response.status_code} for {self.link}"
58
+ content_type = head_response.headers.get("content-type", "").lower()
60
59
 
61
60
  # Skip large files
62
61
  content_length = int(head_response.headers.get("content-length", 0))
@@ -64,8 +63,16 @@ class WebSearchResult:
64
63
  return (
65
64
  f"Error: Content too large ({content_length} bytes) for {self.link}"
66
65
  )
66
+ # Skip non-HTML content types
67
+ if content_type and not any(
68
+ html_type in content_type
69
+ for html_type in ["text/html", "application/xhtml", "text/plain"]
70
+ ):
71
+ return f"Skipping Content type '{content_type}' " f"in {self.link}"
67
72
 
68
73
  response: Response = requests.get(self.link, timeout=10)
74
+ if response.status_code != 200:
75
+ return f"Error: HTTP {response.status_code} for {self.link}"
69
76
 
70
77
  import warnings
71
78
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langroid
3
- Version: 0.50.5
3
+ Version: 0.50.7
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  Author-email: Prasad Chalasani <pchalasani@gmail.com>
6
6
  License: MIT
@@ -6,7 +6,7 @@ langroid/agent/__init__.py,sha256=ll0Cubd2DZ-fsCMl7e10hf9ZjFGKzphfBco396IKITY,78
6
6
  langroid/agent/base.py,sha256=bs5OLCf534mhsdR7Rgf27GqVNuSV2bOVbD46Y86mGFA,79829
7
7
  langroid/agent/batch.py,sha256=vi1r5i1-vN80WfqHDSwjEym_KfGsqPGUtwktmiK1nuk,20635
8
8
  langroid/agent/chat_agent.py,sha256=m1alf-KNJSU6PeFF6ocwTHSG0cmTE-iy1o7UYAvRGQE,85081
9
- langroid/agent/chat_document.py,sha256=T7ybVjpQezlMxTB0OylROI0XfrYVIF9NUKkepKeR_wU,18199
9
+ langroid/agent/chat_document.py,sha256=gWceR8mcggyGbJePJQgVvqzVivYlfPlFp8pUZ7yUZvg,17821
10
10
  langroid/agent/openai_assistant.py,sha256=JkAcs02bIrgPNVvUWVR06VCthc5-ulla2QMBzux_q6o,34340
11
11
  langroid/agent/task.py,sha256=HB6N-Jn80HFqCf0ZYOC1v3Bn3oO7NLjShHQJJFwW0q4,90557
12
12
  langroid/agent/tool_message.py,sha256=BhjP-_TfQ2tgxuY4Yo_JHLOwwt0mJ4BwjPnREvEY4vk,14744
@@ -96,7 +96,7 @@ langroid/parsing/table_loader.py,sha256=qNM4obT_0Y4tjrxNBCNUYjKQ9oETCZ7FbolKBTcz
96
96
  langroid/parsing/url_loader.py,sha256=NQuCxa-hTOuxLZDq4xKLvPfGVB4IWFzh2ItqWq297DI,15675
97
97
  langroid/parsing/urls.py,sha256=Tjzr64YsCusiYkY0LEGB5-rSuX8T2P_4DVoOFKAeKuI,8081
98
98
  langroid/parsing/utils.py,sha256=WwqzOhbQRlorbVvddDIZKv9b1KqZCBDm955lgIHDXRw,12828
99
- langroid/parsing/web_search.py,sha256=sARV1Tku4wiInhuCz0kRaMHcoF6Ok6CLu7vapLS8hjs,8222
99
+ langroid/parsing/web_search.py,sha256=atk8wIpOfiGTvW8yL_26TvjvyY2zD24xIHIi0QjEklI,8599
100
100
  langroid/prompts/__init__.py,sha256=RW11vK6jiLPuaUh4GpeFvstti73gkm8_rDMtrbo2YsU,142
101
101
  langroid/prompts/dialog.py,sha256=SpfiSyofSgy2pwD1YboHR_yHO3LEEMbv6j2sm874jKo,331
102
102
  langroid/prompts/prompts_config.py,sha256=p_lp9nbMuQwhhMwAZsOxveRw9C0ZFZvql7pdIfgVZYo,143
@@ -129,7 +129,7 @@ langroid/vector_store/pineconedb.py,sha256=otxXZNaBKb9f_H75HTaU3lMHiaR2NUp5MqwLZ
129
129
  langroid/vector_store/postgres.py,sha256=wHPtIi2qM4fhO4pMQr95pz1ZCe7dTb2hxl4VYspGZoA,16104
130
130
  langroid/vector_store/qdrantdb.py,sha256=O6dSBoDZ0jzfeVBd7LLvsXu083xs2fxXtPa9gGX3JX4,18443
131
131
  langroid/vector_store/weaviatedb.py,sha256=Yn8pg139gOy3zkaPfoTbMXEEBCiLiYa1MU5d_3UA1K4,11847
132
- langroid-0.50.5.dist-info/METADATA,sha256=-9cQads1gvMq_WSH3f9mcoe9agU5RkRHIg6yndUIhu0,63641
133
- langroid-0.50.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
- langroid-0.50.5.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
135
- langroid-0.50.5.dist-info/RECORD,,
132
+ langroid-0.50.7.dist-info/METADATA,sha256=Am8GortMmvBBtL6aMTS88xmzYCa3ywMFEgraPvNYsTQ,63641
133
+ langroid-0.50.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
+ langroid-0.50.7.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
135
+ langroid-0.50.7.dist-info/RECORD,,