langroid 0.20.1__py3-none-any.whl → 0.21.0__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/arangodb/arangodb_agent.py +33 -1
- langroid/agent/special/arangodb/system_messages.py +6 -3
- langroid/language_models/__init__.py +2 -0
- langroid/language_models/openai_gpt.py +24 -6
- {langroid-0.20.1.dist-info → langroid-0.21.0.dist-info}/METADATA +4 -1
- {langroid-0.20.1.dist-info → langroid-0.21.0.dist-info}/RECORD +9 -9
- pyproject.toml +1 -1
- {langroid-0.20.1.dist-info → langroid-0.21.0.dist-info}/LICENSE +0 -0
- {langroid-0.20.1.dist-info → langroid-0.21.0.dist-info}/WHEEL +0 -0
@@ -118,6 +118,7 @@ class ArangoChatAgent(ChatAgent):
|
|
118
118
|
def init_state(self) -> None:
|
119
119
|
super().init_state()
|
120
120
|
self.current_retrieval_aql_query: str = ""
|
121
|
+
self.current_schema_params: ArangoSchemaTool = ArangoSchemaTool()
|
121
122
|
self.num_tries = 0 # how many attempts to answer user question
|
122
123
|
|
123
124
|
def user_response(
|
@@ -125,6 +126,8 @@ class ArangoChatAgent(ChatAgent):
|
|
125
126
|
msg: Optional[str | ChatDocument] = None,
|
126
127
|
) -> Optional[ChatDocument]:
|
127
128
|
response = super().user_response(msg)
|
129
|
+
if response is None:
|
130
|
+
return None
|
128
131
|
response_str = response.content if response is not None else ""
|
129
132
|
if response_str != "":
|
130
133
|
self.num_tries = 0 # reset number of tries if user responds
|
@@ -165,7 +168,20 @@ class ArangoChatAgent(ChatAgent):
|
|
165
168
|
"""
|
166
169
|
)
|
167
170
|
|
168
|
-
|
171
|
+
response = super().llm_response(message)
|
172
|
+
if (
|
173
|
+
response is not None
|
174
|
+
and self.config.chat_mode
|
175
|
+
and self.config.addressing_prefix in response.content
|
176
|
+
and self.has_tool_message_attempt(response)
|
177
|
+
):
|
178
|
+
# response contains both a user-addressing and a tool, which
|
179
|
+
# is not allowed, so remove the user-addressing prefix
|
180
|
+
response.content = response.content.replace(
|
181
|
+
self.config.addressing_prefix, ""
|
182
|
+
)
|
183
|
+
|
184
|
+
return response
|
169
185
|
|
170
186
|
def _validate_config(self) -> None:
|
171
187
|
assert isinstance(self.config, ArangoChatAgentConfig)
|
@@ -363,6 +379,11 @@ class ArangoChatAgent(ChatAgent):
|
|
363
379
|
"""
|
364
380
|
self.num_tries += 1
|
365
381
|
query = msg.aql_query
|
382
|
+
if query == self.current_retrieval_aql_query:
|
383
|
+
return """
|
384
|
+
You have already tried this query, so you will get the same results again!
|
385
|
+
If you need to retry, please MODIFY the query to get different results.
|
386
|
+
"""
|
366
387
|
self.current_retrieval_aql_query = query
|
367
388
|
logger.info(f"Executing AQL query: {query}")
|
368
389
|
response = self.read_query(query)
|
@@ -399,6 +420,17 @@ class ArangoChatAgent(ChatAgent):
|
|
399
420
|
else show all properties and example-docs.
|
400
421
|
"""
|
401
422
|
|
423
|
+
if (
|
424
|
+
msg is not None
|
425
|
+
and msg.collections == self.current_schema_params.collections
|
426
|
+
and msg.properties == self.current_schema_params.properties
|
427
|
+
):
|
428
|
+
return """
|
429
|
+
You have already tried this schema TOOL, so you will get the same results
|
430
|
+
again! Please MODIFY the tool params `collections` or `properties` to get
|
431
|
+
different results.
|
432
|
+
"""
|
433
|
+
|
402
434
|
if msg is not None:
|
403
435
|
collections = msg.collections
|
404
436
|
properties = msg.properties
|
@@ -144,14 +144,17 @@ THEN make ANOTHER query, and so on, until you have the answer.
|
|
144
144
|
RETRY-SUGGESTIONS:
|
145
145
|
If you receive a null or other unexpected result,
|
146
146
|
(a) make sure you use the available TOOLs correctly,
|
147
|
-
(b)
|
148
|
-
|
147
|
+
(b) learn more about the schema using EITHER:
|
148
|
+
- `{arango_schema_tool_name}` tool/function-call to find properties of specific
|
149
|
+
collections or other parts of the schema, OR
|
150
|
+
- `{aql_retrieval_tool_name}` tool/function-call to use AQL queries to
|
151
|
+
find specific parts of the schema.
|
149
152
|
(c) Collection names are CASE-SENSITIVE -- make sure you adhere to the exact
|
150
153
|
collection name you found in the schema.
|
151
154
|
(d) see if you have made an assumption in your AQL query, and try another way,
|
152
155
|
or use `{aql_retrieval_tool_name}` to explore the database contents before
|
153
156
|
submitting your final query.
|
154
|
-
(
|
157
|
+
(e) Try APPROXIMATE or PARTIAL MATCHES to strings in the user's query,
|
155
158
|
e.g. user may ask about "Godfather" instead of "The Godfather",
|
156
159
|
or try using CASE-INSENSITIVE MATCHES.
|
157
160
|
|
@@ -17,6 +17,7 @@ from .base import (
|
|
17
17
|
from .openai_gpt import (
|
18
18
|
OpenAIChatModel,
|
19
19
|
AnthropicModel,
|
20
|
+
GeminiModel,
|
20
21
|
OpenAICompletionModel,
|
21
22
|
OpenAIGPTConfig,
|
22
23
|
OpenAIGPT,
|
@@ -41,6 +42,7 @@ __all__ = [
|
|
41
42
|
"LLMResponse",
|
42
43
|
"OpenAIChatModel",
|
43
44
|
"AnthropicModel",
|
45
|
+
"GeminiModel",
|
44
46
|
"OpenAICompletionModel",
|
45
47
|
"OpenAIGPTConfig",
|
46
48
|
"OpenAIGPT",
|
@@ -66,6 +66,7 @@ if "OLLAMA_HOST" in os.environ:
|
|
66
66
|
else:
|
67
67
|
OLLAMA_BASE_URL = "http://localhost:11434/v1"
|
68
68
|
|
69
|
+
GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/"
|
69
70
|
OLLAMA_API_KEY = "ollama"
|
70
71
|
DUMMY_API_KEY = "xxx"
|
71
72
|
|
@@ -92,6 +93,14 @@ class OpenAIChatModel(str, Enum):
|
|
92
93
|
O1_MINI = "o1-mini"
|
93
94
|
|
94
95
|
|
96
|
+
class GeminiModel(str, Enum):
|
97
|
+
"""Enum for Gemini models"""
|
98
|
+
|
99
|
+
GEMINI_1_5_FLASH = "gemini-1.5-flash"
|
100
|
+
GEMINI_1_5_FLASH_8B = "gemini-1.5-flash-8b"
|
101
|
+
GEMINI_1_5_PRO = "gemini-1.5-pro"
|
102
|
+
|
103
|
+
|
95
104
|
class OpenAICompletionModel(str, Enum):
|
96
105
|
"""Enum for OpenAI Completion models"""
|
97
106
|
|
@@ -503,6 +512,7 @@ class OpenAIGPT(LanguageModel):
|
|
503
512
|
|
504
513
|
self.is_groq = self.config.chat_model.startswith("groq/")
|
505
514
|
self.is_cerebras = self.config.chat_model.startswith("cerebras/")
|
515
|
+
self.is_gemini = self.config.chat_model.startswith("gemini/")
|
506
516
|
|
507
517
|
if self.is_groq:
|
508
518
|
self.config.chat_model = self.config.chat_model.replace("groq/", "")
|
@@ -524,6 +534,11 @@ class OpenAIGPT(LanguageModel):
|
|
524
534
|
api_key=self.api_key,
|
525
535
|
)
|
526
536
|
else:
|
537
|
+
if self.is_gemini:
|
538
|
+
self.config.chat_model = self.config.chat_model.replace("gemini/", "")
|
539
|
+
self.api_key = os.getenv("GEMINI_API_KEY", DUMMY_API_KEY)
|
540
|
+
self.api_base = GEMINI_BASE_URL
|
541
|
+
|
527
542
|
self.client = OpenAI(
|
528
543
|
api_key=self.api_key,
|
529
544
|
base_url=self.api_base,
|
@@ -623,7 +638,13 @@ class OpenAIGPT(LanguageModel):
|
|
623
638
|
Currently main troublemaker is o1* series.
|
624
639
|
"""
|
625
640
|
match self.config.chat_model:
|
626
|
-
case
|
641
|
+
case (
|
642
|
+
OpenAIChatModel.O1_MINI
|
643
|
+
| OpenAIChatModel.O1_PREVIEW
|
644
|
+
| GeminiModel.GEMINI_1_5_FLASH
|
645
|
+
| GeminiModel.GEMINI_1_5_FLASH_8B
|
646
|
+
| GeminiModel.GEMINI_1_5_PRO
|
647
|
+
):
|
627
648
|
return {"max_tokens": "max_completion_tokens"}
|
628
649
|
case _:
|
629
650
|
return {}
|
@@ -1229,13 +1250,10 @@ class OpenAIGPT(LanguageModel):
|
|
1229
1250
|
cost = 0.0
|
1230
1251
|
prompt_tokens = 0
|
1231
1252
|
completion_tokens = 0
|
1232
|
-
if not cached and not self.get_stream():
|
1253
|
+
if not cached and not self.get_stream() and response["usage"] is not None:
|
1233
1254
|
prompt_tokens = response["usage"]["prompt_tokens"]
|
1234
1255
|
completion_tokens = response["usage"]["completion_tokens"]
|
1235
|
-
cost = self._cost_chat_model(
|
1236
|
-
response["usage"]["prompt_tokens"],
|
1237
|
-
response["usage"]["completion_tokens"],
|
1238
|
-
)
|
1256
|
+
cost = self._cost_chat_model(prompt_tokens, completion_tokens)
|
1239
1257
|
|
1240
1258
|
return LLMTokenUsage(
|
1241
1259
|
prompt_tokens=prompt_tokens, completion_tokens=completion_tokens, cost=cost
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: langroid
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.21.0
|
4
4
|
Summary: Harness LLMs with Multi-Agent Programming
|
5
5
|
License: MIT
|
6
6
|
Author: Prasad Chalasani
|
@@ -248,6 +248,9 @@ teacher_task.run()
|
|
248
248
|
<details>
|
249
249
|
<summary> <b>Click to expand</b></summary>
|
250
250
|
|
251
|
+
- **Nov 2024:**
|
252
|
+
- **[0.20.0](https://github.com/langroid/langroid/releases/tag/0.20.0)** Support for
|
253
|
+
ArangoDB Knowledge Graphs.
|
251
254
|
- **Oct 2024:**
|
252
255
|
- **[0.18.0]** [LLMConfig.async_stream_quiet](https://langroid.github.io/langroid/notes/async-streaming/) flag to
|
253
256
|
turn off LLM output in async + stream mode.
|
@@ -11,8 +11,8 @@ langroid/agent/junk,sha256=LxfuuW7Cijsg0szAzT81OjWWv1PMNI-6w_-DspVIO2s,339
|
|
11
11
|
langroid/agent/openai_assistant.py,sha256=2rjCZw45ysNBEGNzQM4uf0bTC4KkatGYAWcVcW4xcek,34337
|
12
12
|
langroid/agent/special/__init__.py,sha256=gik_Xtm_zV7U9s30Mn8UX3Gyuy4jTjQe9zjiE3HWmEo,1273
|
13
13
|
langroid/agent/special/arangodb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
langroid/agent/special/arangodb/arangodb_agent.py,sha256=
|
15
|
-
langroid/agent/special/arangodb/system_messages.py,sha256=
|
14
|
+
langroid/agent/special/arangodb/arangodb_agent.py,sha256=CXD1Z4yXnWwre4ybg7BMhVFTgQq0zVXzobutyxIYCP4,26862
|
15
|
+
langroid/agent/special/arangodb/system_messages.py,sha256=udwfLleTdyz_DuxHuoiv2wHEZoAPBPbwdF_ivjIfP5c,6867
|
16
16
|
langroid/agent/special/arangodb/tools.py,sha256=WasFERC1cToLOWi1cWqUs-TujU0A68gZWbhbP128obo,3499
|
17
17
|
langroid/agent/special/arangodb/utils.py,sha256=LIevtkayIdVVXyj3jlbKH2WgdZTtH5-JLgbXOHC7uxs,1420
|
18
18
|
langroid/agent/special/doc_chat_agent.py,sha256=xIqBOyLax_jMU0UevxqXf_aQUrRkW6MQUKpKnKvaqkQ,59281
|
@@ -70,12 +70,12 @@ langroid/embedding_models/remote_embeds.py,sha256=6_kjXByVbqhY9cGwl9R83ZcYC2km-n
|
|
70
70
|
langroid/exceptions.py,sha256=G60UVDChkUlBDVWHFr_43zUUszZHSejoU00tX_dfD68,2322
|
71
71
|
langroid/language_models/.chainlit/config.toml,sha256=1t5lHORGzc2E6dkaO9P15jYHu2w-4Kl9pYjpDPc84vs,3716
|
72
72
|
langroid/language_models/.chainlit/translations/en-US.json,sha256=DAFz2HjOFFfboCStrUfKFg2BpplJPK_OOtixwF_GivY,9931
|
73
|
-
langroid/language_models/__init__.py,sha256=
|
73
|
+
langroid/language_models/__init__.py,sha256=8o8D8Lxaq961_oxVpB_bC2iEJ1GXJqYXMlwUcn6OJb8,976
|
74
74
|
langroid/language_models/azure_openai.py,sha256=G4le3j4YLHV7IwgB2C37hO3MKijZ1KjynbYlEvpIF7Y,6214
|
75
75
|
langroid/language_models/base.py,sha256=xMFg8syIHiA7ABRNWPXeFM1vGeY_1EN84ki8C3dycfw,22722
|
76
76
|
langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
|
77
77
|
langroid/language_models/mock_lm.py,sha256=HuiAvjHiCfffYF5xjFJUq945HVTW0QPbeUUctOnNCzQ,3868
|
78
|
-
langroid/language_models/openai_gpt.py,sha256
|
78
|
+
langroid/language_models/openai_gpt.py,sha256=CVRwYvIT8lt02GqI0G5_sTQXLcQbiwwNXpU8_qsw6q8,69584
|
79
79
|
langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
|
80
80
|
langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
|
81
81
|
langroid/language_models/prompt_formatter/hf_formatter.py,sha256=PVJppmjRvD-2DF-XNC6mE05vTZ9wbu37SmXwZBQhad0,5055
|
@@ -142,8 +142,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
|
|
142
142
|
langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
|
143
143
|
langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
|
144
144
|
langroid/vector_store/qdrantdb.py,sha256=v88lqFkepADvlN6lByUj9I4NEKa9X9lWH16uTPPbYrE,17457
|
145
|
-
pyproject.toml,sha256=
|
146
|
-
langroid-0.
|
147
|
-
langroid-0.
|
148
|
-
langroid-0.
|
149
|
-
langroid-0.
|
145
|
+
pyproject.toml,sha256=yiLcLTge7QxJ1EWYE05yUHpBADouFh36WO3SlRzJKL0,7488
|
146
|
+
langroid-0.21.0.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
147
|
+
langroid-0.21.0.dist-info/METADATA,sha256=TSl0anzCbcnchyI2yTczV4fK2KBkfJnUu2Jl8oqGGLA,56893
|
148
|
+
langroid-0.21.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
149
|
+
langroid-0.21.0.dist-info/RECORD,,
|
pyproject.toml
CHANGED
File without changes
|
File without changes
|