langroid 0.52.4__py3-none-any.whl → 0.52.6__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.
@@ -735,7 +735,11 @@ class ChatAgent(Agent):
735
735
  self.llm_tools_usable.discard(t)
736
736
  self.llm_functions_usable.discard(t)
737
737
 
738
- # Set tool instructions and JSON format instructions
738
+ self._update_tool_instructions()
739
+
740
+ def _update_tool_instructions(self) -> None:
741
+ # Set tool instructions and JSON format instructions,
742
+ # in case Tools have been enabled/disabled.
739
743
  if self.config.use_tools:
740
744
  self.system_tool_format_instructions = self.tool_format_rules()
741
745
  self.system_tool_instructions = self.tool_instructions()
@@ -977,6 +981,8 @@ class ChatAgent(Agent):
977
981
  self.llm_tools_usable.discard(t)
978
982
  self.llm_functions_usable.discard(t)
979
983
 
984
+ self._update_tool_instructions()
985
+
980
986
  def disable_message_use_except(self, message_class: Type[ToolMessage]) -> None:
981
987
  """
982
988
  Disable this agent from USING ALL messages EXCEPT a message class (Tool)
@@ -988,6 +994,7 @@ class ChatAgent(Agent):
988
994
  for r in to_remove:
989
995
  self.llm_tools_usable.discard(r)
990
996
  self.llm_functions_usable.discard(r)
997
+ self._update_tool_instructions()
991
998
 
992
999
  def _load_output_format(self, message: ChatDocument) -> None:
993
1000
  """
@@ -123,6 +123,9 @@ class DocChatAgentConfig(ChatAgentConfig):
123
123
  None # filter condition for various lexical/semantic search fns
124
124
  )
125
125
  conversation_mode: bool = True # accumulate message history?
126
+ # retain retrieved context? Setting to True increases token consumption, but
127
+ # helps LLM fix citation errors and improve accuracy of follow-up questions.
128
+ retain_context: bool = False
126
129
  # In assistant mode, DocChatAgent receives questions from another Agent,
127
130
  # and those will already be in stand-alone form, so in this mode
128
131
  # there is no need to convert them to stand-alone form.
@@ -861,8 +864,11 @@ class DocChatAgent(ChatAgent):
861
864
  # one for `final_prompt`, and one for the LLM response
862
865
 
863
866
  if self.config.conversation_mode:
864
- # respond with temporary context
865
- answer_doc = super()._llm_response_temp_context(question, final_prompt)
867
+ if self.config.retain_context:
868
+ answer_doc = super().llm_response(final_prompt)
869
+ else:
870
+ # respond with temporary context
871
+ answer_doc = super()._llm_response_temp_context(question, final_prompt)
866
872
  else:
867
873
  answer_doc = super().llm_response_forget(final_prompt)
868
874
 
@@ -6,12 +6,3 @@ __all__ = [
6
6
  "base",
7
7
  "redis_cachedb",
8
8
  ]
9
-
10
-
11
- try:
12
- from . import momento_cachedb
13
-
14
- momento_cachedb
15
- __all__.append("momento_cachedb")
16
- except ImportError:
17
- pass
@@ -627,20 +627,7 @@ class OpenAIGPT(LanguageModel):
627
627
 
628
628
  self.cache: CacheDB | None = None
629
629
  use_cache = self.config.cache_config is not None
630
- if settings.cache_type == "momento" and use_cache:
631
- from langroid.cachedb.momento_cachedb import (
632
- MomentoCache,
633
- MomentoCacheConfig,
634
- )
635
-
636
- if config.cache_config is None or not isinstance(
637
- config.cache_config,
638
- MomentoCacheConfig,
639
- ):
640
- # switch to fresh momento config if needed
641
- config.cache_config = MomentoCacheConfig()
642
- self.cache = MomentoCache(config.cache_config)
643
- elif "redis" in settings.cache_type and use_cache:
630
+ if "redis" in settings.cache_type and use_cache:
644
631
  if config.cache_config is None or not isinstance(
645
632
  config.cache_config,
646
633
  RedisCacheConfig,
@@ -656,7 +643,7 @@ class OpenAIGPT(LanguageModel):
656
643
  elif settings.cache_type != "none" and use_cache:
657
644
  raise ValueError(
658
645
  f"Invalid cache type {settings.cache_type}. "
659
- "Valid types are momento, redis, fakeredis, none"
646
+ "Valid types are redis, fakeredis, none"
660
647
  )
661
648
 
662
649
  self.config._validate_litellm()
@@ -17,7 +17,7 @@ class Settings(BaseSettings):
17
17
  progress: bool = False # show progress spinners/bars?
18
18
  stream: bool = True # stream output?
19
19
  cache: bool = True # use cache?
20
- cache_type: Literal["redis", "fakeredis", "momento", "none"] = "redis" # cache type
20
+ cache_type: Literal["redis", "fakeredis", "none"] = "redis" # cache type
21
21
  chat_model: str = "" # language model name, e.g. litellm/ollama/llama2
22
22
  quiet: bool = False # quiet mode (i.e. suppress all output)?
23
23
  notebook: bool = False # running in a notebook?
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langroid
3
- Version: 0.52.4
3
+ Version: 0.52.6
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  Author-email: Prasad Chalasani <pchalasani@gmail.com>
6
6
  License: MIT
@@ -151,8 +151,6 @@ Provides-Extra: meilisearch
151
151
  Requires-Dist: meilisearch-python-sdk<3.0.0,>=2.2.3; extra == 'meilisearch'
152
152
  Provides-Extra: metaphor
153
153
  Requires-Dist: metaphor-python<0.2.0,>=0.1.23; extra == 'metaphor'
154
- Provides-Extra: momento
155
- Requires-Dist: momento<1.21.0,>=1.10.2; extra == 'momento'
156
154
  Provides-Extra: mysql
157
155
  Requires-Dist: pymysql<2.0.0,>=1.1.0; extra == 'mysql'
158
156
  Provides-Extra: neo4j
@@ -617,9 +615,8 @@ section above)
617
615
  providers ([local/open](https://langroid.github.io/langroid/tutorials/local-llm-setup/) or [remote/commercial](https://langroid.github.io/langroid/tutorials/non-openai-llms/)) via proxy libraries and local model servers
618
616
  such as [ollama](https://github.com/ollama), [oobabooga](https://github.com/oobabooga/text-generation-webui),
619
617
  [LiteLLM](https://docs.litellm.ai/docs/providers) that in effect mimic the OpenAI API. See the [supported LLMs](https://langroid.github.io/langroid/tutorials/supported-models/).
620
- - **Caching of LLM responses:** Langroid supports [Redis](https://redis.com/try-free/) and
621
- [Momento](https://www.gomomento.com/) to cache LLM responses.
622
- - **Vector-stores**: [LanceDB](https://github.com/lancedb/lancedb), [Qdrant](https://qdrant.tech/), [Chroma](https://www.trychroma.com/) are currently supported.
618
+ - **Caching of LLM responses:** Langroid supports [Redis](https://redis.com/try-free/) to cache LLM responses.
619
+ - **Vector-stores**: [Qdrant](https://qdrant.tech/), [Chroma](https://www.trychroma.com/), LanceDB, Pinecone, PostgresDB (PGVector), Weaviate are currently supported.
623
620
  Vector stores allow for Retrieval-Augmented-Generation (RAG).
624
621
  - **Grounding and source-citation:** Access to external documents via vector-stores
625
622
  allows for grounding and source-citation.
@@ -5,7 +5,7 @@ langroid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  langroid/agent/__init__.py,sha256=ll0Cubd2DZ-fsCMl7e10hf9ZjFGKzphfBco396IKITY,786
6
6
  langroid/agent/base.py,sha256=lWR4ivX_elTFejpknLhkO-DlAGT3aG6ojQAVkzDOqMc,80090
7
7
  langroid/agent/batch.py,sha256=vi1r5i1-vN80WfqHDSwjEym_KfGsqPGUtwktmiK1nuk,20635
8
- langroid/agent/chat_agent.py,sha256=mIkf3kq5m1RPXeBb6U52pXB9itum0ChcpXABC_g-Xfs,85082
8
+ langroid/agent/chat_agent.py,sha256=nsFSARSANCVByL4fAl_DhyWm9gM7s_6waqNsmePXJMA,85309
9
9
  langroid/agent/chat_document.py,sha256=6O20Fp4QrquykaF2jFtwNHkvcoDte1LLwVZNk9mVH9c,18057
10
10
  langroid/agent/openai_assistant.py,sha256=JkAcs02bIrgPNVvUWVR06VCthc5-ulla2QMBzux_q6o,34340
11
11
  langroid/agent/task.py,sha256=HB6N-Jn80HFqCf0ZYOC1v3Bn3oO7NLjShHQJJFwW0q4,90557
@@ -14,7 +14,7 @@ langroid/agent/xml_tool_message.py,sha256=6SshYZJKIfi4mkE-gIoSwjkEYekQ8GwcSiCv7a
14
14
  langroid/agent/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  langroid/agent/callbacks/chainlit.py,sha256=UHB6P_J40vsVnssosqkpkOVWRf9NK4TOY0_G2g_Arsg,20900
16
16
  langroid/agent/special/__init__.py,sha256=gik_Xtm_zV7U9s30Mn8UX3Gyuy4jTjQe9zjiE3HWmEo,1273
17
- langroid/agent/special/doc_chat_agent.py,sha256=ALp2rv12J-ChRCxVtflDwz6n0qIbUAymldIy8qpsvrg,65236
17
+ langroid/agent/special/doc_chat_agent.py,sha256=-ABgZiaIowFVqYMYlU1Nf8WfOqXOTmlMCEnafEXucPo,65564
18
18
  langroid/agent/special/doc_chat_task.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  langroid/agent/special/lance_doc_chat_agent.py,sha256=s8xoRs0gGaFtDYFUSIRchsgDVbS5Q3C2b2mr3V1Fd-Q,10419
20
20
  langroid/agent/special/lance_tools.py,sha256=qS8x4wi8mrqfbYV2ztFzrcxyhHQ0ZWOc-zkYiH7awj0,2105
@@ -54,9 +54,8 @@ langroid/agent/tools/retrieval_tool.py,sha256=zcAV20PP_6VzSd-UE-IJcabaBseFL_QNz5
54
54
  langroid/agent/tools/rewind_tool.py,sha256=XAXL3BpNhCmBGYq_qi_sZfHJuIw7NY2jp4wnojJ7WRs,5606
55
55
  langroid/agent/tools/segment_extract_tool.py,sha256=__srZ_VGYLVOdPrITUM8S0HpmX4q7r5FHWMDdHdEv8w,1440
56
56
  langroid/agent/tools/tavily_search_tool.py,sha256=soI-j0HdgVQLf09wRQScaEK4b5RpAX9C4cwOivRFWWI,1903
57
- langroid/cachedb/__init__.py,sha256=icAT2s7Vhf-ZGUeqpDQGNU6ob6o0aFEyjwcxxUGRFjg,225
57
+ langroid/cachedb/__init__.py,sha256=G2KyNnk3Qkhv7OKyxTOnpsxfDycx3NY0O_wXkJlalNY,96
58
58
  langroid/cachedb/base.py,sha256=ztVjB1DtN6pLCujCWnR6xruHxwVj3XkYniRTYAKKqk0,1354
59
- langroid/cachedb/momento_cachedb.py,sha256=YEOJ62hEcV6iIeMr5aGgRYgWQqFYaej9gEDEcY0sm7M,3172
60
59
  langroid/cachedb/redis_cachedb.py,sha256=7kgnbf4b5CKsCrlL97mHWKvdvlLt8zgn7lc528jEpiE,5141
61
60
  langroid/embedding_models/__init__.py,sha256=KyYxR3jDFUCfYjSuCL86qjAmrq6mXXjOT4lFNOKVj6Y,955
62
61
  langroid/embedding_models/base.py,sha256=Ml7oA6PzQm0wZmIYn3fhF7dvZCi-amviWUwOeBegH3A,2562
@@ -73,7 +72,7 @@ langroid/language_models/base.py,sha256=pfN3t-BktKmN_4K8pwmpjC9OdcHxsytM5s5TmsJ-
73
72
  langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
74
73
  langroid/language_models/mock_lm.py,sha256=5BgHKDVRWFbUwDT_PFgTZXz9-k8wJSA2e3PZmyDgQ1k,4022
75
74
  langroid/language_models/model_info.py,sha256=vOaTi-XFKnz-BvHUvgjnt0XfOtl21Apev3Zy7Rhckbw,14458
76
- langroid/language_models/openai_gpt.py,sha256=KFbG6q143CYt6SP8rU1UEFX2mffn8yXfVOdEyuA5IaY,85854
75
+ langroid/language_models/openai_gpt.py,sha256=Hw4llY9Dbox7L0sVP06q10ayoem8FOfXSfbLm3u55v4,85317
77
76
  langroid/language_models/utils.py,sha256=hC5p61P_Qlrowkm5wMap1A1b5ZUCwK_XhPIzAQk1T1s,5483
78
77
  langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
79
78
  langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
@@ -105,7 +104,7 @@ langroid/prompts/templates.py,sha256=VV84HVf_amOx6xdWQyIsN9i5dNfrbl8rsfFp6hyfOss
105
104
  langroid/pydantic_v1/__init__.py,sha256=HxPGVERapVueRUORgSpj2JX_vTZxVlVbWvhpQlpjygE,283
106
105
  langroid/pydantic_v1/main.py,sha256=p_k7kDY9eDrsA5dxNNqXusKLgx7mS_icGnS7fu4goqY,147
107
106
  langroid/utils/__init__.py,sha256=Sruos2tB4G7Tn0vlblvYlX9PEGR0plI2uE0PJ4d_EC4,353
108
- langroid/utils/configuration.py,sha256=FJVoseN3mkqx5vzpmtkzCLuQEYlWZEK_11YJ-Ge-L5o,4812
107
+ langroid/utils/configuration.py,sha256=ZkHHkEeWuS-o3_S4g0SE0wz-UK_of23NOWve1kpQiNY,4801
109
108
  langroid/utils/constants.py,sha256=CK09kda9bNDEhnwClq7ZTWZOh38guJlfcZ5hKUS1Ijo,1075
110
109
  langroid/utils/git_utils.py,sha256=WnflJ3R3owhlD0LNdSJakcKhExcEehE1UW5jYVQl8JY,7955
111
110
  langroid/utils/globals.py,sha256=Az9dOFqR6n9CoTYSqa2kLikQWS0oCQ9DFQIQAnG-2q8,1355
@@ -130,7 +129,7 @@ langroid/vector_store/pineconedb.py,sha256=otxXZNaBKb9f_H75HTaU3lMHiaR2NUp5MqwLZ
130
129
  langroid/vector_store/postgres.py,sha256=wHPtIi2qM4fhO4pMQr95pz1ZCe7dTb2hxl4VYspGZoA,16104
131
130
  langroid/vector_store/qdrantdb.py,sha256=O6dSBoDZ0jzfeVBd7LLvsXu083xs2fxXtPa9gGX3JX4,18443
132
131
  langroid/vector_store/weaviatedb.py,sha256=Yn8pg139gOy3zkaPfoTbMXEEBCiLiYa1MU5d_3UA1K4,11847
133
- langroid-0.52.4.dist-info/METADATA,sha256=8q70bM9X5i9DkmZ9jg3zAEn5Lk-vUKaJRF46A2EnSvA,63642
134
- langroid-0.52.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
135
- langroid-0.52.4.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
136
- langroid-0.52.4.dist-info/RECORD,,
132
+ langroid-0.52.6.dist-info/METADATA,sha256=fOf2NTPNfbS1F9rSfa7oLtYHB66xFiN65MnRWybC9sU,63519
133
+ langroid-0.52.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
134
+ langroid-0.52.6.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
135
+ langroid-0.52.6.dist-info/RECORD,,
@@ -1,108 +0,0 @@
1
- import json
2
- import logging
3
- import os
4
- from datetime import timedelta
5
- from typing import Any, Dict, List
6
-
7
- from langroid.cachedb.base import CacheDBConfig
8
- from langroid.exceptions import LangroidImportError
9
-
10
- try:
11
- import momento
12
- from momento.responses import CacheGet
13
- except ImportError:
14
- raise LangroidImportError(package="momento", extra="momento")
15
-
16
- from dotenv import load_dotenv
17
-
18
- from langroid.cachedb.base import CacheDB
19
-
20
- logger = logging.getLogger(__name__)
21
-
22
-
23
- class MomentoCacheConfig(CacheDBConfig):
24
- """Configuration model for Momento Cache."""
25
-
26
- ttl: int = 60 * 60 * 24 * 7 # 1 week
27
- cachename: str = "langroid_momento_cache"
28
-
29
-
30
- class MomentoCache(CacheDB):
31
- """Momento implementation of the CacheDB."""
32
-
33
- def __init__(self, config: MomentoCacheConfig):
34
- """
35
- Initialize a MomentoCache with the given config.
36
-
37
- Args:
38
- config (MomentoCacheConfig): The configuration to use.
39
- """
40
- self.config = config
41
- load_dotenv()
42
-
43
- momento_token = os.getenv("MOMENTO_AUTH_TOKEN")
44
- if momento_token is None:
45
- raise ValueError("""MOMENTO_AUTH_TOKEN not set in .env file""")
46
- else:
47
- self.client = momento.CacheClient(
48
- configuration=momento.Configurations.Laptop.v1(),
49
- credential_provider=momento.CredentialProvider.from_environment_variable(
50
- "MOMENTO_AUTH_TOKEN"
51
- ),
52
- default_ttl=timedelta(seconds=self.config.ttl),
53
- )
54
- self.client.create_cache(self.config.cachename)
55
-
56
- def clear(self) -> None:
57
- """Clear keys from current db."""
58
- self.client.flush_cache(self.config.cachename)
59
-
60
- def store(self, key: str, value: Any) -> None:
61
- """
62
- Store a value associated with a key.
63
-
64
- Args:
65
- key (str): The key under which to store the value.
66
- value (Any): The value to store.
67
- """
68
- self.client.set(self.config.cachename, key, json.dumps(value))
69
-
70
- def retrieve(self, key: str) -> Dict[str, Any] | str | None:
71
- """
72
- Retrieve the value associated with a key.
73
-
74
- Args:
75
- key (str): The key to retrieve the value for.
76
-
77
- Returns:
78
- dict: The value associated with the key.
79
- """
80
- value = self.client.get(self.config.cachename, key)
81
- if isinstance(value, CacheGet.Hit):
82
- return json.loads(value.value_string) # type: ignore
83
- else:
84
- return None
85
-
86
- def delete_keys(self, keys: List[str]) -> None:
87
- """
88
- Delete the keys from the cache.
89
-
90
- Args:
91
- keys (List[str]): The keys to delete.
92
- """
93
- for key in keys:
94
- self.client.delete(self.config.cachename, key)
95
-
96
- def delete_keys_pattern(self, pattern: str) -> None:
97
- """
98
- Delete the keys from the cache with the given pattern.
99
-
100
- Args:
101
- prefix (str): The pattern to match.
102
- """
103
- raise NotImplementedError(
104
- """
105
- MomentoCache does not support delete_keys_pattern.
106
- Please use RedisCache instead.
107
- """
108
- )