langroid 0.45.2__py3-none-any.whl → 0.45.4__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/base.py +7 -6
- langroid/agent/chat_agent.py +2 -0
- langroid/parsing/document_parser.py +4 -4
- langroid/parsing/parser.py +3 -0
- langroid/utils/output/citations.py +12 -3
- {langroid-0.45.2.dist-info → langroid-0.45.4.dist-info}/METADATA +1 -1
- {langroid-0.45.2.dist-info → langroid-0.45.4.dist-info}/RECORD +9 -9
- {langroid-0.45.2.dist-info → langroid-0.45.4.dist-info}/WHEEL +0 -0
- {langroid-0.45.2.dist-info → langroid-0.45.4.dist-info}/licenses/LICENSE +0 -0
langroid/agent/base.py
CHANGED
@@ -1363,8 +1363,7 @@ class Agent(ABC):
|
|
1363
1363
|
|
1364
1364
|
has_orch = any(isinstance(t, ORCHESTRATION_TOOLS) for t in tools)
|
1365
1365
|
if has_orch and len(tools) > 1:
|
1366
|
-
|
1367
|
-
return [err_str for _ in tools]
|
1366
|
+
return ["ERROR: Use ONE tool at a time!"] * len(tools)
|
1368
1367
|
|
1369
1368
|
return []
|
1370
1369
|
|
@@ -1499,8 +1498,6 @@ class Agent(ABC):
|
|
1499
1498
|
# as a response to the tool message even though the tool was not intended
|
1500
1499
|
# for this agent.
|
1501
1500
|
return None
|
1502
|
-
if len(tools) > 1 and not self.config.allow_multiple_tools:
|
1503
|
-
return self.to_ChatDocument("ERROR: Use ONE tool at a time!")
|
1504
1501
|
if len(tools) == 0:
|
1505
1502
|
fallback_result = self.handle_message_fallback(msg)
|
1506
1503
|
if fallback_result is None:
|
@@ -1509,10 +1506,14 @@ class Agent(ABC):
|
|
1509
1506
|
fallback_result,
|
1510
1507
|
chat_doc=msg if isinstance(msg, ChatDocument) else None,
|
1511
1508
|
)
|
1512
|
-
chat_doc = msg if isinstance(msg, ChatDocument) else None
|
1513
1509
|
|
1514
|
-
results =
|
1510
|
+
results: List[str | ChatDocument | None] = []
|
1511
|
+
if len(tools) > 1 and not self.config.allow_multiple_tools:
|
1512
|
+
results = ["ERROR: Use ONE tool at a time!"] * len(tools)
|
1513
|
+
if not results:
|
1514
|
+
results = self._get_multiple_orch_tool_errs(tools)
|
1515
1515
|
if not results:
|
1516
|
+
chat_doc = msg if isinstance(msg, ChatDocument) else None
|
1516
1517
|
results = [self.handle_tool_message(t, chat_doc=chat_doc) for t in tools]
|
1517
1518
|
# if there's a solitary ChatDocument|str result, return it as is
|
1518
1519
|
if len(results) == 1 and isinstance(results[0], (str, ChatDocument)):
|
langroid/agent/chat_agent.py
CHANGED
@@ -85,6 +85,8 @@ class ChatAgentConfig(AgentConfig):
|
|
85
85
|
enabled when such tool calls are not desired.
|
86
86
|
output_format_include_defaults: Whether to include fields with default arguments
|
87
87
|
in the output schema
|
88
|
+
full_citations: Whether to show source reference citation + content for each
|
89
|
+
citation, or just the main reference citation.
|
88
90
|
"""
|
89
91
|
|
90
92
|
system_message: str = "You are a helpful assistant."
|
@@ -404,8 +404,8 @@ class DocumentParser(Parser):
|
|
404
404
|
# that it needs to be combined with the next chunk.
|
405
405
|
while len(split) > self.config.chunk_size:
|
406
406
|
# pretty formatting of pages (e.g. 1-3, 4, 5-7)
|
407
|
-
p_0 = int(pages[0])
|
408
|
-
p_n = int(pages[-1])
|
407
|
+
p_0 = int(pages[0]) - self.config.page_number_offset
|
408
|
+
p_n = int(pages[-1]) - self.config.page_number_offset
|
409
409
|
page_str = f"pages {p_0}-{p_n}" if p_0 != p_n else f"page {p_0}"
|
410
410
|
text = self.tokenizer.decode(split[: self.config.chunk_size])
|
411
411
|
docs.append(
|
@@ -426,8 +426,8 @@ class DocumentParser(Parser):
|
|
426
426
|
# since it's already included in the prior chunk;
|
427
427
|
# the only exception is if there have been no chunks so far.
|
428
428
|
if len(split) > self.config.overlap or n_chunks == 0:
|
429
|
-
p_0 = int(pages[0])
|
430
|
-
p_n = int(pages[-1])
|
429
|
+
p_0 = int(pages[0]) - self.config.page_number_offset
|
430
|
+
p_n = int(pages[-1]) - self.config.page_number_offset
|
431
431
|
page_str = f"pages {p_0}-{p_n}" if p_0 != p_n else f"page {p_0}"
|
432
432
|
text = self.tokenizer.decode(split[: self.config.chunk_size])
|
433
433
|
docs.append(
|
langroid/parsing/parser.py
CHANGED
@@ -103,6 +103,9 @@ class ParsingConfig(BaseSettings):
|
|
103
103
|
chunk_size: int = 200 # aim for this many tokens per chunk
|
104
104
|
overlap: int = 50 # overlap between chunks
|
105
105
|
max_chunks: int = 10_000
|
106
|
+
# offset to subtract from page numbers:
|
107
|
+
# e.g. if physical page 12 is displayed as page 1, set page_number_offset = 11
|
108
|
+
page_number_offset: int = 0
|
106
109
|
# aim to have at least this many chars per chunk when truncating due to punctuation
|
107
110
|
min_chunk_chars: int = 350
|
108
111
|
discard_chunk_chars: int = 5 # discard chunks with fewer than this many chars
|
@@ -1,7 +1,10 @@
|
|
1
|
+
import logging
|
1
2
|
from typing import List, Tuple
|
2
3
|
|
3
4
|
from langroid.mytypes import Document
|
4
5
|
|
6
|
+
logger = logging.getLogger(__name__)
|
7
|
+
|
5
8
|
|
6
9
|
def extract_markdown_references(md_string: str) -> List[int]:
|
7
10
|
"""
|
@@ -87,15 +90,21 @@ def format_cited_references(
|
|
87
90
|
full_citations_str = ""
|
88
91
|
if len(citations) > 0:
|
89
92
|
# append [i] source, content for each citation
|
93
|
+
good_citations = [c for c in citations if c > 0 and c <= len(passages)]
|
94
|
+
if len(good_citations) < len(citations):
|
95
|
+
logger.warning(f"Invalid citations: {set(citations) - set(good_citations)}")
|
96
|
+
|
97
|
+
# source and content for each citation
|
90
98
|
full_citations_str = "\n".join(
|
91
99
|
[
|
92
100
|
f"[^{c}] {passages[c-1].metadata.source}"
|
93
101
|
f"\n{format_footnote_text(passages[c-1].content)}"
|
94
|
-
for c in
|
102
|
+
for c in good_citations
|
95
103
|
]
|
96
104
|
)
|
97
|
-
|
105
|
+
|
106
|
+
# source for each citation
|
98
107
|
citations_str = "\n".join(
|
99
|
-
[f"[^{c}] {passages[c-1].metadata.source}" for c in
|
108
|
+
[f"[^{c}] {passages[c-1].metadata.source}" for c in good_citations]
|
100
109
|
)
|
101
110
|
return full_citations_str, citations_str
|
@@ -3,9 +3,9 @@ langroid/exceptions.py,sha256=OPjece_8cwg94DLPcOGA1ddzy5bGh65pxzcHMnssTz8,2995
|
|
3
3
|
langroid/mytypes.py,sha256=wfb320SFnZVTv_CgcLWsvoKBXxAFfY4EISeue8MFqpQ,2912
|
4
4
|
langroid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
langroid/agent/__init__.py,sha256=ll0Cubd2DZ-fsCMl7e10hf9ZjFGKzphfBco396IKITY,786
|
6
|
-
langroid/agent/base.py,sha256=
|
6
|
+
langroid/agent/base.py,sha256=yM7ul2byHhwCFm6w8_4RULkPdhI8XR3n7XqNBS0hD20,79567
|
7
7
|
langroid/agent/batch.py,sha256=vi1r5i1-vN80WfqHDSwjEym_KfGsqPGUtwktmiK1nuk,20635
|
8
|
-
langroid/agent/chat_agent.py,sha256=
|
8
|
+
langroid/agent/chat_agent.py,sha256=Z53oleOUcOXVs_UL90spttGoAooe0mrx3tDtOuhKVms,85214
|
9
9
|
langroid/agent/chat_document.py,sha256=xzMtrPbaW-Y-BnF7kuhr2dorsD-D5rMWzfOqJ8HAoo8,17885
|
10
10
|
langroid/agent/openai_assistant.py,sha256=JkAcs02bIrgPNVvUWVR06VCthc5-ulla2QMBzux_q6o,34340
|
11
11
|
langroid/agent/task.py,sha256=HB6N-Jn80HFqCf0ZYOC1v3Bn3oO7NLjShHQJJFwW0q4,90557
|
@@ -81,10 +81,10 @@ langroid/language_models/prompt_formatter/llama2_formatter.py,sha256=YdcO88qyBeu
|
|
81
81
|
langroid/parsing/__init__.py,sha256=2oUWJJAxIavq9Wtw5RGlkXLq3GF3zgXeVLLW4j7yeb8,1138
|
82
82
|
langroid/parsing/agent_chats.py,sha256=sbZRV9ujdM5QXvvuHVjIi2ysYSYlap-uqfMMUKulrW0,1068
|
83
83
|
langroid/parsing/code_parser.py,sha256=5ze0MBytrGGkU69pA_bJDjRm6QZz_QYfPcIwkagUa7U,3796
|
84
|
-
langroid/parsing/document_parser.py,sha256=
|
84
|
+
langroid/parsing/document_parser.py,sha256=fyCx4X1192asom5tp3DNV4J5Em2u4Z7rCC0FA8dNsSQ,52954
|
85
85
|
langroid/parsing/para_sentence_split.py,sha256=AJBzZojP3zpB-_IMiiHismhqcvkrVBQ3ZINoQyx_bE4,2000
|
86
86
|
langroid/parsing/parse_json.py,sha256=aADo38bAHQhC8on4aWZZzVzSDy-dK35vRLZsFI2ewh8,4756
|
87
|
-
langroid/parsing/parser.py,sha256=
|
87
|
+
langroid/parsing/parser.py,sha256=ZUvBhzMZQWKerbb9UECbcqkNc9wWKuUgPyC8L6baxao,14295
|
88
88
|
langroid/parsing/pdf_utils.py,sha256=rmNJ9UzuBgXTAYwj1TtRJcD8h53x7cizhgyYHKO88I4,1513
|
89
89
|
langroid/parsing/repo_loader.py,sha256=NpysuyzRHvgL3F4BB_wGo5sCUnZ3FOlVCJmZ7CaUdbs,30202
|
90
90
|
langroid/parsing/routing.py,sha256=-FcnlqldzL4ZoxuDwXjQPNHgBe9F9-F4R6q7b_z9CvI,1232
|
@@ -115,7 +115,7 @@ langroid/utils/types.py,sha256=-BvyIf_LmAJ5jR9NC7S4CSVNEr3XayAaxJ5o0TiIej0,2992
|
|
115
115
|
langroid/utils/algorithms/__init__.py,sha256=WylYoZymA0fnzpB4vrsH_0n7WsoLhmuZq8qxsOCjUpM,41
|
116
116
|
langroid/utils/algorithms/graph.py,sha256=JbdpPnUOhw4-D6O7ou101JLA3xPCD0Lr3qaPoFCaRfo,2866
|
117
117
|
langroid/utils/output/__init__.py,sha256=7P0f--4IZneNsTxXY5fd6d6iW-CeVe-KSsl-87sbBPc,340
|
118
|
-
langroid/utils/output/citations.py,sha256=
|
118
|
+
langroid/utils/output/citations.py,sha256=5mhg2-kpBF7qgV82gJbIiUHfoJcpJiK1sAWdDF0o0Wc,3866
|
119
119
|
langroid/utils/output/printing.py,sha256=yzPJZN-8_jyOJmI9N_oLwEDfjMwVgk3IDiwnZ4eK_AE,2962
|
120
120
|
langroid/utils/output/status.py,sha256=rzbE7mDJcgNNvdtylCseQcPGCGghtJvVq3lB-OPJ49E,1049
|
121
121
|
langroid/vector_store/__init__.py,sha256=8ktJUVsVUoc7FMmkUFpFBZu7VMWUqQY9zpm4kEJ8yTs,1537
|
@@ -127,7 +127,7 @@ langroid/vector_store/pineconedb.py,sha256=otxXZNaBKb9f_H75HTaU3lMHiaR2NUp5MqwLZ
|
|
127
127
|
langroid/vector_store/postgres.py,sha256=wHPtIi2qM4fhO4pMQr95pz1ZCe7dTb2hxl4VYspGZoA,16104
|
128
128
|
langroid/vector_store/qdrantdb.py,sha256=O6dSBoDZ0jzfeVBd7LLvsXu083xs2fxXtPa9gGX3JX4,18443
|
129
129
|
langroid/vector_store/weaviatedb.py,sha256=Yn8pg139gOy3zkaPfoTbMXEEBCiLiYa1MU5d_3UA1K4,11847
|
130
|
-
langroid-0.45.
|
131
|
-
langroid-0.45.
|
132
|
-
langroid-0.45.
|
133
|
-
langroid-0.45.
|
130
|
+
langroid-0.45.4.dist-info/METADATA,sha256=_OkZa9etwNRz12dFklGCKBl8k58cZC-XefrycQA8-1g,63335
|
131
|
+
langroid-0.45.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
132
|
+
langroid-0.45.4.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
133
|
+
langroid-0.45.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|