langroid 0.1.160__py3-none-any.whl → 0.1.162__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.
@@ -50,7 +50,7 @@ class ChatAgentConfig(AgentConfig):
50
50
  depending on config settings and availability of fn-calling.
51
51
  """
52
52
  if self.use_functions_api and not fn_available:
53
- logger.warning(
53
+ logger.debug(
54
54
  """
55
55
  You have enabled `use_functions_api` but the LLM does not support it.
56
56
  So we will enable `use_tools` instead, so we can use
@@ -63,7 +63,7 @@ class ChatAgentConfig(AgentConfig):
63
63
  if not self.use_functions_api or not self.use_tools:
64
64
  return
65
65
  if self.use_functions_api and self.use_tools:
66
- logger.warning(
66
+ logger.debug(
67
67
  """
68
68
  You have enabled both `use_tools` and `use_functions_api`.
69
69
  Turning off `use_tools`, since the LLM supports function-calling.
@@ -84,6 +84,12 @@ class LanceDocChatAgent(DocChatAgent):
84
84
  logger.error(f"Error setting up documents: {e}")
85
85
  # say DONE with err msg so it goes back to LanceFilterAgent
86
86
  return f"{DONE} Possible Filter Error:\n {e}"
87
+ if plan.query is None or plan.query.strip() == "":
88
+ # Empty query, say DONE with a message to parent's LLM to try again
89
+ return """DONE
90
+ Rephrased query in QueryPlan cannot be empty.
91
+ Please try again.
92
+ """
87
93
  # update the filter so it is used in the DocChatAgent
88
94
  self.config.filter = plan.filter or None
89
95
  if plan.dataframe_calc:
@@ -227,8 +227,10 @@ class SQLChatAgent(ChatAgent):
227
227
  if isinstance(msg, ChatDocument) and msg.function_call is not None:
228
228
  sender_name = msg.function_call.name
229
229
 
230
+ content = results.content if isinstance(results, ChatDocument) else results
231
+
230
232
  return ChatDocument(
231
- content=results,
233
+ content=content,
232
234
  metadata=ChatDocMetaData(
233
235
  source=Entity.AGENT,
234
236
  sender=Entity.AGENT,
langroid/parsing/utils.py CHANGED
@@ -101,14 +101,33 @@ def split_paragraphs(text: str) -> List[str]:
101
101
  return [para.strip() for para in paras if para.strip()]
102
102
 
103
103
 
104
- def number_segments(s: str, len: int = 1) -> str:
104
+ def split_newlines(text: str) -> List[str]:
105
+ """
106
+ Split the input text into lines using "\n" as the delimiter.
107
+
108
+ Args:
109
+ text (str): The input text.
110
+
111
+ Returns:
112
+ list: A list of lines.
113
+ """
114
+ lines = re.split(r"\n", text)
115
+ return [line.strip() for line in lines if line.strip()]
116
+
117
+
118
+ def number_segments(s: str, granularity: int = 1) -> str:
105
119
  """
106
120
  Number the segments in a given text, preserving paragraph structure.
107
- A segment is a sequence of `len` consecutive sentences.
121
+ A segment is a sequence of `len` consecutive "sentences", where a "sentence"
122
+ is either a normal sentence, or if there isn't enough punctuation to properly
123
+ identify sentences, then we use a pseudo-sentence via heuristics (split by newline
124
+ or failing that, just split every 40 words). The goal here is simply to number
125
+ segments at a reasonable granularity so the LLM can identify relevant segments,
126
+ in the RelevanceExtractorAgent.
108
127
 
109
128
  Args:
110
129
  s (str): The input text.
111
- len (int): The number of sentences in a segment.
130
+ granularity (int): The number of sentences in a segment.
112
131
  If this is -1, then the entire text is treated as a single segment,
113
132
  and is numbered as <#1#>.
114
133
 
@@ -119,7 +138,7 @@ def number_segments(s: str, len: int = 1) -> str:
119
138
  >>> number_segments("Hello world! How are you? Have a good day.")
120
139
  '<#1#> Hello world! <#2#> How are you? <#3#> Have a good day.'
121
140
  """
122
- if len < 0:
141
+ if granularity < 0:
123
142
  return "<#1#> " + s
124
143
  numbered_text = []
125
144
  count = 0
@@ -127,9 +146,34 @@ def number_segments(s: str, len: int = 1) -> str:
127
146
  paragraphs = split_paragraphs(s)
128
147
  for paragraph in paragraphs:
129
148
  sentences = nltk.sent_tokenize(paragraph)
149
+ # Some docs are problematic (e.g. resumes) and have no (or too few) periods,
150
+ # so we can't split usefully into sentences.
151
+ # We try a series of heuristics to split into sentences,
152
+ # until the avg num words per sentence is less than 40.
153
+ avg_words_per_sentence = sum(
154
+ len(nltk.word_tokenize(sentence)) for sentence in sentences
155
+ ) / len(sentences)
156
+ if avg_words_per_sentence > 40:
157
+ sentences = split_newlines(paragraph)
158
+ avg_words_per_sentence = sum(
159
+ len(nltk.word_tokenize(sentence)) for sentence in sentences
160
+ ) / len(sentences)
161
+ if avg_words_per_sentence > 40:
162
+ # Still too long, just split on every 40 words
163
+ sentences = []
164
+ for sentence in nltk.sent_tokenize(paragraph):
165
+ words = nltk.word_tokenize(sentence)
166
+ for i in range(0, len(words), 40):
167
+ # if there are less than 20 words left after this,
168
+ # just add them to the last sentence and break
169
+ if len(words) - i < 20:
170
+ sentences.append(" ".join(words[i:]))
171
+ break
172
+ else:
173
+ sentences.append(" ".join(words[i : i + 40]))
130
174
  for i, sentence in enumerate(sentences):
131
- num = count // len + 1
132
- number_prefix = f"<#{num}#>" if count % len == 0 else ""
175
+ num = count // granularity + 1
176
+ number_prefix = f"<#{num}#>" if count % granularity == 0 else ""
133
177
  sentence = f"{number_prefix} {sentence}"
134
178
  count += 1
135
179
  sentences[i] = sentence
@@ -140,7 +184,7 @@ def number_segments(s: str, len: int = 1) -> str:
140
184
 
141
185
 
142
186
  def number_sentences(s: str) -> str:
143
- return number_segments(s, len=1)
187
+ return number_segments(s, granularity=1)
144
188
 
145
189
 
146
190
  def parse_number_range_list(specs: str) -> List[int]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.1.160
3
+ Version: 0.1.162
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -2,14 +2,14 @@ langroid/__init__.py,sha256=mlQxyJTPRJjTon0D5MlzpMHQ0jwdzSIEpiB0A6mZR7A,477
2
2
  langroid/agent/__init__.py,sha256=ZqDw3Ktw7XGDl6mC8DN61F71V4ckf0rBoEOydH9l6C4,428
3
3
  langroid/agent/base.py,sha256=Cs-TQV_a5Vxdt0A3p1rvW1XGDN7g2zVqtyBhGco0_EE,33156
4
4
  langroid/agent/batch.py,sha256=Cg7Qv1yGi_M9rMl38_4-hjXPsoLlZrOSXDhbOFqUcKY,5593
5
- langroid/agent/chat_agent.py,sha256=TaSxTnA6jA1QnbClkyPxuFZXbHDS2hg_bczyWpOuDT0,36161
5
+ langroid/agent/chat_agent.py,sha256=geQU3F20OoEU_OmfeHq1iEc4FWBiPBbFlkE40J27zoo,36157
6
6
  langroid/agent/chat_document.py,sha256=kbep6196vfTwEKNeMw6PB656W6wf-AFDT01IJxL9tIM,7181
7
7
  langroid/agent/helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  langroid/agent/junk,sha256=LxfuuW7Cijsg0szAzT81OjWWv1PMNI-6w_-DspVIO2s,339
9
9
  langroid/agent/openai_assistant.py,sha256=yBtxis64XOnxtJzlkwUoTm-wCyvKr4DGo9-laXYMok0,32654
10
10
  langroid/agent/special/__init__.py,sha256=PLGt63iwNnSCCigRYcqicD8AUXwdV_HRUWffRHllUC4,510
11
11
  langroid/agent/special/doc_chat_agent.py,sha256=0XMUTyIAmL-looB_Xb6TsljoywiiDfF6GjgldlL2K3E,44585
12
- langroid/agent/special/lance_doc_chat_agent.py,sha256=xZvB4adgGBp8L79wi1Z77kGkZmTTJg8dZU60heeO5cc,7570
12
+ langroid/agent/special/lance_doc_chat_agent.py,sha256=2qTERApPRr9OgQzb7KASw6SH5Xo8AKQfFHf7i2AZ4u8,7861
13
13
  langroid/agent/special/lance_rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  langroid/agent/special/lance_rag/critic_agent.py,sha256=9izW4keCxVZEqrFOgyVUHD7N1vTXLkRynXYYd1Vpwzw,5785
15
15
  langroid/agent/special/lance_rag/lance_rag_task.py,sha256=l_HQgrYY-CX2FwIsS961aEF3bYog3GDYo98fj0C0mSk,2889
@@ -18,7 +18,7 @@ langroid/agent/special/lance_rag/query_planner_agent.py,sha256=Tf0-70Di4mw1B6efS
18
18
  langroid/agent/special/relevance_extractor_agent.py,sha256=Z0OJmpCOESRX0Viar3JRcjjnDBhSA8useD1ZDflIo0s,4571
19
19
  langroid/agent/special/retriever_agent.py,sha256=uu6vqFg85uCVM-_DrXesYe2gH_-WcoHhlsKRlLuZPXk,1867
20
20
  langroid/agent/special/sql/__init__.py,sha256=3kR5nC0wnYIzmMrr9L8RJa7JAJpbwBLx7KKygiwz0v0,111
21
- langroid/agent/special/sql/sql_chat_agent.py,sha256=fU1nwlMu6RirsEvM9boIUkhDJborYnL9aXS9RkkTrnQ,12832
21
+ langroid/agent/special/sql/sql_chat_agent.py,sha256=sFxApcIMc7u31aEZLV01Zrtn8ZLYHZ74kjWfOJpVKoA,12917
22
22
  langroid/agent/special/sql/utils/__init__.py,sha256=_IBHt3iNXvPqxvDrs5_T86qdj0gPugVGnGNi6Cx7F-I,238
23
23
  langroid/agent/special/sql/utils/description_extractors.py,sha256=GcQ82IhKPInS_3TOqRgD4iRUQt-Ez4WG9vNHsV0V85Q,4494
24
24
  langroid/agent/special/sql/utils/populate_metadata.py,sha256=zRjw31a1ZXvpx9bcmbtC2mngdHl-bp1ZNHStcPG8_Qk,2712
@@ -70,7 +70,7 @@ langroid/parsing/table_loader.py,sha256=qNM4obT_0Y4tjrxNBCNUYjKQ9oETCZ7FbolKBTcz
70
70
  langroid/parsing/url_loader.py,sha256=RZCX1RJuQpTatJjBOU74_gJ5Ab7xwarRmFh5ON4n_G4,2279
71
71
  langroid/parsing/url_loader_cookies.py,sha256=Lg4sNpRz9MByWq2mde6T0hKv68VZSV3mtMjNEHuFeSU,2327
72
72
  langroid/parsing/urls.py,sha256=Nv4yCWQLLBEjaiRdaZZVQNBEl_cfK_V6cVuPm91wGtU,7686
73
- langroid/parsing/utils.py,sha256=AaUt7mnQ-VNBI-pIDr-ZtprmeKHOv0LwdonaPxmI47g,7801
73
+ langroid/parsing/utils.py,sha256=g5tRl0HWLXYzkiwYdMfreamzG76tK6ieiUqPNx35ln4,9845
74
74
  langroid/parsing/web_search.py,sha256=hGUVoSJNdpoT5rsm-ikAteMiUropHrzKaxN8EVVqO2U,2496
75
75
  langroid/prompts/__init__.py,sha256=aTW86CbDZM7tntqiTVeNLYJv7pbRDcKOI3qHVXCEHUY,99
76
76
  langroid/prompts/dialog.py,sha256=SpfiSyofSgy2pwD1YboHR_yHO3LEEMbv6j2sm874jKo,331
@@ -103,7 +103,7 @@ langroid/vector_store/meilisearch.py,sha256=d2huA9P-NoYRuAQ9ZeXJmMKr7ry8u90RUSR2
103
103
  langroid/vector_store/momento.py,sha256=j6Eo6oIDN2fe7lsBOlCXJn3uvvERHHTFL5QJfeREeOM,10044
104
104
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
105
105
  langroid/vector_store/qdrantdb.py,sha256=qt7Dye6rcgoe0551WzmOxRGIlJfL87D4MX7HdqxuEok,13393
106
- langroid-0.1.160.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
107
- langroid-0.1.160.dist-info/METADATA,sha256=C2tjQ0HKr3e3x0iWWa6vrbraLd9qgHZuslb1nrN5ERA,42745
108
- langroid-0.1.160.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
109
- langroid-0.1.160.dist-info/RECORD,,
106
+ langroid-0.1.162.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
107
+ langroid-0.1.162.dist-info/METADATA,sha256=j6ZBZx4nLwIX4NNMNpwu4iDYIxtD6lOFjTFZ3n53zic,42745
108
+ langroid-0.1.162.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
109
+ langroid-0.1.162.dist-info/RECORD,,