langroid 0.3.0__py3-none-any.whl → 0.3.1__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.
@@ -133,12 +133,15 @@ class AzureGPT(OpenAIGPT):
133
133
  """
134
134
  Handles the setting of the GPT-4 model in the configuration.
135
135
  This function checks the `model_version` in the configuration.
136
- If the version is not set, it raises a ValueError indicating that the model
137
- version needs to be specified in the ``.env`` file.
138
- It sets `OpenAIChatModel.GPT4_TURBO` if the version is
139
- '1106-Preview', otherwise, it defaults to setting `OpenAIChatModel.GPT4`.
136
+ If the version is not set, it raises a ValueError indicating
137
+ that the model version needs to be specified in the ``.env``
138
+ file. It sets `OpenAIChatMode.GPT4o` if the version is
139
+ '2024-05-13', `OpenAIChatModel.GPT4_TURBO` if the version is
140
+ '1106-Preview', otherwise, it defaults to setting
141
+ `OpenAIChatModel.GPT4`.
140
142
  """
141
143
  VERSION_1106_PREVIEW = "1106-Preview"
144
+ VERSION_GPT4o = "2024-05-13"
142
145
 
143
146
  if self.config.model_version == "":
144
147
  raise ValueError(
@@ -146,7 +149,9 @@ class AzureGPT(OpenAIGPT):
146
149
  "Please set it to the chat model version used in your deployment."
147
150
  )
148
151
 
149
- if self.config.model_version == VERSION_1106_PREVIEW:
152
+ if self.config.model_version == VERSION_GPT4o:
153
+ self.config.chat_model = OpenAIChatModel.GPT4o
154
+ elif self.config.model_version == VERSION_1106_PREVIEW:
150
155
  self.config.chat_model = OpenAIChatModel.GPT4_TURBO
151
156
  else:
152
157
  self.config.chat_model = OpenAIChatModel.GPT4
@@ -234,6 +234,7 @@ class LLMResponse(BaseModel):
234
234
  # in this case we ignore message, since all information is in function_call
235
235
  msg = ""
236
236
  args = self.function_call.arguments
237
+ recipient = ""
237
238
  if isinstance(args, dict):
238
239
  recipient = args.get("recipient", "")
239
240
  return recipient, msg
@@ -1,4 +1,3 @@
1
- import ast
2
1
  import hashlib
3
2
  import json
4
3
  import logging
@@ -49,6 +48,7 @@ from langroid.language_models.utils import (
49
48
  async_retry_with_exponential_backoff,
50
49
  retry_with_exponential_backoff,
51
50
  )
51
+ from langroid.parsing.parse_json import parse_imperfect_json
52
52
  from langroid.pydantic_v1 import BaseModel
53
53
  from langroid.utils.configuration import settings
54
54
  from langroid.utils.constants import Colors
@@ -797,11 +797,24 @@ class OpenAIGPT(LanguageModel):
797
797
  args = {}
798
798
  if has_function and function_args != "":
799
799
  try:
800
- args = ast.literal_eval(function_args.strip())
801
- except (SyntaxError, ValueError):
800
+ stripped_fn_args = function_args.strip()
801
+ dict_or_list = parse_imperfect_json(stripped_fn_args)
802
+ if not isinstance(dict_or_list, dict):
803
+ raise ValueError(
804
+ f"""
805
+ Invalid function args: {stripped_fn_args}
806
+ parsed as {dict_or_list},
807
+ which is not a valid dict.
808
+ """
809
+ )
810
+ args = dict_or_list
811
+ except (SyntaxError, ValueError) as e:
802
812
  logging.warning(
803
- f"Parsing OpenAI function args failed: {function_args};"
804
- " treating args as normal message"
813
+ f"""
814
+ Parsing OpenAI function args failed: {function_args};
815
+ treating args as normal message. Error detail:
816
+ {e}
817
+ """
805
818
  )
806
819
  has_function = False
807
820
  completion = completion + function_args
@@ -1,5 +1,6 @@
1
+ import ast
1
2
  import json
2
- from typing import Any, Iterator, List
3
+ from typing import Any, Dict, Iterator, List, Union
3
4
 
4
5
  import yaml
5
6
  from pyparsing import nestedExpr, originalTextFor
@@ -73,6 +74,31 @@ def add_quotes(s: str) -> str:
73
74
  return s
74
75
 
75
76
 
77
+ def parse_imperfect_json(json_string: str) -> Union[Dict[str, Any], List[Any]]:
78
+ if not json_string.strip():
79
+ raise ValueError("Empty string is not valid JSON")
80
+
81
+ # First, try parsing with ast.literal_eval
82
+ try:
83
+ result = ast.literal_eval(json_string)
84
+ if isinstance(result, (dict, list)):
85
+ return result
86
+ except (ValueError, SyntaxError):
87
+ pass
88
+
89
+ # If ast.literal_eval fails or returns non-dict/list, try json.loads
90
+ try:
91
+ str = add_quotes(json_string)
92
+ result = json.loads(str)
93
+ if isinstance(result, (dict, list)):
94
+ return result
95
+ except json.JSONDecodeError:
96
+ pass
97
+
98
+ # If all methods fail, raise ValueError
99
+ raise ValueError(f"Unable to parse as JSON: {json_string}")
100
+
101
+
76
102
  def repair_newlines(s: str) -> str:
77
103
  """
78
104
  Attempt to load as json, and if it fails, try with newlines replaced by space.
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Momento Vector Index.
3
3
  https://docs.momentohq.com/vector-index/develop/api-reference
4
+ DEPRECATED: API is unstable.
4
5
  """
5
6
 
6
7
  from __future__ import annotations
@@ -63,6 +63,7 @@ def is_valid_uuid(uuid_to_test: str) -> bool:
63
63
 
64
64
  class QdrantDBConfig(VectorStoreConfig):
65
65
  cloud: bool = True
66
+ docker: bool = False
66
67
  collection_name: str | None = "temp"
67
68
  storage_path: str = ".qdrant/data"
68
69
  embedding: EmbeddingModelsConfig = OpenAIEmbeddingsConfig()
@@ -102,7 +103,19 @@ class QdrantDB(VectorStore):
102
103
  load_dotenv()
103
104
  key = os.getenv("QDRANT_API_KEY")
104
105
  url = os.getenv("QDRANT_API_URL")
105
- if config.cloud and None in [key, url]:
106
+ if config.docker:
107
+ if url is None:
108
+ logger.warning(
109
+ f"""The QDRANT_API_URL env variable must be set to use
110
+ QdrantDB in local docker mode. Please set this
111
+ value in your .env file.
112
+ Switching to local storage at {config.storage_path}
113
+ """
114
+ )
115
+ config.cloud = False
116
+ else:
117
+ config.cloud = True
118
+ elif config.cloud and None in [key, url]:
106
119
  logger.warning(
107
120
  f"""QDRANT_API_KEY, QDRANT_API_URL env variable must be set to use
108
121
  QdrantDB in cloud mode. Please set these values
@@ -111,6 +124,7 @@ class QdrantDB(VectorStore):
111
124
  """
112
125
  )
113
126
  config.cloud = False
127
+
114
128
  if config.cloud:
115
129
  self.client = QdrantClient(
116
130
  url=url,
@@ -385,7 +399,7 @@ class QdrantDB(VectorStore):
385
399
  # Note the records may NOT be in the order of the ids,
386
400
  # so we re-order them here.
387
401
  id2payload = {record.id: record.payload for record in records}
388
- ordered_payloads = [id2payload[id] for id in _ids]
402
+ ordered_payloads = [id2payload[id] for id in _ids if id in id2payload]
389
403
  docs = [Document(**payload) for payload in ordered_payloads] # type: ignore
390
404
  return docs
391
405
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -59,7 +59,7 @@ Requires-Dist: litellm (>=1.30.1,<2.0.0) ; extra == "all" or extra == "litellm"
59
59
  Requires-Dist: lxml (>=4.9.3,<5.0.0)
60
60
  Requires-Dist: meilisearch-python-sdk (>=2.2.3,<3.0.0) ; extra == "meilisearch"
61
61
  Requires-Dist: metaphor-python (>=0.1.23,<0.2.0) ; extra == "all" or extra == "metaphor"
62
- Requires-Dist: momento (>=1.10.2,<2.0.0) ; extra == "momento"
62
+ Requires-Dist: momento (>=1.10.2,<1.21) ; extra == "momento"
63
63
  Requires-Dist: neo4j (>=5.14.1,<6.0.0) ; extra == "all" or extra == "neo4j"
64
64
  Requires-Dist: nest-asyncio (>=1.6.0,<2.0.0)
65
65
  Requires-Dist: nltk (>=3.8.1,<4.0.0)
@@ -235,6 +235,8 @@ teacher_task.run()
235
235
  <details>
236
236
  <summary> <b>Click to expand</b></summary>
237
237
 
238
+ - **Jul 2024:**
239
+ - **[0.3.0](https://github.com/langroid/langroid/releases/tag/0.3.0)**: Added [FastEmbed](https://qdrant.github.io/fastembed/qdrant/Usage_With_Qdrant/) embeddings from Qdrant
238
240
  - **Jun 2024:**
239
241
  - **0.2.0:** Improved lineage tracking, granular sub-task configs, and a new tool, `RewindTool`,
240
242
  that lets an agent "rewind and redo" a past message (and all dependent messages are cleared out
@@ -33,6 +33,7 @@ langroid/agent/special/sql/utils/system_message.py,sha256=qKLHkvQWRQodTtPLPxr1GS
33
33
  langroid/agent/special/sql/utils/tools.py,sha256=vFYysk6Vi7HJjII8B4RitA3pt_z3gkSglDNdhNVMiFc,1332
34
34
  langroid/agent/special/table_chat_agent.py,sha256=d9v2wsblaRx7oMnKhLV7uO_ujvk9gh59pSGvBXyeyNc,9659
35
35
  langroid/agent/task.py,sha256=vKM2dmRYSH4i_VA0lf2axUtZcTGU44rVHz6EyxI4kG0,73990
36
+ langroid/agent/team.py,sha256=88VNRSmK35WEl620GfBzuIrBASXYSeBZ8yDKX-nP_Bo,75778
36
37
  langroid/agent/tool_message.py,sha256=wIyZnUcZpxkiRPvM9O3MO3b5BBAdLEEan9kqPbvtApc,9743
37
38
  langroid/agent/tools/__init__.py,sha256=e-63cfwQNk_ftRKQwgDAJQK16QLbRVWDBILeXIc7wLk,402
38
39
  langroid/agent/tools/duckduckgo_search_tool.py,sha256=NhsCaGZkdv28nja7yveAhSK_w6l_Ftym8agbrdzqgfo,1935
@@ -63,11 +64,11 @@ langroid/embedding_models/protoc/embeddings_pb2_grpc.py,sha256=9dYQqkW3JPyBpSEje
63
64
  langroid/embedding_models/remote_embeds.py,sha256=6_kjXByVbqhY9cGwl9R83ZcYC2km-nGieNNAo1McHaY,5151
64
65
  langroid/exceptions.py,sha256=w_Cr41nPAmsa6gW5nNFaO9yDcBCWdQqRspL1jYvZf5w,2209
65
66
  langroid/language_models/__init__.py,sha256=1sUGobooTqq77XC7LxKsvME0RgSd5GGmeyrPo9SMh4U,940
66
- langroid/language_models/azure_openai.py,sha256=ncRCbKooqLVOY-PWQUIo9C3yTuKEFbAwyngXT_M4P7k,5989
67
- langroid/language_models/base.py,sha256=oAK2lXBqksMglqWqE2CjC03X3qPFXWgtjFWpH9hJ3C8,17500
67
+ langroid/language_models/azure_openai.py,sha256=G4le3j4YLHV7IwgB2C37hO3MKijZ1KjynbYlEvpIF7Y,6214
68
+ langroid/language_models/base.py,sha256=nhY-AdSkfqaW4hzeIekxxZs29AWLd7X7GYhRygU9L74,17527
68
69
  langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
69
70
  langroid/language_models/mock_lm.py,sha256=qdgj-wtbQBXlibo_0rIRfCt0hGTPRoxy1C4VjN6quI4,2707
70
- langroid/language_models/openai_gpt.py,sha256=84oXRT6hyY_MiavmRw61Jtw67xCmzBQEt5NKuqsxnQo,51680
71
+ langroid/language_models/openai_gpt.py,sha256=JOgENlOGBTg9r94hjvuqB2OteHRbX2JtMkrApoNu-jc,52257
71
72
  langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
72
73
  langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
73
74
  langroid/language_models/prompt_formatter/hf_formatter.py,sha256=TFL6ppmeQWnzr6CKQzRZFYY810zE1mr8DZnhw6i85ok,5217
@@ -82,7 +83,7 @@ langroid/parsing/config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
83
  langroid/parsing/document_parser.py,sha256=WGnA5ADwMHliGJt6WW9rc4RiFXQcKU33b5zdPiGrtEY,24265
83
84
  langroid/parsing/image_text.py,sha256=sbLIQ5nHe2UnYUksBaQsmZGaX-X0qgEpPd7CEzi_z5M,910
84
85
  langroid/parsing/para_sentence_split.py,sha256=AJBzZojP3zpB-_IMiiHismhqcvkrVBQ3ZINoQyx_bE4,2000
85
- langroid/parsing/parse_json.py,sha256=tgB_oatcrgt6L9ZplC-xBBXjLzL1gjSQf1L2_W5kwFA,4230
86
+ langroid/parsing/parse_json.py,sha256=Rcy0iCyMMICk2QstrlJtW7zDPs9lOZ3N_mlaJGWkC40,5033
86
87
  langroid/parsing/parser.py,sha256=AgtmlVUvrkSG1l7-YZPX8rlldgXjh_HqXAMqpXkBxUo,11746
87
88
  langroid/parsing/repo_loader.py,sha256=3GjvPJS6Vf5L6gV2zOU8s-Tf1oq_fZm-IB_RL_7CTsY,29373
88
89
  langroid/parsing/routing.py,sha256=-FcnlqldzL4ZoxuDwXjQPNHgBe9F9-F4R6q7b_z9CvI,1232
@@ -126,11 +127,11 @@ langroid/vector_store/base.py,sha256=tuEPaxJcuU_39sRnUjjNd8D8n8IjP6jrbwQv_ecNpSw
126
127
  langroid/vector_store/chromadb.py,sha256=bZ5HjwgKgfJj1PUHsatYsrHv-v0dpOfMR2l0tJ2H0_A,7890
127
128
  langroid/vector_store/lancedb.py,sha256=9x7e_5zo7nLhMbhjYby2ZpBJ-vyawcC0_XAuatfHJf8,20517
128
129
  langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3HmhHQICXLs,11663
129
- langroid/vector_store/momento.py,sha256=QaPzUnTwlswoawGB-paLtUPyLRvckFXLfLDfvbTzjNQ,10505
130
+ langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
130
131
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
131
- langroid/vector_store/qdrantdb.py,sha256=wYOuu5c2vIKn9ZgvTXcAiZXMpV8AOXEWFAzI8S8UP-0,16828
132
- pyproject.toml,sha256=gh7X6Y1IgIluL77xY0ejjIJMOIXBPw2-oLYcXUg01Ng,7054
133
- langroid-0.3.0.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
134
- langroid-0.3.0.dist-info/METADATA,sha256=MUh8_clSRdnwAFTiu8ESCAyXKNkFbU59uXvthr6r2CI,54210
135
- langroid-0.3.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
136
- langroid-0.3.0.dist-info/RECORD,,
132
+ langroid/vector_store/qdrantdb.py,sha256=HkcK6jOf-FEDoOiG94MpsYDJr98T7vZkDyG__1BlnWI,17354
133
+ pyproject.toml,sha256=x0YGXi9ennkubMYlFO-Eeyp6h2YE_aOBbeRJrUtTm34,7063
134
+ langroid-0.3.1.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
135
+ langroid-0.3.1.dist-info/METADATA,sha256=9WLpuCfOtRfjB30PZa2jwGmnlotxXRZgHqt6UWiNh4E,54402
136
+ langroid-0.3.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
137
+ langroid-0.3.1.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"
@@ -14,7 +14,7 @@ python = ">=3.10,<3.13"
14
14
 
15
15
  # =========== OPTIONALS ==============================
16
16
  chromadb = {version=">=0.4.21, <=0.4.23", optional=true}
17
- momento = {version="^1.10.2", optional=true}
17
+ momento = {version=">=1.10.2, < 1.21", optional=true}
18
18
  unstructured = {extras = ["docx", "pptx", "pdf"], version = ">=0.10.16,<0.10.18", optional=true}
19
19
  sentence-transformers = {version="^2.2.2", optional=true}
20
20
  torch = {version="^2.0.0", optional=true}