langroid 0.1.31__py3-none-any.whl → 0.1.33__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.
@@ -177,7 +177,7 @@ class RetrieverAgent(DocChatAgent, ABC):
177
177
  list of Document objects
178
178
  """
179
179
  doc_contents = "\n\n".join(
180
- [f"DOC: ID={d.id()}, content={d.content}" for d in docs]
180
+ [f"DOC: ID={d.id()}, CONTENT: {d.content}" for d in docs]
181
181
  )
182
182
  prompt = f"""
183
183
  Given the following QUERY:
@@ -186,8 +186,11 @@ class RetrieverAgent(DocChatAgent, ABC):
186
186
  {doc_contents}
187
187
 
188
188
  Find at most {self.config.n_matches} DOCs that are most relevant to the QUERY.
189
- Return your as a sequence of DOC IDS ONLY, for example:
189
+ Return your answer as a sequence of DOC IDS ONLY, for example:
190
190
  "id1 id2 id3..."
191
+ If there are no relevant docs, simply say {NO_ANSWER}.
192
+ Even if there is only one relevant doc, return it as a single ID.
193
+ Do not give any explanations or justifications.
191
194
  """
192
195
  default_response = Document(
193
196
  content=NO_ANSWER,
langroid/agent/task.py CHANGED
@@ -61,6 +61,7 @@ class Task:
61
61
  user_message: str = "",
62
62
  restart: bool = False,
63
63
  default_human_response: Optional[str] = None,
64
+ interactive: bool = True,
64
65
  only_user_quits_root: bool = True,
65
66
  erase_substeps: bool = False,
66
67
  ):
@@ -84,6 +85,9 @@ class Task:
84
85
  restart (bool): if true, resets the agent's message history
85
86
  default_human_response (str): default response from user; useful for
86
87
  testing, to avoid interactive input from user.
88
+ interactive (bool): if true, wait for human input after each non-human
89
+ response (prevents infinite loop of non-human responses).
90
+ Default is true. If false, then `default_human_response` is set to ""
87
91
  only_user_quits_root (bool): if true, only user can quit the root task.
88
92
  erase_substeps (bool): if true, when task completes, erase intermediate
89
93
  conversation with subtasks from this agent's `message_history`, and also
@@ -111,6 +115,9 @@ class Task:
111
115
  self.agent = agent
112
116
  self.name = name or agent.config.name
113
117
  self.default_human_response = default_human_response
118
+ self.interactive = interactive
119
+ if not interactive:
120
+ self.default_human_response = ""
114
121
  if default_human_response is not None:
115
122
  self.agent.default_human_response = default_human_response
116
123
  self.only_user_quits_root = only_user_quits_root
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
15
15
 
16
16
 
17
17
  class MomentoCacheConfig(BaseModel):
18
- """Configuration model for RedisCache."""
18
+ """Configuration model for Momento Cache."""
19
19
 
20
20
  ttl: int = 60 * 60 * 24 * 7 # 1 week
21
21
  cachename: str = "langroid_momento_cache"
@@ -224,7 +224,7 @@ class OpenAIGPT(LanguageModel):
224
224
  hashed_key = hashlib.sha256(raw_key.encode()).hexdigest()
225
225
 
226
226
  if not settings.cache:
227
- # when cacheing disabled, return the hashed_key and none result
227
+ # when caching disabled, return the hashed_key and none result
228
228
  return hashed_key, None
229
229
  # Try to get the result from the cache
230
230
  return hashed_key, self.cache.retrieve(hashed_key)
@@ -96,7 +96,7 @@ class RepoLoader:
96
96
  json.dump({"junk": "ignore"}, f)
97
97
  with open(self.log_file, "r") as f:
98
98
  log = json.load(f)
99
- if self.url in log:
99
+ if self.url in log and os.path.exists(log[self.url]):
100
100
  logger.info(f"Repo Already downloaded in {log[self.url]}")
101
101
  self.clone_path = log[self.url]
102
102
 
@@ -55,7 +55,15 @@ SUMMARY_ANSWER_PROMPT_GPT4 = f"""
55
55
  and even if the answer contradicts other parts of the document. The only
56
56
  important thing is that your answer is consistent with and supported by the
57
57
  extracts. Compose your complete answer and cite all supporting sources on a
58
- separate separate line as "SOURCE:".
58
+ separate separate line as follows. For each SOURCE, (a) show the source name,
59
+ and (b) the exact EXTRACT from the source that supports your answer.
60
+ DO NOT SHOW THE FULL EXTRACT; only show the FIRST 3 words and LAST 3 words.
61
+ For example:
62
+ SOURCE: https://en.wikipedia.org/wiki/Tree
63
+ EXTRACTS: "The tree species ... oak, maple, and birch."
64
+
65
+ SOURCE: https://en.wikipedia.org/wiki/Oak
66
+ EXTRACTS: "The oak trees ... longevity and strength."
59
67
 
60
68
  {{extracts}}
61
69
 
@@ -1,9 +1,12 @@
1
1
  from typing import List
2
2
 
3
+ from dotenv import load_dotenv
3
4
  from pydantic import BaseSettings
4
5
 
5
6
 
6
7
  class Settings(BaseSettings):
8
+ # NOTE all of these can be overridden in your .env file with upper-case names,
9
+ # for example CACHE_TYPE=momento
7
10
  debug: bool = False # show debug messages?
8
11
  progress: bool = False # show progress spinners/bars?
9
12
  stream: bool = True # stream output?
@@ -17,6 +20,7 @@ class Settings(BaseSettings):
17
20
  extra = "forbid"
18
21
 
19
22
 
23
+ load_dotenv() # get settings from .env file
20
24
  settings = Settings()
21
25
 
22
26
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.1.31
3
+ Version: 0.1.33
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -154,7 +154,8 @@ Here is what it looks like in action:
154
154
  Agents with specific skills, wrap them in Tasks, and combine tasks in a flexible way.
155
155
  - **LLM Support**: Langroid supports OpenAI LLMs including GPT-3.5-Turbo,
156
156
  GPT-4-0613
157
- - **Caching of LLM prompts, responses:** Langroid uses [Redis](https://redis.com/try-free/) for caching.
157
+ - **Caching of LLM responses:** Langroid supports [Redis](https://redis.com/try-free/) and
158
+ [Momento](https://www.gomomento.com/) to cache LLM responses.
158
159
  - **Vector-stores**: [Qdrant](https://qdrant.tech/) and [Chroma](https://www.trychroma.com/) are currently supported.
159
160
  Vector stores allow for Retrieval-Augmented-Generation (RAG).
160
161
  - **Grounding and source-citation:** Access to external documents via vector-stores
@@ -226,14 +227,16 @@ All of the below are optional and not strictly needed to run any of the examples
226
227
  If you skip setting up these, Langroid will use Qdrant in local-storage mode.
227
228
  Alternatively [Chroma](https://docs.trychroma.com/) is also currently supported.
228
229
  We use the local-storage version of Chroma, so there is no need for an API key.
230
+ Langroid uses Qdrant by default.
229
231
  - **Redis** Password, host, port: This is optional, and only needed to cache LLM API responses
230
232
  using Redis Cloud. Redis [offers](https://redis.com/try-free/) a free 30MB Redis account
231
233
  which is more than sufficient to try out Langroid and even beyond.
232
234
  If you don't set up these, Langroid will use a pure-python
233
235
  Redis in-memory cache via the [Fakeredis](https://fakeredis.readthedocs.io/en/latest/) library.
234
236
  - **Momento** Serverless Caching of LLM API responses (as an alternative to Redis).
235
- To use Momento instead of Redis, simply enter your Momento Token in the `.env` file,
236
- as the value of `MOMENTO_AUTH_TOKEN` (see example file below).
237
+ To use Momento instead of Redis:
238
+ - enter your Momento Token in the `.env` file, as the value of `MOMENTO_AUTH_TOKEN` (see example file below),
239
+ - in the `.env` file set `CACHE_TYPE=momento` (instead of `CACHE_TYPE=redis` which is the default).
237
240
  - **GitHub** Personal Access Token (required for apps that need to analyze git
238
241
  repos; token-based API calls are less rate-limited). See this
239
242
  [GitHub page](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
@@ -242,6 +245,7 @@ If you add all of these optional variables, your `.env` file should look like th
242
245
  ```bash
243
246
  OPENAI_API_KEY=your-key-here-without-quotes
244
247
  GITHUB_ACCESS_TOKEN=your-personal-access-token-no-quotes
248
+ CACHE_TYPE=redis # or momento
245
249
  REDIS_PASSWORD=your-redis-password-no-quotes
246
250
  REDIS_HOST=your-redis-hostname-no-quotes
247
251
  REDIS_PORT=your-redis-port-no-quotes
@@ -8,14 +8,14 @@ langroid/agent/junk,sha256=LxfuuW7Cijsg0szAzT81OjWWv1PMNI-6w_-DspVIO2s,339
8
8
  langroid/agent/special/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  langroid/agent/special/doc_chat_agent.py,sha256=NhoS02rlLr3nAfRvLB1YNcmfsWZJH24K8O-m-uYnb-I,15741
10
10
  langroid/agent/special/recipient_validator_agent.py,sha256=x2UprcGlh-fyxQCZbb_fkKrruU5Om0mgOnNzk_PYBNM,4527
11
- langroid/agent/special/retriever_agent.py,sha256=AiGKIJdndV4u5kr3woINw-vLKhwWnsINlvXtXxHcJgQ,6995
11
+ langroid/agent/special/retriever_agent.py,sha256=dkG_-QdL5KvpeS4K4jnx1kV9h_KxVEhgHz2rzdilZss,7196
12
12
  langroid/agent/special/table_chat_agent.py,sha256=6xoFcb3-y3xb3NAADV-sXid77et1KRz5PcwN9GshP6g,4673
13
- langroid/agent/task.py,sha256=irYxLnJ6J7cJCEyJnq6KDIDc6T2VeaaixsWUm2P2x_s,25844
13
+ langroid/agent/task.py,sha256=KJZt6lSfCAVctyFfBJWLFcfys73kjrQJV4Y3aMVwO1M,26233
14
14
  langroid/agent/tool_message.py,sha256=7OdVcV7UyOZD2ihYgV1C_1fIwiWM-2pR8FFxoA1IgOo,5379
15
15
  langroid/agent_config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  langroid/cachedb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  langroid/cachedb/base.py,sha256=F-QSDlRXrC0tBRbxL397MX8hulfBMAnZNs1e9zH71OQ,790
18
- langroid/cachedb/momento_cachedb.py,sha256=TG_6sYhKvgl2b7t1bAQHDs9pXvkS6iPCwo-9_pMHwhs,2339
18
+ langroid/cachedb/momento_cachedb.py,sha256=mfLnAJO3-mPucHjwwgHeU7HQzE_jmUxca2qt3RUHVC0,2342
19
19
  langroid/cachedb/redis_cachedb.py,sha256=xuQ96FAqcHTfK8PEt1tjrh1BkMWUjojFHIgjDfF3SnU,2369
20
20
  langroid/embedding_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  langroid/embedding_models/base.py,sha256=176jDrjEAAhNzdFCG8pfossd8SAhvHR8Q5Y8pOOm0LI,983
@@ -23,7 +23,7 @@ langroid/embedding_models/clustering.py,sha256=tZWElUqXl9Etqla0FAa7og96iDKgjqWju
23
23
  langroid/embedding_models/models.py,sha256=1xcv9hqmCTsbUbS8v7XeZRsf25Tu79JUoSipIYpvNoo,2765
24
24
  langroid/language_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  langroid/language_models/base.py,sha256=7FMiUyJ3Kf9Uiqvjh-lNGfwnCibY0SbnK4jdORCv3SM,12657
26
- langroid/language_models/openai_gpt.py,sha256=NQYQqTj5OqsFtOxq9LBsJktEldbpeEKQTj_Jd-G7_XM,17974
26
+ langroid/language_models/openai_gpt.py,sha256=TuertCPkjJzz35YYGHTwX2E5gevENEPdPoFVyGl8M6k,17973
27
27
  langroid/language_models/utils.py,sha256=rmnSn-sJ3aKl_wBdeLPkck0Li4Ed6zkCxZYYl7n1V34,4668
28
28
  langroid/mytypes.py,sha256=YA42IJcooJnTxAwk-B4FmZ1hqzIIF1ZZKcpUKzBTGGo,1537
29
29
  langroid/parsing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -34,7 +34,7 @@ langroid/parsing/json.py,sha256=d56BDPjs7mC4Dc6aqm3pfNkTnA0Pq15tAJT7YkeQc0s,981
34
34
  langroid/parsing/para_sentence_split.py,sha256=2wa2_BWGhZx_Uh9TF8VsCOvn1TfLfQJcHmffJVtBtMg,1829
35
35
  langroid/parsing/parser.py,sha256=2qPjFfVjFI4jmt-21gYJTCyhYGv4HvssQj0aAGEz9ZY,7350
36
36
  langroid/parsing/pdf_parser.py,sha256=RFrck50VvqYl37xzUp-cj4uSC4FDIvJqTwv100Dilgg,1432
37
- langroid/parsing/repo_loader.py,sha256=_Wlv123kdvRMcVXll-VArRpciBHS2sGOUJRcBe8p6bo,26983
37
+ langroid/parsing/repo_loader.py,sha256=ILlvBH-wSvfdLLQKHklAzuxU980_ajts_bz7_9IwtLY,27017
38
38
  langroid/parsing/table_loader.py,sha256=4nK5QzQkwNwwzKRpg40pVLGarQp8HA9JqBQoRsGqDHA,1080
39
39
  langroid/parsing/url_loader.py,sha256=tdYPMC2V9zI_B207LFdU4aroZzJW4sY9y794XePFAVg,1824
40
40
  langroid/parsing/url_loader_cookies.py,sha256=Lg4sNpRz9MByWq2mde6T0hKv68VZSV3mtMjNEHuFeSU,2327
@@ -43,11 +43,11 @@ langroid/parsing/utils.py,sha256=giJOG_idlSrJi3BJWpot3ggent2VYnrNQS5Dj2lGpPk,683
43
43
  langroid/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
44
  langroid/prompts/dialog.py,sha256=SpfiSyofSgy2pwD1YboHR_yHO3LEEMbv6j2sm874jKo,331
45
45
  langroid/prompts/prompts_config.py,sha256=EMK1Fm7EmS8y3CV4AkrVgn5K4NipiM4m7J8819W1KeM,98
46
- langroid/prompts/templates.py,sha256=8jmDiCN926mFMalMYRUUzYykFnVojVeSTazdDH9V1zA,5850
46
+ langroid/prompts/templates.py,sha256=4OAujKJzKIhqt4SQL2GE1aPahlZuDotlT_dZAKx0bqE,6311
47
47
  langroid/prompts/transforms.py,sha256=GsQo1klGxUy0fACh6j0lTblk6XEl2erRnhRWlN2M4-c,2706
48
48
  langroid/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  langroid/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
- langroid/utils/configuration.py,sha256=ApAAL8w3TRtAolEl-nHy5fegLwA4WffsytbEbbWl0Tg,1564
50
+ langroid/utils/configuration.py,sha256=ZTKzE9hRx7QgoSiaAXMUJreWB5E-vOsU9MtPOKTzphY,1760
51
51
  langroid/utils/constants.py,sha256=_keF-e-GIwEFvBxKJbC1Ry0u3SVWQBk4HRX0NpV2Qq8,485
52
52
  langroid/utils/docker.py,sha256=kJQOLTgM0x9j9pgIIqp0dZNZCTvoUDhp6i8tYBq1Jr0,1105
53
53
  langroid/utils/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -64,7 +64,7 @@ langroid/vector_store/base.py,sha256=QZx3NUNwf2I0r3A7iuoUHIRGbqt_pFGD0hq1R-Yg8iM
64
64
  langroid/vector_store/chromadb.py,sha256=s5pQkKjaMP-Tt5A8M10EInFzttaALPbJAq7q4gf0TKg,5235
65
65
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
66
66
  langroid/vector_store/qdrantdb.py,sha256=KRvIIj1IZG2zFqejofMnRs2hT86B-27LgBEnuczdqOU,9072
67
- langroid-0.1.31.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
68
- langroid-0.1.31.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
69
- langroid-0.1.31.dist-info/METADATA,sha256=JcvdrnuK85jDSoXwGapFFUF5LnYLHMz3OgJBQTSlYFU,24978
70
- langroid-0.1.31.dist-info/RECORD,,
67
+ langroid-0.1.33.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
68
+ langroid-0.1.33.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
69
+ langroid-0.1.33.dist-info/METADATA,sha256=gGIWKbaKr2cNtJbwrH6rZvsx0GUKQJKyWLeUbADs3u0,25190
70
+ langroid-0.1.33.dist-info/RECORD,,