langroid 0.1.160__tar.gz → 0.1.162__tar.gz
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-0.1.160 → langroid-0.1.162}/PKG-INFO +1 -1
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/chat_agent.py +2 -2
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_doc_chat_agent.py +6 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/sql_chat_agent.py +3 -1
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/utils.py +51 -7
- {langroid-0.1.160 → langroid-0.1.162}/pyproject.toml +1 -1
- {langroid-0.1.160 → langroid-0.1.162}/LICENSE +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/README.md +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/base.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/batch.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/chat_document.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/helpers.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/junk +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/openai_assistant.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/doc_chat_agent.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_rag/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_rag/lance_tools.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/relevance_extractor_agent.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/retriever_agent.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/utils/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/utils/system_message.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/utils/tools.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/table_chat_agent.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/task.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tool_message.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/extract_tool.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/generator_tool.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/google_search_tool.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/recipient_tool.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/run_python_code.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent/tools/segment_extract_tool.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/agent_config.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/cachedb/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/cachedb/base.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/cachedb/momento_cachedb.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/cachedb/redis_cachedb.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/embedding_models/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/embedding_models/base.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/embedding_models/clustering.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/embedding_models/models.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/azure_openai.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/base.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/config.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/openai_assistants.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/openai_gpt.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/prompt_formatter/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/prompt_formatter/base.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/utils.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/mytypes.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/agent_chats.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/code-parsing.md +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/code_parser.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/config.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/document_parser.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/json.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/para_sentence_split.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/parser.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/repo_loader.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/search.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/spider.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/table_loader.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/url_loader.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/url_loader_cookies.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/urls.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/parsing/web_search.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/prompts/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/prompts/dialog.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/prompts/prompts_config.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/prompts/templates.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/prompts/transforms.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/algorithms/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/algorithms/graph.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/configuration.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/constants.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/docker.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/globals.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/llms/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/llms/strings.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/logging.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/output/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/output/printing.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/pandas_utils.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/pydantic_utils.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/system.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/web/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/web/login.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/utils/web/selenium_login.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/__init__.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/base.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/chromadb.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/lancedb.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/meilisearch.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/momento.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/qdrant_cloud.py +0 -0
- {langroid-0.1.160 → langroid-0.1.162}/langroid/vector_store/qdrantdb.py +0 -0
@@ -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.
|
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.
|
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=
|
233
|
+
content=content,
|
232
234
|
metadata=ChatDocMetaData(
|
233
235
|
source=Entity.AGENT,
|
234
236
|
sender=Entity.AGENT,
|
@@ -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
|
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
|
-
|
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
|
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 //
|
132
|
-
number_prefix = f"<#{num}#>" if count %
|
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,
|
187
|
+
return number_segments(s, granularity=1)
|
144
188
|
|
145
189
|
|
146
190
|
def parse_number_range_list(specs: str) -> List[int]:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/lance_rag/query_planner_agent.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.1.160 → langroid-0.1.162}/langroid/agent/special/sql/utils/description_extractors.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.1.160 → langroid-0.1.162}/langroid/language_models/prompt_formatter/llama2_formatter.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|