langroid 0.1.235__py3-none-any.whl → 0.1.237__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/openai_assistant.py +16 -13
- langroid/agent/task.py +3 -2
- langroid/embedding_models/protoc/__init__.py +0 -0
- langroid/language_models/openai_gpt.py +37 -12
- {langroid-0.1.235.dist-info → langroid-0.1.237.dist-info}/METADATA +18 -2
- {langroid-0.1.235.dist-info → langroid-0.1.237.dist-info}/RECORD +8 -7
- {langroid-0.1.235.dist-info → langroid-0.1.237.dist-info}/LICENSE +0 -0
- {langroid-0.1.235.dist-info → langroid-0.1.237.dist-info}/WHEEL +0 -0
@@ -7,6 +7,7 @@ import time
|
|
7
7
|
from enum import Enum
|
8
8
|
from typing import Any, Dict, List, Optional, Tuple, Type, cast, no_type_check
|
9
9
|
|
10
|
+
import openai
|
10
11
|
from openai.types.beta import Assistant, Thread
|
11
12
|
from openai.types.beta.assistant_update_params import (
|
12
13
|
ToolResources,
|
@@ -99,12 +100,14 @@ class OpenAIAssistant(ChatAgent):
|
|
99
100
|
super().__init__(config)
|
100
101
|
self.config: OpenAIAssistantConfig = config
|
101
102
|
self.llm: OpenAIGPT = OpenAIGPT(self.config.llm)
|
103
|
+
if not isinstance(self.llm.client, openai.OpenAI):
|
104
|
+
raise ValueError("Client must be OpenAI")
|
102
105
|
# handles for various entities and methods
|
103
|
-
self.client = self.llm.client
|
104
|
-
self.runs = self.
|
105
|
-
self.threads = self.
|
106
|
-
self.thread_messages = self.
|
107
|
-
self.assistants = self.
|
106
|
+
self.client: openai.OpenAI = self.llm.client
|
107
|
+
self.runs = self.client.beta.threads.runs
|
108
|
+
self.threads = self.client.beta.threads
|
109
|
+
self.thread_messages = self.client.beta.threads.messages
|
110
|
+
self.assistants = self.client.beta.assistants
|
108
111
|
# which tool_ids are awaiting output submissions
|
109
112
|
self.pending_tool_ids: List[str] = []
|
110
113
|
self.cached_tool_ids: List[str] = []
|
@@ -208,14 +211,14 @@ class OpenAIAssistant(ChatAgent):
|
|
208
211
|
|
209
212
|
def _cache_thread_key(self) -> str:
|
210
213
|
"""Key to use for caching or retrieving thread id"""
|
211
|
-
org = self.
|
214
|
+
org = self.client.organization or ""
|
212
215
|
uid = generate_user_id(org)
|
213
216
|
name = self.config.name
|
214
217
|
return "Thread:" + name + ":" + uid
|
215
218
|
|
216
219
|
def _cache_assistant_key(self) -> str:
|
217
220
|
"""Key to use for caching or retrieving assistant id"""
|
218
|
-
org = self.
|
221
|
+
org = self.client.organization or ""
|
219
222
|
uid = generate_user_id(org)
|
220
223
|
name = self.config.name
|
221
224
|
return "Assistant:" + name + ":" + uid
|
@@ -317,7 +320,7 @@ class OpenAIAssistant(ChatAgent):
|
|
317
320
|
cached = self._cache_thread_lookup()
|
318
321
|
if cached is not None:
|
319
322
|
if self.config.use_cached_thread:
|
320
|
-
self.thread = self.
|
323
|
+
self.thread = self.client.beta.threads.retrieve(thread_id=cached)
|
321
324
|
else:
|
322
325
|
logger.warning(
|
323
326
|
f"""
|
@@ -326,7 +329,7 @@ class OpenAIAssistant(ChatAgent):
|
|
326
329
|
"""
|
327
330
|
)
|
328
331
|
try:
|
329
|
-
self.
|
332
|
+
self.client.beta.threads.delete(thread_id=cached)
|
330
333
|
except Exception:
|
331
334
|
logger.warning(
|
332
335
|
f"""
|
@@ -337,7 +340,7 @@ class OpenAIAssistant(ChatAgent):
|
|
337
340
|
if self.thread is None:
|
338
341
|
if self.assistant is None:
|
339
342
|
raise ValueError("Assistant is None")
|
340
|
-
self.thread = self.
|
343
|
+
self.thread = self.client.beta.threads.create()
|
341
344
|
hash_key_str = (
|
342
345
|
(self.assistant.instructions or "")
|
343
346
|
+ str(self.config.use_tools)
|
@@ -371,7 +374,7 @@ class OpenAIAssistant(ChatAgent):
|
|
371
374
|
cached = self._cache_assistant_lookup()
|
372
375
|
if cached is not None:
|
373
376
|
if self.config.use_cached_assistant:
|
374
|
-
self.assistant = self.
|
377
|
+
self.assistant = self.client.beta.assistants.retrieve(
|
375
378
|
assistant_id=cached
|
376
379
|
)
|
377
380
|
else:
|
@@ -382,7 +385,7 @@ class OpenAIAssistant(ChatAgent):
|
|
382
385
|
"""
|
383
386
|
)
|
384
387
|
try:
|
385
|
-
self.
|
388
|
+
self.client.beta.assistants.delete(assistant_id=cached)
|
386
389
|
except Exception:
|
387
390
|
logger.warning(
|
388
391
|
f"""
|
@@ -391,7 +394,7 @@ class OpenAIAssistant(ChatAgent):
|
|
391
394
|
)
|
392
395
|
self.llm.cache.delete_keys([self._cache_assistant_key()])
|
393
396
|
if self.assistant is None:
|
394
|
-
self.assistant = self.
|
397
|
+
self.assistant = self.client.beta.assistants.create(
|
395
398
|
name=self.config.name,
|
396
399
|
instructions=self.config.system_message,
|
397
400
|
tools=[],
|
langroid/agent/task.py
CHANGED
@@ -84,6 +84,7 @@ class Task:
|
|
84
84
|
|
85
85
|
# class variable called `cache` that is a RedisCache object
|
86
86
|
cache: RedisCache = RedisCache(RedisCacheConfig(fake=False))
|
87
|
+
|
87
88
|
def __init__(
|
88
89
|
self,
|
89
90
|
agent: Optional[Agent] = None,
|
@@ -331,9 +332,9 @@ class Task:
|
|
331
332
|
self._cache_session_store("kill", "0")
|
332
333
|
|
333
334
|
@classmethod
|
334
|
-
def kill_session(cls, session_id=""):
|
335
|
+
def kill_session(cls, session_id: str = "") -> None:
|
335
336
|
"""
|
336
|
-
Kill the
|
337
|
+
Kill the session with the given session_id.
|
337
338
|
"""
|
338
339
|
session_id_kill_key = f"{session_id}:kill"
|
339
340
|
cls.cache.store(session_id_kill_key, "1")
|
File without changes
|
@@ -21,6 +21,7 @@ from typing import (
|
|
21
21
|
)
|
22
22
|
|
23
23
|
import openai
|
24
|
+
from groq import AsyncGroq, Groq
|
24
25
|
from httpx import Timeout
|
25
26
|
from openai import AsyncOpenAI, OpenAI
|
26
27
|
from pydantic import BaseModel
|
@@ -347,6 +348,9 @@ class OpenAIGPT(LanguageModel):
|
|
347
348
|
Class for OpenAI LLMs
|
348
349
|
"""
|
349
350
|
|
351
|
+
client: OpenAI | Groq
|
352
|
+
async_client: AsyncOpenAI | AsyncGroq
|
353
|
+
|
350
354
|
def __init__(self, config: OpenAIGPTConfig = OpenAIGPTConfig()):
|
351
355
|
"""
|
352
356
|
Args:
|
@@ -448,18 +452,31 @@ class OpenAIGPT(LanguageModel):
|
|
448
452
|
self.api_key = os.getenv("OPENAI_API_KEY", DUMMY_API_KEY)
|
449
453
|
else:
|
450
454
|
self.api_key = DUMMY_API_KEY
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
455
|
+
|
456
|
+
self.is_groq = self.config.chat_model.startswith("groq/")
|
457
|
+
|
458
|
+
if self.is_groq:
|
459
|
+
self.config.chat_model = self.config.chat_model.replace("groq/", "")
|
460
|
+
self.api_key = os.getenv("GROQ_API_KEY", DUMMY_API_KEY)
|
461
|
+
self.client = Groq(
|
462
|
+
api_key=self.api_key,
|
463
|
+
)
|
464
|
+
self.async_client = AsyncGroq(
|
465
|
+
api_key=self.api_key,
|
466
|
+
)
|
467
|
+
else:
|
468
|
+
self.client = OpenAI(
|
469
|
+
api_key=self.api_key,
|
470
|
+
base_url=self.api_base,
|
471
|
+
organization=self.config.organization,
|
472
|
+
timeout=Timeout(self.config.timeout),
|
473
|
+
)
|
474
|
+
self.async_client = AsyncOpenAI(
|
475
|
+
api_key=self.api_key,
|
476
|
+
organization=self.config.organization,
|
477
|
+
base_url=self.api_base,
|
478
|
+
timeout=Timeout(self.config.timeout),
|
479
|
+
)
|
463
480
|
|
464
481
|
self.cache: MomentoCache | RedisCache
|
465
482
|
if settings.cache_type == "momento":
|
@@ -855,6 +872,9 @@ class OpenAIGPT(LanguageModel):
|
|
855
872
|
if self.config.use_chat_for_completion:
|
856
873
|
return self.chat(messages=prompt, max_tokens=max_tokens)
|
857
874
|
|
875
|
+
if self.is_groq:
|
876
|
+
raise ValueError("Groq does not support pure completions")
|
877
|
+
|
858
878
|
if settings.debug:
|
859
879
|
print(f"[grey37]PROMPT: {escape(prompt)}[/grey37]")
|
860
880
|
|
@@ -869,6 +889,7 @@ class OpenAIGPT(LanguageModel):
|
|
869
889
|
else:
|
870
890
|
if self.config.litellm:
|
871
891
|
from litellm import completion as litellm_completion
|
892
|
+
assert isinstance(self.client, OpenAI)
|
872
893
|
completion_call = (
|
873
894
|
litellm_completion
|
874
895
|
if self.config.litellm
|
@@ -929,6 +950,9 @@ class OpenAIGPT(LanguageModel):
|
|
929
950
|
if self.config.use_chat_for_completion:
|
930
951
|
return await self.achat(messages=prompt, max_tokens=max_tokens)
|
931
952
|
|
953
|
+
if self.is_groq:
|
954
|
+
raise ValueError("Groq does not support pure completions")
|
955
|
+
|
932
956
|
if settings.debug:
|
933
957
|
print(f"[grey37]PROMPT: {escape(prompt)}[/grey37]")
|
934
958
|
|
@@ -948,6 +972,7 @@ class OpenAIGPT(LanguageModel):
|
|
948
972
|
from litellm import acompletion as litellm_acompletion
|
949
973
|
# TODO this may not work: text_completion is not async,
|
950
974
|
# and we didn't find an async version in litellm
|
975
|
+
assert isinstance(self.async_client, AsyncOpenAI)
|
951
976
|
acompletion_call = (
|
952
977
|
litellm_acompletion
|
953
978
|
if self.config.litellm
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: langroid
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.237
|
4
4
|
Summary: Harness LLMs with Multi-Agent Programming
|
5
5
|
License: MIT
|
6
6
|
Author: Prasad Chalasani
|
@@ -29,12 +29,13 @@ Requires-Dist: chainlit (>=1.0.400,<2.0.0) ; extra == "chainlit"
|
|
29
29
|
Requires-Dist: chromadb (>=0.4.21,<=0.4.23) ; extra == "chromadb"
|
30
30
|
Requires-Dist: colorlog (>=6.7.0,<7.0.0)
|
31
31
|
Requires-Dist: docstring-parser (>=0.15,<0.16)
|
32
|
-
Requires-Dist: duckduckgo-search (>=
|
32
|
+
Requires-Dist: duckduckgo-search (>=5.3.0,<6.0.0)
|
33
33
|
Requires-Dist: faker (>=18.9.0,<19.0.0)
|
34
34
|
Requires-Dist: fakeredis (>=2.12.1,<3.0.0)
|
35
35
|
Requires-Dist: fire (>=0.5.0,<0.6.0)
|
36
36
|
Requires-Dist: flake8 (>=6.0.0,<7.0.0)
|
37
37
|
Requires-Dist: google-api-python-client (>=2.95.0,<3.0.0)
|
38
|
+
Requires-Dist: groq (>=0.5.0,<0.6.0)
|
38
39
|
Requires-Dist: grpcio (>=1.62.1,<2.0.0)
|
39
40
|
Requires-Dist: halo (>=0.0.31,<0.0.32)
|
40
41
|
Requires-Dist: huggingface-hub (>=0.21.2,<0.22.0) ; extra == "transformers"
|
@@ -57,6 +58,7 @@ Requires-Dist: mkdocstrings[python] (>=0.21.2,<0.22.0) ; extra == "mkdocs"
|
|
57
58
|
Requires-Dist: momento (>=1.10.2,<2.0.0)
|
58
59
|
Requires-Dist: mypy (>=1.7.0,<2.0.0)
|
59
60
|
Requires-Dist: neo4j (>=5.14.1,<6.0.0) ; extra == "neo4j"
|
61
|
+
Requires-Dist: nest-asyncio (>=1.6.0,<2.0.0)
|
60
62
|
Requires-Dist: nltk (>=3.8.1,<4.0.0)
|
61
63
|
Requires-Dist: onnxruntime (==1.16.1)
|
62
64
|
Requires-Dist: openai (>=1.14.0,<2.0.0)
|
@@ -81,6 +83,7 @@ Requires-Dist: pytest-postgresql (>=5.0.0,<6.0.0) ; extra == "postgres"
|
|
81
83
|
Requires-Dist: pytest-redis (>=3.0.2,<4.0.0)
|
82
84
|
Requires-Dist: python-docx (>=1.1.0,<2.0.0)
|
83
85
|
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
86
|
+
Requires-Dist: python-magic (>=0.4.27,<0.5.0)
|
84
87
|
Requires-Dist: python-socketio (>=5.11.0,<6.0.0) ; extra == "chainlit"
|
85
88
|
Requires-Dist: qdrant-client (>=1.8.0,<2.0.0)
|
86
89
|
Requires-Dist: rank-bm25 (>=0.2.2,<0.3.0)
|
@@ -230,6 +233,19 @@ teacher_task.run()
|
|
230
233
|
<details>
|
231
234
|
<summary> <b>Click to expand</b></summary>
|
232
235
|
|
236
|
+
- **Apr 2024:**
|
237
|
+
- **0.1.236**: Support for open LLMs hosted on Groq, e.g. specify
|
238
|
+
`chat_model="groq/llama3-8b-8192"`.
|
239
|
+
See [tutorial](https://langroid.github.io/langroid/tutorials/local-llm-setup/).
|
240
|
+
- **0.1.235**: `Task.run(), Task.run_async(), run_batch_tasks` have `max_cost`
|
241
|
+
and `max_tokens` params to exit when tokens or cost exceed a limit. The result
|
242
|
+
`ChatDocument.metadata` now includes a `status` field which is a code indicating a
|
243
|
+
task completion reason code. Also `task.run()` etc can be invoked with an explicit
|
244
|
+
`session_id` field which is used as a key to look up various settings in Redis cache.
|
245
|
+
Currently only used to look up "kill status" - this allows killing a running task, either by `task.kill()`
|
246
|
+
or by the classmethod `Task.kill_session(session_id)`.
|
247
|
+
For example usage, see the `test_task_kill` in [tests/main/test_task.py](https://github.com/langroid/langroid/blob/main/tests/main/test_task.py)
|
248
|
+
|
233
249
|
- **Mar 2024:**
|
234
250
|
- **0.1.216:** Improvements to allow concurrent runs of `DocChatAgent`, see the
|
235
251
|
[`test_doc_chat_agent.py`](https://github.com/langroid/langroid/blob/main/tests/main/test_doc_chat_agent.py)
|
@@ -8,7 +8,7 @@ langroid/agent/chat_agent.py,sha256=X5uVMm9qdw3j-FRf4hbN8k8ByaSdtQCTuU8olKE0sbs,
|
|
8
8
|
langroid/agent/chat_document.py,sha256=NGr5FEWasPUQZ7cJnqrkVYYTi5fOqplSoCU-z5tTONA,8422
|
9
9
|
langroid/agent/helpers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
langroid/agent/junk,sha256=LxfuuW7Cijsg0szAzT81OjWWv1PMNI-6w_-DspVIO2s,339
|
11
|
-
langroid/agent/openai_assistant.py,sha256=
|
11
|
+
langroid/agent/openai_assistant.py,sha256=kIVDI4r-xGvplLU5s0nShPVHs6Jq-wOsfWE0kcMhAdQ,33056
|
12
12
|
langroid/agent/special/__init__.py,sha256=NG0JkB5y4K0bgnd9Q9UIvFExun3uTfVOWEVLVymff1M,1207
|
13
13
|
langroid/agent/special/doc_chat_agent.py,sha256=LwWNb_1s5n9rOk9OpOFPuuY1VnVX5DjzQmPwBanKRrM,53763
|
14
14
|
langroid/agent/special/lance_doc_chat_agent.py,sha256=USp0U3eTaJzwF_3bdqE7CedSLbaqAi2tm-VzygcyLaA,10175
|
@@ -32,7 +32,7 @@ langroid/agent/special/sql/utils/populate_metadata.py,sha256=x2OMKfmIBnJESBG3qKt
|
|
32
32
|
langroid/agent/special/sql/utils/system_message.py,sha256=qKLHkvQWRQodTtPLPxr1GSLUYUFASZU8x-ybV67cB68,1885
|
33
33
|
langroid/agent/special/sql/utils/tools.py,sha256=6uB2424SLtmapui9ggcEr0ZTiB6_dL1-JRGgN8RK9Js,1332
|
34
34
|
langroid/agent/special/table_chat_agent.py,sha256=coEvEWL9UJJSeDu8JcOxR4qCyzH7HuTdre7-3pMfGjo,8785
|
35
|
-
langroid/agent/task.py,sha256=
|
35
|
+
langroid/agent/task.py,sha256=b_d46txohISETxXJoWpmIX0hinvt1wjHbK08LZRBEz8,54020
|
36
36
|
langroid/agent/tool_message.py,sha256=2kPsQUwi3ZzINTUNj10huKnZLjLp5SXmefacTHx8QDc,8304
|
37
37
|
langroid/agent/tools/__init__.py,sha256=q-maq3k2BXhPAU99G0H6-j_ozoRvx15I1RFpPVicQIU,304
|
38
38
|
langroid/agent/tools/duckduckgo_search_tool.py,sha256=mLGhlgs6pwbYZIwrOs9shfh1dMBVT4DtkR29pYL3cCQ,1900
|
@@ -52,6 +52,7 @@ langroid/embedding_models/__init__.py,sha256=AJg2668ytmUyqYP0SGw-ZKz2ITi4YK7IAv2
|
|
52
52
|
langroid/embedding_models/base.py,sha256=xY9QF01ilsMvaNH4JMDvkZgXY59AeYR4VAykgNd6Flg,1818
|
53
53
|
langroid/embedding_models/clustering.py,sha256=tZWElUqXl9Etqla0FAa7og96iDKgjqWjucZR_Egtp-A,6684
|
54
54
|
langroid/embedding_models/models.py,sha256=-xeN0irBPc1tUgRFHGM1ki4NwOIHr6F3SKuEjD5nTOg,7144
|
55
|
+
langroid/embedding_models/protoc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
56
|
langroid/embedding_models/protoc/embeddings.proto,sha256=_O-SgFpTaylQeOTgSpxhEJ7CUw7PeCQQJLaPqpPYKJg,321
|
56
57
|
langroid/embedding_models/protoc/embeddings_pb2.py,sha256=4Q57PhOunv-uZNJrxYrWBXAI0ZtfnVZXFRhRj5JuRSg,1662
|
57
58
|
langroid/embedding_models/protoc/embeddings_pb2.pyi,sha256=UkNy7BrNsmQm0vLb3NtGXy8jVtz-kPWwwFsX-QbQBhQ,1475
|
@@ -62,7 +63,7 @@ langroid/language_models/azure_openai.py,sha256=ncRCbKooqLVOY-PWQUIo9C3yTuKEFbAw
|
|
62
63
|
langroid/language_models/base.py,sha256=B6dX43ZR65mIvjD95W4RcfpT-WpmiuEcstR3eMrr56Y,21029
|
63
64
|
langroid/language_models/config.py,sha256=5UF3DzO1a-Dfsc3vghE0XGq7g9t_xDsRCsuRiU4dgBg,366
|
64
65
|
langroid/language_models/openai_assistants.py,sha256=9K-DEAL2aSWHeXj2hwCo2RAlK9_1oCPtqX2u1wISCj8,36
|
65
|
-
langroid/language_models/openai_gpt.py,sha256=
|
66
|
+
langroid/language_models/openai_gpt.py,sha256=BOZt2lOFViN3ct-jvfELRKeUkUaBOGhGxO7F6JQNCNY,50257
|
66
67
|
langroid/language_models/prompt_formatter/__init__.py,sha256=9JXFF22QNMmbQV1q4nrIeQVTtA3Tx8tEZABLtLBdFyc,352
|
67
68
|
langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
|
68
69
|
langroid/language_models/prompt_formatter/hf_formatter.py,sha256=TFL6ppmeQWnzr6CKQzRZFYY810zE1mr8DZnhw6i85ok,5217
|
@@ -120,7 +121,7 @@ langroid/vector_store/meilisearch.py,sha256=d2huA9P-NoYRuAQ9ZeXJmMKr7ry8u90RUSR2
|
|
120
121
|
langroid/vector_store/momento.py,sha256=9cui31TTrILid2KIzUpBkN2Ey3g_CZWOQVdaFsA4Ors,10045
|
121
122
|
langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
|
122
123
|
langroid/vector_store/qdrantdb.py,sha256=foKRxRv0BBony6S4Vt0Vav9Rn9HMxZvcIh1cE7nosFE,13524
|
123
|
-
langroid-0.1.
|
124
|
-
langroid-0.1.
|
125
|
-
langroid-0.1.
|
126
|
-
langroid-0.1.
|
124
|
+
langroid-0.1.237.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
125
|
+
langroid-0.1.237.dist-info/METADATA,sha256=8bm8JGn4PdHABe-cp1DGCG8xKRTM-hC63FaJiXmH3NU,48961
|
126
|
+
langroid-0.1.237.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
127
|
+
langroid-0.1.237.dist-info/RECORD,,
|
File without changes
|
File without changes
|