langroid 0.50.4__py3-none-any.whl → 0.50.6__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.
- langroid/agent/chat_document.py +89 -83
- {langroid-0.50.4.dist-info → langroid-0.50.6.dist-info}/METADATA +1 -1
- {langroid-0.50.4.dist-info → langroid-0.50.6.dist-info}/RECORD +5 -5
- {langroid-0.50.4.dist-info → langroid-0.50.6.dist-info}/WHEEL +0 -0
- {langroid-0.50.4.dist-info → langroid-0.50.6.dist-info}/licenses/LICENSE +0 -0
langroid/agent/chat_document.py
CHANGED
@@ -215,9 +215,17 @@ class ChatDocument(Document):
|
|
215
215
|
"""
|
216
216
|
tool_type = "" # FUNC or TOOL
|
217
217
|
tool = "" # tool name or function name
|
218
|
+
oai_tools = (
|
219
|
+
[]
|
220
|
+
if self.oai_tool_calls is None
|
221
|
+
else [t for t in self.oai_tool_calls if t.function is not None]
|
222
|
+
)
|
218
223
|
if self.function_call is not None:
|
219
224
|
tool_type = "FUNC"
|
220
225
|
tool = self.function_call.name
|
226
|
+
elif len(oai_tools) > 0:
|
227
|
+
tool_type = "OAI_TOOL"
|
228
|
+
tool = ",".join(t.function.name for t in oai_tools) # type: ignore
|
221
229
|
else:
|
222
230
|
try:
|
223
231
|
json_tools = self.get_tool_names()
|
@@ -354,90 +362,88 @@ class ChatDocument(Document):
|
|
354
362
|
oai_tool_calls = None
|
355
363
|
tool_id = "" # for OpenAI Assistant
|
356
364
|
chat_document_id: str = ""
|
357
|
-
if isinstance(message,
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
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
|
384
419
|
):
|
385
|
-
#
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
message.
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
# ChatDocument.content has result of a single tool-call
|
413
|
-
return [
|
414
|
-
LLMMessage(
|
415
|
-
role=Role.TOOL,
|
416
|
-
tool_call_id=message.metadata.oai_tool_id,
|
417
|
-
content=content,
|
418
|
-
chat_document_id=chat_document_id,
|
419
|
-
)
|
420
|
-
]
|
421
|
-
elif message.oai_tool_id2result is not None:
|
422
|
-
# Case 2:
|
423
|
-
# There were > 1 tool-calls awaiting response,
|
424
|
-
assert (
|
425
|
-
len(message.oai_tool_id2result) > 1
|
426
|
-
), "oai_tool_id2result must have more than 1 item."
|
427
|
-
return [
|
428
|
-
LLMMessage(
|
429
|
-
role=Role.TOOL,
|
430
|
-
tool_call_id=tool_id,
|
431
|
-
content=result,
|
432
|
-
chat_document_id=chat_document_id,
|
433
|
-
)
|
434
|
-
for tool_id, result in message.oai_tool_id2result.items()
|
435
|
-
]
|
436
|
-
elif message.metadata.sender == Entity.LLM:
|
437
|
-
sender_role = Role.ASSISTANT
|
438
|
-
else:
|
439
|
-
# LLM can only respond to text content, so extract it
|
440
|
-
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
|
441
447
|
|
442
448
|
return [
|
443
449
|
LLMMessage(
|
@@ -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=
|
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
|
@@ -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.
|
133
|
-
langroid-0.50.
|
134
|
-
langroid-0.50.
|
135
|
-
langroid-0.50.
|
132
|
+
langroid-0.50.6.dist-info/METADATA,sha256=JsIZE0WSSPm0jpB-5UX2Bfdvk6-txTtUo4J49ryyQIw,63641
|
133
|
+
langroid-0.50.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
134
|
+
langroid-0.50.6.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
135
|
+
langroid-0.50.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|