langroid 0.1.85__py3-none-any.whl → 0.1.219__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/__init__.py +95 -0
- langroid/agent/__init__.py +40 -0
- langroid/agent/base.py +222 -91
- langroid/agent/batch.py +264 -0
- langroid/agent/callbacks/chainlit.py +608 -0
- langroid/agent/chat_agent.py +247 -101
- langroid/agent/chat_document.py +41 -4
- langroid/agent/openai_assistant.py +842 -0
- langroid/agent/special/__init__.py +50 -0
- langroid/agent/special/doc_chat_agent.py +837 -141
- langroid/agent/special/lance_doc_chat_agent.py +258 -0
- langroid/agent/special/lance_rag/__init__.py +9 -0
- langroid/agent/special/lance_rag/critic_agent.py +136 -0
- langroid/agent/special/lance_rag/lance_rag_task.py +80 -0
- langroid/agent/special/lance_rag/query_planner_agent.py +180 -0
- langroid/agent/special/lance_tools.py +44 -0
- langroid/agent/special/neo4j/__init__.py +0 -0
- langroid/agent/special/neo4j/csv_kg_chat.py +174 -0
- langroid/agent/special/neo4j/neo4j_chat_agent.py +370 -0
- langroid/agent/special/neo4j/utils/__init__.py +0 -0
- langroid/agent/special/neo4j/utils/system_message.py +46 -0
- langroid/agent/special/relevance_extractor_agent.py +127 -0
- langroid/agent/special/retriever_agent.py +32 -198
- langroid/agent/special/sql/__init__.py +11 -0
- langroid/agent/special/sql/sql_chat_agent.py +47 -23
- langroid/agent/special/sql/utils/__init__.py +22 -0
- langroid/agent/special/sql/utils/description_extractors.py +95 -46
- langroid/agent/special/sql/utils/populate_metadata.py +28 -21
- langroid/agent/special/table_chat_agent.py +43 -9
- langroid/agent/task.py +475 -122
- langroid/agent/tool_message.py +75 -13
- langroid/agent/tools/__init__.py +13 -0
- langroid/agent/tools/duckduckgo_search_tool.py +66 -0
- langroid/agent/tools/google_search_tool.py +11 -0
- langroid/agent/tools/metaphor_search_tool.py +67 -0
- langroid/agent/tools/recipient_tool.py +16 -29
- langroid/agent/tools/run_python_code.py +60 -0
- langroid/agent/tools/sciphi_search_rag_tool.py +79 -0
- langroid/agent/tools/segment_extract_tool.py +36 -0
- langroid/cachedb/__init__.py +9 -0
- langroid/cachedb/base.py +22 -2
- langroid/cachedb/momento_cachedb.py +26 -2
- langroid/cachedb/redis_cachedb.py +78 -11
- langroid/embedding_models/__init__.py +34 -0
- langroid/embedding_models/base.py +21 -2
- langroid/embedding_models/models.py +120 -18
- langroid/embedding_models/protoc/embeddings.proto +19 -0
- langroid/embedding_models/protoc/embeddings_pb2.py +33 -0
- langroid/embedding_models/protoc/embeddings_pb2.pyi +50 -0
- langroid/embedding_models/protoc/embeddings_pb2_grpc.py +79 -0
- langroid/embedding_models/remote_embeds.py +153 -0
- langroid/language_models/__init__.py +45 -0
- langroid/language_models/azure_openai.py +80 -27
- langroid/language_models/base.py +117 -12
- langroid/language_models/config.py +5 -0
- langroid/language_models/openai_assistants.py +3 -0
- langroid/language_models/openai_gpt.py +558 -174
- langroid/language_models/prompt_formatter/__init__.py +15 -0
- langroid/language_models/prompt_formatter/base.py +4 -6
- langroid/language_models/prompt_formatter/hf_formatter.py +135 -0
- langroid/language_models/utils.py +18 -21
- langroid/mytypes.py +25 -8
- langroid/parsing/__init__.py +46 -0
- langroid/parsing/document_parser.py +260 -63
- langroid/parsing/image_text.py +32 -0
- langroid/parsing/parse_json.py +143 -0
- langroid/parsing/parser.py +122 -59
- langroid/parsing/repo_loader.py +114 -52
- langroid/parsing/search.py +68 -63
- langroid/parsing/spider.py +3 -2
- langroid/parsing/table_loader.py +44 -0
- langroid/parsing/url_loader.py +59 -11
- langroid/parsing/urls.py +85 -37
- langroid/parsing/utils.py +298 -4
- langroid/parsing/web_search.py +73 -0
- langroid/prompts/__init__.py +11 -0
- langroid/prompts/chat-gpt4-system-prompt.md +68 -0
- langroid/prompts/prompts_config.py +1 -1
- langroid/utils/__init__.py +17 -0
- langroid/utils/algorithms/__init__.py +3 -0
- langroid/utils/algorithms/graph.py +103 -0
- langroid/utils/configuration.py +36 -5
- langroid/utils/constants.py +4 -0
- langroid/utils/globals.py +2 -2
- langroid/utils/logging.py +2 -5
- langroid/utils/output/__init__.py +21 -0
- langroid/utils/output/printing.py +47 -1
- langroid/utils/output/status.py +33 -0
- langroid/utils/pandas_utils.py +30 -0
- langroid/utils/pydantic_utils.py +616 -2
- langroid/utils/system.py +98 -0
- langroid/vector_store/__init__.py +40 -0
- langroid/vector_store/base.py +203 -6
- langroid/vector_store/chromadb.py +59 -32
- langroid/vector_store/lancedb.py +463 -0
- langroid/vector_store/meilisearch.py +10 -7
- langroid/vector_store/momento.py +262 -0
- langroid/vector_store/qdrantdb.py +104 -22
- {langroid-0.1.85.dist-info → langroid-0.1.219.dist-info}/METADATA +329 -149
- langroid-0.1.219.dist-info/RECORD +127 -0
- {langroid-0.1.85.dist-info → langroid-0.1.219.dist-info}/WHEEL +1 -1
- langroid/agent/special/recipient_validator_agent.py +0 -157
- langroid/parsing/json.py +0 -64
- langroid/utils/web/selenium_login.py +0 -36
- langroid-0.1.85.dist-info/RECORD +0 -94
- /langroid/{scripts → agent/callbacks}/__init__.py +0 -0
- {langroid-0.1.85.dist-info → langroid-0.1.219.dist-info}/LICENSE +0 -0
langroid/agent/chat_document.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import json
|
2
|
-
from typing import List, Optional,
|
2
|
+
from typing import List, Optional, Union
|
3
3
|
|
4
4
|
from pydantic import BaseModel, Extra
|
5
5
|
|
6
|
+
from langroid.agent.tool_message import ToolMessage
|
6
7
|
from langroid.language_models.base import (
|
7
8
|
LLMFunctionCall,
|
8
9
|
LLMMessage,
|
@@ -12,7 +13,7 @@ from langroid.language_models.base import (
|
|
12
13
|
)
|
13
14
|
from langroid.mytypes import DocMetaData, Document, Entity
|
14
15
|
from langroid.parsing.agent_chats import parse_message
|
15
|
-
from langroid.parsing.
|
16
|
+
from langroid.parsing.parse_json import extract_top_level_json, top_level_json_field
|
16
17
|
from langroid.utils.output.printing import shorten_text
|
17
18
|
|
18
19
|
|
@@ -25,6 +26,7 @@ class ChatDocAttachment(BaseModel):
|
|
25
26
|
class ChatDocMetaData(DocMetaData):
|
26
27
|
parent: Optional["ChatDocument"] = None
|
27
28
|
sender: Entity
|
29
|
+
tool_ids: List[str] = [] # stack of tool_ids; used by OpenAIAssistant
|
28
30
|
# when result returns to parent, pretend message is from this entity
|
29
31
|
parent_responder: None | Entity = None
|
30
32
|
block: None | Entity = None
|
@@ -52,6 +54,7 @@ class ChatDocLoggerFields(BaseModel):
|
|
52
54
|
|
53
55
|
class ChatDocument(Document):
|
54
56
|
function_call: Optional[LLMFunctionCall] = None
|
57
|
+
tool_messages: List[ToolMessage] = []
|
55
58
|
metadata: ChatDocMetaData
|
56
59
|
attachment: None | ChatDocAttachment = None
|
57
60
|
|
@@ -81,7 +84,7 @@ class ChatDocument(Document):
|
|
81
84
|
json_data = json.loads(j)
|
82
85
|
tool = json_data.get("request")
|
83
86
|
if tool is not None:
|
84
|
-
tools.append(tool)
|
87
|
+
tools.append(str(tool))
|
85
88
|
return tools
|
86
89
|
|
87
90
|
def log_fields(self) -> ChatDocLoggerFields:
|
@@ -102,6 +105,8 @@ class ChatDocument(Document):
|
|
102
105
|
content = self.content
|
103
106
|
sender_entity = self.metadata.sender
|
104
107
|
sender_name = self.metadata.sender_name
|
108
|
+
if tool_type == "FUNC":
|
109
|
+
content += str(self.function_call)
|
105
110
|
return ChatDocLoggerFields(
|
106
111
|
sender_entity=sender_entity,
|
107
112
|
sender_name=sender_name,
|
@@ -118,12 +123,30 @@ class ChatDocument(Document):
|
|
118
123
|
field_values = fields.dict().values()
|
119
124
|
return "\t".join(str(v) for v in field_values)
|
120
125
|
|
126
|
+
def pop_tool_ids(self) -> None:
|
127
|
+
"""
|
128
|
+
Pop the last tool_id from the stack of tool_ids.
|
129
|
+
"""
|
130
|
+
if len(self.metadata.tool_ids) > 0:
|
131
|
+
self.metadata.tool_ids.pop()
|
132
|
+
|
121
133
|
@staticmethod
|
122
134
|
def from_LLMResponse(
|
123
135
|
response: LLMResponse,
|
124
136
|
displayed: bool = False,
|
125
137
|
) -> "ChatDocument":
|
138
|
+
"""
|
139
|
+
Convert LLMResponse to ChatDocument.
|
140
|
+
Args:
|
141
|
+
response (LLMResponse): LLMResponse to convert.
|
142
|
+
displayed (bool): Whether this response was displayed to the user.
|
143
|
+
Returns:
|
144
|
+
ChatDocument: ChatDocument representation of this LLMResponse.
|
145
|
+
"""
|
126
146
|
recipient, message = response.get_recipient_and_message()
|
147
|
+
message = message.strip()
|
148
|
+
if message in ["''", '""']:
|
149
|
+
message = ""
|
127
150
|
return ChatDocument(
|
128
151
|
content=message,
|
129
152
|
function_call=response.function_call,
|
@@ -155,7 +178,7 @@ class ChatDocument(Document):
|
|
155
178
|
)
|
156
179
|
|
157
180
|
@staticmethod
|
158
|
-
def to_LLMMessage(message: str
|
181
|
+
def to_LLMMessage(message: Union[str, "ChatDocument"]) -> LLMMessage:
|
159
182
|
"""
|
160
183
|
Convert to LLMMessage for use with LLM.
|
161
184
|
|
@@ -168,10 +191,23 @@ class ChatDocument(Document):
|
|
168
191
|
sender_name = None
|
169
192
|
sender_role = Role.USER
|
170
193
|
fun_call = None
|
194
|
+
tool_id = ""
|
171
195
|
if isinstance(message, ChatDocument):
|
172
196
|
content = message.content
|
173
197
|
fun_call = message.function_call
|
198
|
+
if message.metadata.sender == Entity.USER and fun_call is not None:
|
199
|
+
# This may happen when a (parent agent's) LLM generates a
|
200
|
+
# a Function-call, and it ends up being sent to the current task's
|
201
|
+
# LLM (possibly because the function-call is mis-named or has other
|
202
|
+
# issues and couldn't be handled by handler methods).
|
203
|
+
# But a function-call can only be generated by an entity with
|
204
|
+
# Role.ASSISTANT, so we instead put the content of the function-call
|
205
|
+
# in the content of the message.
|
206
|
+
content += " " + str(fun_call)
|
207
|
+
fun_call = None
|
174
208
|
sender_name = message.metadata.sender_name
|
209
|
+
tool_ids = message.metadata.tool_ids
|
210
|
+
tool_id = tool_ids[-1] if len(tool_ids) > 0 else ""
|
175
211
|
if message.metadata.sender == Entity.SYSTEM:
|
176
212
|
sender_role = Role.SYSTEM
|
177
213
|
if (
|
@@ -188,6 +224,7 @@ class ChatDocument(Document):
|
|
188
224
|
|
189
225
|
return LLMMessage(
|
190
226
|
role=sender_role,
|
227
|
+
tool_id=tool_id,
|
191
228
|
content=content,
|
192
229
|
function_call=fun_call,
|
193
230
|
name=sender_name,
|