langroid 0.5.1__py3-none-any.whl → 0.6.1__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/special/lance_rag_new/critic_agent.py +1 -1
- langroid/agent/special/neo4j/neo4j_chat_agent.py +17 -39
- langroid/agent/special/neo4j/utils/system_message.py +10 -0
- langroid/language_models/openai_gpt.py +4 -0
- {langroid-0.5.1.dist-info → langroid-0.6.1.dist-info}/METADATA +1 -1
- {langroid-0.5.1.dist-info → langroid-0.6.1.dist-info}/RECORD +9 -9
- pyproject.toml +1 -1
- {langroid-0.5.1.dist-info → langroid-0.6.1.dist-info}/LICENSE +0 -0
- {langroid-0.5.1.dist-info → langroid-0.6.1.dist-info}/WHEEL +0 -0
@@ -64,7 +64,7 @@ class QueryPlanCriticConfig(LanceQueryPlanAgentConfig):
|
|
64
64
|
- DATAFRAME CALCULATION, which must be a SINGLE LINE calculation (or empty),
|
65
65
|
[NOTE ==> This calculation is applied AFTER the FILTER and REPHRASED QUERY.],
|
66
66
|
- ANSWER received from an assistant that used this QUERY PLAN.
|
67
|
-
NOTE --
|
67
|
+
NOTE --the ANSWER will usually NOT contain any references to FILTERING conditions,
|
68
68
|
and this is ALLOWED, since the ANSWER is based on documents AFTER FILTERING.
|
69
69
|
|
70
70
|
In addition to the above SCHEMA fields there is a `content` field which:
|
@@ -11,10 +11,10 @@ from langroid.pydantic_v1 import BaseModel, BaseSettings
|
|
11
11
|
if TYPE_CHECKING:
|
12
12
|
import neo4j
|
13
13
|
|
14
|
-
|
15
14
|
from langroid.agent.chat_agent import ChatAgent, ChatAgentConfig
|
16
|
-
from langroid.agent.chat_document import
|
15
|
+
from langroid.agent.chat_document import ChatDocument
|
17
16
|
from langroid.agent.special.neo4j.utils.system_message import (
|
17
|
+
ADDRESSING_INSTRUCTION,
|
18
18
|
DEFAULT_NEO4J_CHAT_SYSTEM_MESSAGE,
|
19
19
|
DEFAULT_SYS_MSG,
|
20
20
|
SCHEMA_TOOLS_SYS_MSG,
|
@@ -76,6 +76,7 @@ class Neo4jChatAgentConfig(ChatAgentConfig):
|
|
76
76
|
use_schema_tools: bool = True
|
77
77
|
use_functions_api: bool = True
|
78
78
|
use_tools: bool = False
|
79
|
+
addressing_prefix: str = ""
|
79
80
|
|
80
81
|
|
81
82
|
class Neo4jChatAgent(ChatAgent):
|
@@ -85,12 +86,21 @@ class Neo4jChatAgent(ChatAgent):
|
|
85
86
|
Raises:
|
86
87
|
ValueError: If database information is not provided in the config.
|
87
88
|
"""
|
88
|
-
self.config = config
|
89
|
+
self.config: Neo4jChatAgentConfig = config
|
89
90
|
self._validate_config()
|
90
91
|
self._import_neo4j()
|
91
92
|
self._initialize_connection()
|
92
93
|
self._init_tool_messages()
|
93
94
|
|
95
|
+
def handle_message_fallback(
|
96
|
+
self, msg: str | ChatDocument
|
97
|
+
) -> str | ChatDocument | None:
|
98
|
+
"""When LLM sends a no-tool msg, assume user is the intended recipient."""
|
99
|
+
if isinstance(msg, ChatDocument) and msg.metadata.sender == Entity.LLM:
|
100
|
+
msg.metadata.recipient = Entity.USER
|
101
|
+
return msg
|
102
|
+
return None
|
103
|
+
|
94
104
|
def _validate_config(self) -> None:
|
95
105
|
"""Validate the configuration to ensure all necessary fields are present."""
|
96
106
|
assert isinstance(self.config, Neo4jChatAgentConfig)
|
@@ -318,6 +328,10 @@ class Neo4jChatAgent(ChatAgent):
|
|
318
328
|
"""Initialize message tools used for chatting."""
|
319
329
|
message = self._format_message()
|
320
330
|
self.config.system_message = self.config.system_message.format(mode=message)
|
331
|
+
if self.config.addressing_prefix != "":
|
332
|
+
self.config.system_message += ADDRESSING_INSTRUCTION.format(
|
333
|
+
prefix=self.config.addressing_prefix
|
334
|
+
)
|
321
335
|
super().__init__(self.config)
|
322
336
|
self.enable_message(CypherRetrievalTool)
|
323
337
|
self.enable_message(CypherCreationTool)
|
@@ -332,39 +346,3 @@ class Neo4jChatAgent(ChatAgent):
|
|
332
346
|
if self.config.use_schema_tools
|
333
347
|
else DEFAULT_SYS_MSG.format(schema=self.get_schema(None))
|
334
348
|
)
|
335
|
-
|
336
|
-
def agent_response(
|
337
|
-
self,
|
338
|
-
msg: Optional[str | ChatDocument] = None,
|
339
|
-
) -> Optional[ChatDocument]:
|
340
|
-
if msg is None:
|
341
|
-
return None
|
342
|
-
|
343
|
-
results = self.handle_message(msg)
|
344
|
-
if results is None:
|
345
|
-
return None
|
346
|
-
|
347
|
-
output = results
|
348
|
-
if NEO4J_ERROR_MSG in output:
|
349
|
-
output = "There was an error in the Cypher Query. Press enter to retry."
|
350
|
-
|
351
|
-
console.print(f"[red]{self.indent}", end="")
|
352
|
-
print(f"[red]Agent: {output}")
|
353
|
-
sender_name = self.config.name
|
354
|
-
if isinstance(msg, ChatDocument) and msg.function_call is not None:
|
355
|
-
sender_name = msg.function_call.name
|
356
|
-
|
357
|
-
content = results.content if isinstance(results, ChatDocument) else results
|
358
|
-
recipient = (
|
359
|
-
results.metadata.recipient if isinstance(results, ChatDocument) else ""
|
360
|
-
)
|
361
|
-
|
362
|
-
return ChatDocument(
|
363
|
-
content=content,
|
364
|
-
metadata=ChatDocMetaData(
|
365
|
-
# source=Entity.AGENT,
|
366
|
-
sender=Entity.AGENT,
|
367
|
-
sender_name=sender_name,
|
368
|
-
recipient=recipient,
|
369
|
-
),
|
370
|
-
)
|
@@ -44,3 +44,13 @@ Also if you receive a null or other unexpected result,
|
|
44
44
|
Start by asking what I would like to know about the data.
|
45
45
|
|
46
46
|
"""
|
47
|
+
|
48
|
+
ADDRESSING_INSTRUCTION = """
|
49
|
+
IMPORTANT - Whenever you are NOT writing a CYPHER query, make sure you address the
|
50
|
+
user using {prefix}User. You MUST use the EXACT syntax {prefix} !!!
|
51
|
+
|
52
|
+
In other words, you ALWAYS write EITHER:
|
53
|
+
- a CYPHER query using one of the tools,
|
54
|
+
- OR address the user using {prefix}User.
|
55
|
+
|
56
|
+
"""
|
@@ -82,6 +82,7 @@ class OpenAIChatModel(str, Enum):
|
|
82
82
|
GPT4_32K = "gpt-4-32k"
|
83
83
|
GPT4_TURBO = "gpt-4-turbo"
|
84
84
|
GPT4o = "gpt-4o"
|
85
|
+
GPT4o_MINI = "gpt-4o-mini"
|
85
86
|
|
86
87
|
|
87
88
|
class OpenAICompletionModel(str, Enum):
|
@@ -98,6 +99,7 @@ _context_length: Dict[str, int] = {
|
|
98
99
|
OpenAIChatModel.GPT4_32K: 32_768,
|
99
100
|
OpenAIChatModel.GPT4_TURBO: 128_000,
|
100
101
|
OpenAIChatModel.GPT4o: 128_000,
|
102
|
+
OpenAIChatModel.GPT4o_MINI: 128_000,
|
101
103
|
OpenAICompletionModel.TEXT_DA_VINCI_003: 4096,
|
102
104
|
AnthropicModel.CLAUDE_3_5_SONNET: 200_000,
|
103
105
|
AnthropicModel.CLAUDE_3_OPUS: 200_000,
|
@@ -112,6 +114,7 @@ _cost_per_1k_tokens: Dict[str, Tuple[float, float]] = {
|
|
112
114
|
OpenAIChatModel.GPT4: (0.03, 0.06), # 8K context
|
113
115
|
OpenAIChatModel.GPT4_TURBO: (0.01, 0.03), # 128K context
|
114
116
|
OpenAIChatModel.GPT4o: (0.005, 0.015), # 128K context
|
117
|
+
OpenAIChatModel.GPT4o_MINI: (0.00015, 0.0006), # 128K context
|
115
118
|
AnthropicModel.CLAUDE_3_5_SONNET: (0.003, 0.015),
|
116
119
|
AnthropicModel.CLAUDE_3_OPUS: (0.015, 0.075),
|
117
120
|
AnthropicModel.CLAUDE_3_SONNET: (0.003, 0.015),
|
@@ -123,6 +126,7 @@ openAIChatModelPreferenceList = [
|
|
123
126
|
OpenAIChatModel.GPT4o,
|
124
127
|
OpenAIChatModel.GPT4_TURBO,
|
125
128
|
OpenAIChatModel.GPT4,
|
129
|
+
OpenAIChatModel.GPT4o_MINI,
|
126
130
|
OpenAIChatModel.GPT3_5_TURBO,
|
127
131
|
]
|
128
132
|
|
@@ -17,15 +17,15 @@ langroid/agent/special/lance_rag/critic_agent.py,sha256=S3NA3OAO7XaXjCrmwhKB7qCP
|
|
17
17
|
langroid/agent/special/lance_rag/lance_rag_task.py,sha256=l_HQgrYY-CX2FwIsS961aEF3bYog3GDYo98fj0C0mSk,2889
|
18
18
|
langroid/agent/special/lance_rag/query_planner_agent.py,sha256=QB8UYITUCkgSPturEwu_3i4kU8jXxW_jXNGSLlH5tMc,10109
|
19
19
|
langroid/agent/special/lance_rag_new/__init__.py,sha256=QTbs0IVE2ZgDg8JJy1zN97rUUg4uEPH7SLGctFNumk4,174
|
20
|
-
langroid/agent/special/lance_rag_new/critic_agent.py,sha256=
|
20
|
+
langroid/agent/special/lance_rag_new/critic_agent.py,sha256=9TV0_ILQ1jNeO9Pjeirz3VsUsCKeImyVHPu-fJub6cY,8340
|
21
21
|
langroid/agent/special/lance_rag_new/lance_rag_task.py,sha256=mKo4lCC1ff5Jt9BlxwclQ_y3omw2S_f0MVIJfNmXM6w,5267
|
22
22
|
langroid/agent/special/lance_rag_new/query_planner_agent.py,sha256=JqO_5fKW8HPn-zqKsZzX1sl05RgtcT63qpDMR9-q33A,10251
|
23
23
|
langroid/agent/special/lance_tools.py,sha256=BznV_r3LAFyybvBRa9KQ0oU7mPM3uQVfri7PFp7M_qc,1894
|
24
24
|
langroid/agent/special/neo4j/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
25
|
langroid/agent/special/neo4j/csv_kg_chat.py,sha256=dRsAgMBa1H_EMI2YYgJR2Xyv1D7e4o3G9M64mTewq_c,6409
|
26
|
-
langroid/agent/special/neo4j/neo4j_chat_agent.py,sha256=
|
26
|
+
langroid/agent/special/neo4j/neo4j_chat_agent.py,sha256=B5y4he__9QjNrjNyngv4rlfVx7QezQ4Turom-l_zjCg,12572
|
27
27
|
langroid/agent/special/neo4j/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
|
-
langroid/agent/special/neo4j/utils/system_message.py,sha256=
|
28
|
+
langroid/agent/special/neo4j/utils/system_message.py,sha256=OvYuBSlnLhav4HAiwcYiJJSrpbGxqOqs4RAvnlwAvRI,2557
|
29
29
|
langroid/agent/special/relevance_extractor_agent.py,sha256=zIx8GUdVo1aGW6ASla0NPQjYYIpmriK_TYMijqAx3F8,4796
|
30
30
|
langroid/agent/special/retriever_agent.py,sha256=lvMvf-u9rSosg4YASuFdUbGLgkzLPknXAbJZfZ1LZCc,1868
|
31
31
|
langroid/agent/special/sql/__init__.py,sha256=mWfmm1QpXCezpFOS2eI57M0L_Ok3q5_ukG8tXBnBrEA,319
|
@@ -72,7 +72,7 @@ langroid/language_models/azure_openai.py,sha256=G4le3j4YLHV7IwgB2C37hO3MKijZ1Kjy
|
|
72
72
|
langroid/language_models/base.py,sha256=nhY-AdSkfqaW4hzeIekxxZs29AWLd7X7GYhRygU9L74,17527
|
73
73
|
langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
|
74
74
|
langroid/language_models/mock_lm.py,sha256=qdgj-wtbQBXlibo_0rIRfCt0hGTPRoxy1C4VjN6quI4,2707
|
75
|
-
langroid/language_models/openai_gpt.py,sha256=
|
75
|
+
langroid/language_models/openai_gpt.py,sha256=BI5q9AVEJA-jA0G0Eg60T4NF1AdNLSd1-sOSHXnxaYU,52428
|
76
76
|
langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
|
77
77
|
langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
|
78
78
|
langroid/language_models/prompt_formatter/hf_formatter.py,sha256=TFL6ppmeQWnzr6CKQzRZFYY810zE1mr8DZnhw6i85ok,5217
|
@@ -134,8 +134,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
|
|
134
134
|
langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
|
135
135
|
langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
|
136
136
|
langroid/vector_store/qdrantdb.py,sha256=v88lqFkepADvlN6lByUj9I4NEKa9X9lWH16uTPPbYrE,17457
|
137
|
-
pyproject.toml,sha256=
|
138
|
-
langroid-0.
|
139
|
-
langroid-0.
|
140
|
-
langroid-0.
|
141
|
-
langroid-0.
|
137
|
+
pyproject.toml,sha256=b3vqi_BvwKi-CRtturkQMIR9BjcuLOxbmAAFEMhz9DI,7063
|
138
|
+
langroid-0.6.1.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
139
|
+
langroid-0.6.1.dist-info/METADATA,sha256=o5zXQBol5AfCAVK6sd1vNMwG3Qhrsie8QDo7-1C4yXY,54402
|
140
|
+
langroid-0.6.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
141
|
+
langroid-0.6.1.dist-info/RECORD,,
|
pyproject.toml
CHANGED
File without changes
|
File without changes
|