langroid 0.1.235__tar.gz → 0.1.237__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.
Files changed (127) hide show
  1. {langroid-0.1.235 → langroid-0.1.237}/PKG-INFO +18 -2
  2. {langroid-0.1.235 → langroid-0.1.237}/README.md +13 -0
  3. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/openai_assistant.py +16 -13
  4. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/task.py +3 -2
  5. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/openai_gpt.py +37 -12
  6. langroid-0.1.237/langroid/utils/web/__init__.py +0 -0
  7. {langroid-0.1.235 → langroid-0.1.237}/pyproject.toml +5 -2
  8. {langroid-0.1.235 → langroid-0.1.237}/LICENSE +0 -0
  9. {langroid-0.1.235 → langroid-0.1.237}/langroid/__init__.py +0 -0
  10. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/__init__.py +0 -0
  11. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/base.py +0 -0
  12. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/batch.py +0 -0
  13. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/callbacks/__init__.py +0 -0
  14. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/callbacks/chainlit.py +0 -0
  15. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/chat_agent.py +0 -0
  16. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/chat_document.py +0 -0
  17. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/helpers.py +0 -0
  18. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/junk +0 -0
  19. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/__init__.py +0 -0
  20. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/doc_chat_agent.py +0 -0
  21. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
  22. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/lance_rag/__init__.py +0 -0
  23. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
  24. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
  25. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
  26. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/lance_tools.py +0 -0
  27. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/neo4j/__init__.py +0 -0
  28. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
  29. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
  30. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/neo4j/utils/__init__.py +0 -0
  31. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/neo4j/utils/system_message.py +0 -0
  32. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/relevance_extractor_agent.py +0 -0
  33. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/retriever_agent.py +0 -0
  34. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/__init__.py +0 -0
  35. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/sql_chat_agent.py +0 -0
  36. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/utils/__init__.py +0 -0
  37. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
  38. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
  39. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/utils/system_message.py +0 -0
  40. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/sql/utils/tools.py +0 -0
  41. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/special/table_chat_agent.py +0 -0
  42. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tool_message.py +0 -0
  43. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/__init__.py +0 -0
  44. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
  45. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/extract_tool.py +0 -0
  46. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/generator_tool.py +0 -0
  47. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/google_search_tool.py +0 -0
  48. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/metaphor_search_tool.py +0 -0
  49. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/recipient_tool.py +0 -0
  50. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/run_python_code.py +0 -0
  51. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent/tools/segment_extract_tool.py +0 -0
  52. {langroid-0.1.235 → langroid-0.1.237}/langroid/agent_config.py +0 -0
  53. {langroid-0.1.235 → langroid-0.1.237}/langroid/cachedb/__init__.py +0 -0
  54. {langroid-0.1.235 → langroid-0.1.237}/langroid/cachedb/base.py +0 -0
  55. {langroid-0.1.235 → langroid-0.1.237}/langroid/cachedb/momento_cachedb.py +0 -0
  56. {langroid-0.1.235 → langroid-0.1.237}/langroid/cachedb/redis_cachedb.py +0 -0
  57. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/__init__.py +0 -0
  58. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/base.py +0 -0
  59. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/clustering.py +0 -0
  60. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/models.py +0 -0
  61. {langroid-0.1.235/langroid/utils/llms → langroid-0.1.237/langroid/embedding_models/protoc}/__init__.py +0 -0
  62. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/protoc/embeddings.proto +0 -0
  63. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
  64. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
  65. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
  66. {langroid-0.1.235 → langroid-0.1.237}/langroid/embedding_models/remote_embeds.py +0 -0
  67. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/__init__.py +0 -0
  68. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/azure_openai.py +0 -0
  69. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/base.py +0 -0
  70. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/config.py +0 -0
  71. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/openai_assistants.py +0 -0
  72. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/prompt_formatter/__init__.py +0 -0
  73. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/prompt_formatter/base.py +0 -0
  74. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
  75. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
  76. {langroid-0.1.235 → langroid-0.1.237}/langroid/language_models/utils.py +0 -0
  77. {langroid-0.1.235 → langroid-0.1.237}/langroid/mytypes.py +0 -0
  78. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/__init__.py +0 -0
  79. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/agent_chats.py +0 -0
  80. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/code-parsing.md +0 -0
  81. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/code_parser.py +0 -0
  82. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/config.py +0 -0
  83. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/document_parser.py +0 -0
  84. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/image_text.py +0 -0
  85. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/para_sentence_split.py +0 -0
  86. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/parse_json.py +0 -0
  87. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/parser.py +0 -0
  88. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/repo_loader.py +0 -0
  89. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/search.py +0 -0
  90. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/spider.py +0 -0
  91. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/table_loader.py +0 -0
  92. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/url_loader.py +0 -0
  93. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/url_loader_cookies.py +0 -0
  94. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/urls.py +0 -0
  95. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/utils.py +0 -0
  96. {langroid-0.1.235 → langroid-0.1.237}/langroid/parsing/web_search.py +0 -0
  97. {langroid-0.1.235 → langroid-0.1.237}/langroid/prompts/__init__.py +0 -0
  98. {langroid-0.1.235 → langroid-0.1.237}/langroid/prompts/chat-gpt4-system-prompt.md +0 -0
  99. {langroid-0.1.235 → langroid-0.1.237}/langroid/prompts/dialog.py +0 -0
  100. {langroid-0.1.235 → langroid-0.1.237}/langroid/prompts/prompts_config.py +0 -0
  101. {langroid-0.1.235 → langroid-0.1.237}/langroid/prompts/templates.py +0 -0
  102. {langroid-0.1.235 → langroid-0.1.237}/langroid/prompts/transforms.py +0 -0
  103. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/__init__.py +0 -0
  104. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/algorithms/__init__.py +0 -0
  105. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/algorithms/graph.py +0 -0
  106. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/configuration.py +0 -0
  107. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/constants.py +0 -0
  108. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/docker.py +0 -0
  109. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/globals.py +0 -0
  110. {langroid-0.1.235/langroid/utils/web → langroid-0.1.237/langroid/utils/llms}/__init__.py +0 -0
  111. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/llms/strings.py +0 -0
  112. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/logging.py +0 -0
  113. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/output/__init__.py +0 -0
  114. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/output/printing.py +0 -0
  115. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/output/status.py +0 -0
  116. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/pandas_utils.py +0 -0
  117. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/pydantic_utils.py +0 -0
  118. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/system.py +0 -0
  119. {langroid-0.1.235 → langroid-0.1.237}/langroid/utils/web/login.py +0 -0
  120. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/__init__.py +0 -0
  121. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/base.py +0 -0
  122. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/chromadb.py +0 -0
  123. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/lancedb.py +0 -0
  124. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/meilisearch.py +0 -0
  125. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/momento.py +0 -0
  126. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/qdrant_cloud.py +0 -0
  127. {langroid-0.1.235 → langroid-0.1.237}/langroid/vector_store/qdrantdb.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.1.235
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 (>=4.4,<5.0)
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)
@@ -122,6 +122,19 @@ teacher_task.run()
122
122
  <details>
123
123
  <summary> <b>Click to expand</b></summary>
124
124
 
125
+ - **Apr 2024:**
126
+ - **0.1.236**: Support for open LLMs hosted on Groq, e.g. specify
127
+ `chat_model="groq/llama3-8b-8192"`.
128
+ See [tutorial](https://langroid.github.io/langroid/tutorials/local-llm-setup/).
129
+ - **0.1.235**: `Task.run(), Task.run_async(), run_batch_tasks` have `max_cost`
130
+ and `max_tokens` params to exit when tokens or cost exceed a limit. The result
131
+ `ChatDocument.metadata` now includes a `status` field which is a code indicating a
132
+ task completion reason code. Also `task.run()` etc can be invoked with an explicit
133
+ `session_id` field which is used as a key to look up various settings in Redis cache.
134
+ Currently only used to look up "kill status" - this allows killing a running task, either by `task.kill()`
135
+ or by the classmethod `Task.kill_session(session_id)`.
136
+ 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)
137
+
125
138
  - **Mar 2024:**
126
139
  - **0.1.216:** Improvements to allow concurrent runs of `DocChatAgent`, see the
127
140
  [`test_doc_chat_agent.py`](https://github.com/langroid/langroid/blob/main/tests/main/test_doc_chat_agent.py)
@@ -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.llm.client.beta.threads.runs
105
- self.threads = self.llm.client.beta.threads
106
- self.thread_messages = self.llm.client.beta.threads.messages
107
- self.assistants = self.llm.client.beta.assistants
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.llm.client.organization or ""
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.llm.client.organization or ""
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.llm.client.beta.threads.retrieve(thread_id=cached)
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.llm.client.beta.threads.delete(thread_id=cached)
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.llm.client.beta.threads.create()
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.llm.client.beta.assistants.retrieve(
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.llm.client.beta.assistants.delete(assistant_id=cached)
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.llm.client.beta.assistants.create(
397
+ self.assistant = self.client.beta.assistants.create(
395
398
  name=self.config.name,
396
399
  instructions=self.config.system_message,
397
400
  tools=[],
@@ -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 current session.
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")
@@ -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
- self.client = OpenAI(
452
- api_key=self.api_key,
453
- base_url=self.api_base,
454
- organization=self.config.organization,
455
- timeout=Timeout(self.config.timeout),
456
- )
457
- self.async_client = AsyncOpenAI(
458
- api_key=self.api_key,
459
- organization=self.config.organization,
460
- base_url=self.api_base,
461
- timeout=Timeout(self.config.timeout),
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
File without changes
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.1.235"
3
+ version = "0.1.237"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"
@@ -90,12 +90,15 @@ grpcio = "^1.62.1"
90
90
  metaphor-python = {version = "^0.1.23", optional = true}
91
91
  chainlit = {version = "^1.0.400", optional = true}
92
92
  python-socketio = {version="^5.11.0", optional=true}
93
- duckduckgo-search = "^4.4"
93
+ duckduckgo-search = "^5.3.0"
94
94
  huggingface-hub = {version="^0.21.2", optional=true}
95
95
  pdf2image = "^1.17.0"
96
96
  pytesseract = "^0.3.10"
97
97
  types-pyyaml = "^6.0.12.20240311"
98
98
  types-pillow = "^10.2.0.20240406"
99
+ groq = "^0.5.0"
100
+ nest-asyncio = "^1.6.0"
101
+ python-magic = "^0.4.27"
99
102
 
100
103
  [tool.poetry.extras]
101
104
  # install these using `poetry install -E [...]` where [...] is one of the extras below
File without changes