langroid 0.1.176__tar.gz → 0.1.177__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 (116) hide show
  1. {langroid-0.1.176 → langroid-0.1.177}/PKG-INFO +3 -1
  2. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/neo4j/neo4j_chat_agent.py +4 -4
  3. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/table_chat_agent.py +28 -16
  4. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/task.py +5 -2
  5. langroid-0.1.177/langroid/agent/tools/metaphor_search_tool.py +44 -0
  6. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/openai_gpt.py +6 -4
  7. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/web_search.py +46 -0
  8. {langroid-0.1.176 → langroid-0.1.177}/pyproject.toml +3 -2
  9. {langroid-0.1.176 → langroid-0.1.177}/LICENSE +0 -0
  10. {langroid-0.1.176 → langroid-0.1.177}/README.md +0 -0
  11. {langroid-0.1.176 → langroid-0.1.177}/langroid/__init__.py +0 -0
  12. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/__init__.py +0 -0
  13. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/base.py +0 -0
  14. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/batch.py +0 -0
  15. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/chat_agent.py +0 -0
  16. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/chat_document.py +0 -0
  17. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/helpers.py +0 -0
  18. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/junk +0 -0
  19. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/openai_assistant.py +0 -0
  20. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/__init__.py +0 -0
  21. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/doc_chat_agent.py +0 -0
  22. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
  23. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/lance_rag/__init__.py +0 -0
  24. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
  25. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
  26. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/lance_rag/lance_tools.py +0 -0
  27. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
  28. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/neo4j/__init__.py +0 -0
  29. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/neo4j/utils/__init__.py +0 -0
  30. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/neo4j/utils/system_message.py +0 -0
  31. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/relevance_extractor_agent.py +0 -0
  32. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/retriever_agent.py +0 -0
  33. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/__init__.py +0 -0
  34. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/sql_chat_agent.py +0 -0
  35. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/utils/__init__.py +0 -0
  36. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
  37. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
  38. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/utils/system_message.py +0 -0
  39. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/special/sql/utils/tools.py +0 -0
  40. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tool_message.py +0 -0
  41. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/__init__.py +0 -0
  42. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/extract_tool.py +0 -0
  43. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/generator_tool.py +0 -0
  44. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/google_search_tool.py +0 -0
  45. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/recipient_tool.py +0 -0
  46. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/run_python_code.py +0 -0
  47. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/sciphi_search_rag_tool.py +0 -0
  48. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent/tools/segment_extract_tool.py +0 -0
  49. {langroid-0.1.176 → langroid-0.1.177}/langroid/agent_config.py +0 -0
  50. {langroid-0.1.176 → langroid-0.1.177}/langroid/cachedb/__init__.py +0 -0
  51. {langroid-0.1.176 → langroid-0.1.177}/langroid/cachedb/base.py +0 -0
  52. {langroid-0.1.176 → langroid-0.1.177}/langroid/cachedb/momento_cachedb.py +0 -0
  53. {langroid-0.1.176 → langroid-0.1.177}/langroid/cachedb/redis_cachedb.py +0 -0
  54. {langroid-0.1.176 → langroid-0.1.177}/langroid/embedding_models/__init__.py +0 -0
  55. {langroid-0.1.176 → langroid-0.1.177}/langroid/embedding_models/base.py +0 -0
  56. {langroid-0.1.176 → langroid-0.1.177}/langroid/embedding_models/clustering.py +0 -0
  57. {langroid-0.1.176 → langroid-0.1.177}/langroid/embedding_models/models.py +0 -0
  58. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/__init__.py +0 -0
  59. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/azure_openai.py +0 -0
  60. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/base.py +0 -0
  61. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/config.py +0 -0
  62. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/openai_assistants.py +0 -0
  63. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/prompt_formatter/__init__.py +0 -0
  64. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/prompt_formatter/base.py +0 -0
  65. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
  66. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
  67. {langroid-0.1.176 → langroid-0.1.177}/langroid/language_models/utils.py +0 -0
  68. {langroid-0.1.176 → langroid-0.1.177}/langroid/mytypes.py +0 -0
  69. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/__init__.py +0 -0
  70. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/agent_chats.py +0 -0
  71. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/code-parsing.md +0 -0
  72. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/code_parser.py +0 -0
  73. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/config.py +0 -0
  74. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/document_parser.py +0 -0
  75. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/json.py +0 -0
  76. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/para_sentence_split.py +0 -0
  77. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/parser.py +0 -0
  78. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/repo_loader.py +0 -0
  79. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/search.py +0 -0
  80. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/spider.py +0 -0
  81. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/table_loader.py +0 -0
  82. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/url_loader.py +0 -0
  83. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/url_loader_cookies.py +0 -0
  84. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/urls.py +0 -0
  85. {langroid-0.1.176 → langroid-0.1.177}/langroid/parsing/utils.py +0 -0
  86. {langroid-0.1.176 → langroid-0.1.177}/langroid/prompts/__init__.py +0 -0
  87. {langroid-0.1.176 → langroid-0.1.177}/langroid/prompts/dialog.py +0 -0
  88. {langroid-0.1.176 → langroid-0.1.177}/langroid/prompts/prompts_config.py +0 -0
  89. {langroid-0.1.176 → langroid-0.1.177}/langroid/prompts/templates.py +0 -0
  90. {langroid-0.1.176 → langroid-0.1.177}/langroid/prompts/transforms.py +0 -0
  91. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/__init__.py +0 -0
  92. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/algorithms/__init__.py +0 -0
  93. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/algorithms/graph.py +0 -0
  94. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/configuration.py +0 -0
  95. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/constants.py +0 -0
  96. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/docker.py +0 -0
  97. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/globals.py +0 -0
  98. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/llms/__init__.py +0 -0
  99. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/llms/strings.py +0 -0
  100. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/logging.py +0 -0
  101. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/output/__init__.py +0 -0
  102. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/output/printing.py +0 -0
  103. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/pandas_utils.py +0 -0
  104. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/pydantic_utils.py +0 -0
  105. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/system.py +0 -0
  106. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/web/__init__.py +0 -0
  107. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/web/login.py +0 -0
  108. {langroid-0.1.176 → langroid-0.1.177}/langroid/utils/web/selenium_login.py +0 -0
  109. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/__init__.py +0 -0
  110. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/base.py +0 -0
  111. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/chromadb.py +0 -0
  112. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/lancedb.py +0 -0
  113. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/meilisearch.py +0 -0
  114. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/momento.py +0 -0
  115. {langroid-0.1.176 → langroid-0.1.177}/langroid/vector_store/qdrant_cloud.py +0 -0
  116. {langroid-0.1.176 → langroid-0.1.177}/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.176
3
+ Version: 0.1.177
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Provides-Extra: hf-embeddings
14
14
  Provides-Extra: litellm
15
+ Provides-Extra: metaphor
15
16
  Provides-Extra: mysql
16
17
  Provides-Extra: neo4j
17
18
  Provides-Extra: postgres
@@ -38,6 +39,7 @@ Requires-Dist: litellm (>=1.0.0,<2.0.0) ; extra == "litellm"
38
39
  Requires-Dist: lxml (>=4.9.3,<5.0.0)
39
40
  Requires-Dist: meilisearch (>=0.28.3,<0.29.0)
40
41
  Requires-Dist: meilisearch-python-sdk (>=2.2.3,<3.0.0)
42
+ Requires-Dist: metaphor-python (>=0.1.23,<0.2.0) ; extra == "metaphor"
41
43
  Requires-Dist: mkdocs (>=1.4.2,<2.0.0)
42
44
  Requires-Dist: mkdocs-awesome-pages-plugin (>=2.8.0,<3.0.0)
43
45
  Requires-Dist: mkdocs-gen-files (>=0.4.0,<0.5.0)
@@ -146,10 +146,11 @@ class Neo4jChatAgent(ChatAgent):
146
146
  logger.error(f"Cypher Query failed: {query}\nException: {e}")
147
147
 
148
148
  # Construct the error message
149
- error_message_template = f"""\
149
+ error_message_template = f"""
150
+ There were some errors running your Cypher query:
150
151
  {NEO4J_ERROR_MSG}: '{query}'
151
152
  {str(e)}
152
- Run a new query, correcting the errors.
153
+ Send a new query, correcting the errors.
153
154
  """
154
155
 
155
156
  return error_message_template
@@ -168,7 +169,6 @@ class Neo4jChatAgent(ChatAgent):
168
169
  Returns:
169
170
  str: The result of executing the Cypher query.
170
171
  """
171
- response_message = ""
172
172
  if not self.driver:
173
173
  raise ValueError("No database connection is established.")
174
174
 
@@ -284,7 +284,7 @@ class Neo4jChatAgent(ChatAgent):
284
284
  return "The database schema does not have any nodes or relationships."
285
285
 
286
286
  def _init_tool_messages(self) -> None:
287
- """Initialize message tools used for chatting."""
287
+ """Attach ToolMessages to the Agent."""
288
288
  message = self._format_message()
289
289
  self.config.system_message = self.config.system_message.format(mode=message)
290
290
  super().__init__(self.config)
@@ -10,7 +10,7 @@ the code and returns the result as a string.
10
10
  import io
11
11
  import logging
12
12
  import sys
13
- from typing import List, no_type_check
13
+ from typing import List, Optional, no_type_check
14
14
 
15
15
  import numpy as np
16
16
  import pandas as pd
@@ -23,7 +23,7 @@ from langroid.agent.tool_message import ToolMessage
23
23
  from langroid.language_models.openai_gpt import OpenAIChatModel, OpenAIGPTConfig
24
24
  from langroid.parsing.table_loader import read_tabular_data
25
25
  from langroid.prompts.prompts_config import PromptsConfig
26
- from langroid.utils.constants import DONE, PASS
26
+ from langroid.utils.constants import DONE
27
27
  from langroid.vector_store.base import VectorStoreConfig
28
28
 
29
29
  logger = logging.getLogger(__name__)
@@ -34,7 +34,7 @@ DEFAULT_TABLE_CHAT_SYSTEM_MESSAGE = f"""
34
34
  You are a savvy data scientist, with expertise in analyzing tabular datasets,
35
35
  using Python and the Pandas library for dataframe manipulation.
36
36
  Since you do not have access to the dataframe 'df', you
37
- will need to use the `run_code` tool/function-call to answer the question.
37
+ will need to use the `run_code` tool/function-call to answer my questions.
38
38
  Here is a summary of the dataframe:
39
39
  {{summary}}
40
40
  Do not assume any columns other than those shown.
@@ -48,9 +48,9 @@ If you receive a null or other unexpected result, see if you have made an assump
48
48
  in your code, and try another way, or use `run_code` to explore the dataframe
49
49
  before submitting your final code.
50
50
 
51
- Once you have the answer to the question, say {DONE} and show me the answer.
52
- If you receive an error message, try using the `run_code` tool/function
53
- again with the corrected code.
51
+ Once you have the answer to the question, possibly after a few steps,
52
+ say {DONE} and show me the answer. If you receive an error message,
53
+ try using the `run_code` tool/function again with the corrected code.
54
54
 
55
55
  VERY IMPORTANT: When using the `run_code` tool/function, DO NOT EXPLAIN ANYTHING,
56
56
  SIMPLY USE THE TOOL, with the CODE.
@@ -129,6 +129,7 @@ class RunCodeTool(ToolMessage):
129
129
  purpose: str = """
130
130
  To run <code> on the dataframe 'df' and
131
131
  return the results to answer a question.
132
+ IMPORTANT: ALL the code should be in the <code> field.
132
133
  """
133
134
  code: str
134
135
 
@@ -145,6 +146,8 @@ class TableChatAgent(ChatAgent):
145
146
  Agent for chatting with a collection of documents.
146
147
  """
147
148
 
149
+ sent_code: bool = False
150
+
148
151
  def __init__(self, config: TableChatAgentConfig):
149
152
  if isinstance(config.data, pd.DataFrame):
150
153
  df = config.data
@@ -169,6 +172,15 @@ class TableChatAgent(ChatAgent):
169
172
  # enable the agent to use and handle the RunCodeTool
170
173
  self.enable_message(RunCodeTool)
171
174
 
175
+ def user_response(
176
+ self,
177
+ msg: Optional[str | ChatDocument] = None,
178
+ ) -> Optional[ChatDocument]:
179
+ response = super().user_response(msg)
180
+ if response is not None and response.content != "":
181
+ self.sent_code = False
182
+ return response
183
+
172
184
  def run_code(self, msg: RunCodeTool) -> str:
173
185
  """
174
186
  Handle a RunCodeTool message by running the code and returning the result.
@@ -178,6 +190,7 @@ class TableChatAgent(ChatAgent):
178
190
  Returns:
179
191
  str: The result of running the code along with any print output.
180
192
  """
193
+ self.sent_code = True
181
194
  code = msg.code
182
195
  # Create a dictionary that maps 'df' to the actual DataFrame
183
196
  local_vars = {"df": self.df}
@@ -230,14 +243,13 @@ class TableChatAgent(ChatAgent):
230
243
  ) -> str | ChatDocument | None:
231
244
  """Handle scenario where LLM forgets to say DONE or forgets to use run_code"""
232
245
  if isinstance(msg, ChatDocument) and msg.metadata.sender == lr.Entity.LLM:
233
- return f"""
234
- You either:
235
-
236
- (A) forgot to use the `run_code` tool/function to find the answer,
237
- ==> In this case re-try using the `run_code` tool/function.
238
- OR
239
-
240
- (B) forgot to say {DONE} after you found the answer.
241
- ==> In this case say "{DONE} {PASS}"
242
- """
246
+ if self.sent_code:
247
+ return DONE
248
+ else:
249
+ return """
250
+ You forgot to use the `run_code` tool/function to find the answer.
251
+ Try again using the `run_code` tool/function.
252
+ Remember that ALL your code, including imports,
253
+ should be in the `code` field.
254
+ """
243
255
  return None
@@ -160,6 +160,8 @@ class Task:
160
160
  self.name = name or agent.config.name
161
161
  self.value: str = self.name
162
162
  self.default_human_response = default_human_response
163
+ if default_human_response is not None and default_human_response == "":
164
+ interactive = False
163
165
  self.interactive = interactive
164
166
  self.message_history_idx = -1
165
167
  if interactive:
@@ -957,8 +959,6 @@ class Task:
957
959
  bool: True if task is done, False otherwise
958
960
  """
959
961
  result = result or self.pending_message
960
- if self.is_done:
961
- return True
962
962
  user_quit = (
963
963
  result is not None
964
964
  and result.content in USER_QUIT
@@ -968,6 +968,9 @@ class Task:
968
968
  # for top-level task, only user can quit out
969
969
  return user_quit
970
970
 
971
+ if self.is_done:
972
+ return True
973
+
971
974
  if self.n_stalled_steps >= self.max_stalled_steps:
972
975
  # we are stuck, so bail to avoid infinite loop
973
976
  logger.warning(
@@ -0,0 +1,44 @@
1
+ """
2
+ A tool to trigger a metaphor search for a given query, and return the top results with
3
+ their titles, links, summaries. Since the tool is stateless (i.e. does not need
4
+ access to agent state), it can be enabled for any agent, without having to define a
5
+ special method inside the agent: `agent.enable_message(MetaphorSearchTool)`
6
+
7
+ NOTE: Using this tool requires setting the METAPHOR_API_KEY environment variables in
8
+ your `.env` file, as explained in the
9
+ [README](https://github.com/langroid/langroid#gear-installation-and-setup).
10
+
11
+ This tool requires installing langroid with the `metaphor` extra, e.g.
12
+ `pip install langroid[metaphor]` or `poetry add langroid[metaphor]`
13
+ (it installs the `metaphor-python` package from pypi).
14
+
15
+ For more information, please refer to the official docs:
16
+ https://metaphor.systems/
17
+ """
18
+
19
+ from langroid.agent.tool_message import ToolMessage
20
+ from langroid.parsing.web_search import metaphor_search
21
+
22
+
23
+ class MetaphorSearchTool(ToolMessage):
24
+ request: str = "metaphor_search"
25
+ purpose: str = """
26
+ To search the web by metaphor api and return up to <num_results>
27
+ links relevant to the given <query>.
28
+ """
29
+ query: str
30
+ num_results: int
31
+
32
+ def handle(self) -> str:
33
+ """
34
+ Conducts a search using the metaphor API based on the provided query
35
+ and number of results by triggering a metaphor_search.
36
+
37
+ Returns:
38
+ str: A formatted string containing the titles, links, and
39
+ summaries of each search result, separated by two newlines.
40
+ """
41
+
42
+ search_results = metaphor_search(self.query, self.num_results)
43
+ # return Title, Link, Summary of each result, separated by two newlines
44
+ return "\n\n".join(str(result) for result in search_results)
@@ -60,7 +60,8 @@ class OpenAIChatModel(str, Enum):
60
60
 
61
61
  GPT3_5_TURBO = "gpt-3.5-turbo-1106"
62
62
  GPT4 = "gpt-4"
63
- GPT4_TURBO = "gpt-4-1106-preview"
63
+ GPT4_32K = "gpt-4-32k"
64
+ GPT4_TURBO = "gpt-4-turbo-preview"
64
65
 
65
66
 
66
67
  class OpenAICompletionModel(str, Enum):
@@ -72,8 +73,9 @@ class OpenAICompletionModel(str, Enum):
72
73
 
73
74
  _context_length: Dict[str, int] = {
74
75
  # can add other non-openAI models here
75
- OpenAIChatModel.GPT3_5_TURBO: 4096,
76
+ OpenAIChatModel.GPT3_5_TURBO: 16_385,
76
77
  OpenAIChatModel.GPT4: 8192,
78
+ OpenAIChatModel.GPT4_32K: 32_768,
77
79
  OpenAIChatModel.GPT4_TURBO: 128_000,
78
80
  OpenAICompletionModel.TEXT_DA_VINCI_003: 4096,
79
81
  }
@@ -81,7 +83,7 @@ _context_length: Dict[str, int] = {
81
83
  _cost_per_1k_tokens: Dict[str, Tuple[float, float]] = {
82
84
  # can add other non-openAI models here.
83
85
  # model => (prompt cost, generation cost) in USD
84
- OpenAIChatModel.GPT3_5_TURBO: (0.0015, 0.002),
86
+ OpenAIChatModel.GPT3_5_TURBO: (0.001, 0.002),
85
87
  OpenAIChatModel.GPT4: (0.03, 0.06), # 8K context
86
88
  OpenAIChatModel.GPT4_TURBO: (0.01, 0.03), # 128K context
87
89
  }
@@ -197,7 +199,7 @@ class OpenAIGPTConfig(LLMConfig):
197
199
  api_base: str | None = None # used for local or other non-OpenAI models
198
200
  litellm: bool = False # use litellm api?
199
201
  max_output_tokens: int = 1024
200
- min_output_tokens: int = 64
202
+ min_output_tokens: int = 1
201
203
  use_chat_for_completion = True # do not change this, for OpenAI models!
202
204
  timeout: int = 20
203
205
  temperature: float = 0.2
@@ -77,3 +77,49 @@ def google_search(query: str, num_results: int = 5) -> List[WebSearchResult]:
77
77
  WebSearchResult(result["title"], result["link"], 3500, 300)
78
78
  for result in raw_results
79
79
  ]
80
+
81
+
82
+ def metaphor_search(query: str, num_results: int = 5) -> List[WebSearchResult]:
83
+ """
84
+ Method that makes an API call by Metaphor client that queries
85
+ the top num_results links that matches the query. Returns a list
86
+ of WebSearchResult objects.
87
+
88
+ Args:
89
+ query (str): The query body that users wants to make.
90
+ num_results (int): Number of top matching results that we want
91
+ to grab
92
+ """
93
+
94
+ load_dotenv()
95
+
96
+ api_key = os.getenv("METAPHOR_API_KEY")
97
+ if not api_key:
98
+ raise ValueError(
99
+ """
100
+ METAPHOR_API_KEY is not set.
101
+ Please set the METAPHOR_API_KEY environment variable.
102
+ """
103
+ )
104
+
105
+ try:
106
+ from metaphor_python import Metaphor
107
+ except ImportError:
108
+ raise ImportError(
109
+ "You are attempting to use the `metaphor_python` library;"
110
+ "To use it, please install langroid with the `metaphor` extra, e.g. "
111
+ "`pip install langroid[metaphor]` or `poetry add langroid[metaphor]` "
112
+ "(it installs the `metaphor_python` package from pypi)."
113
+ )
114
+
115
+ client = Metaphor(api_key=api_key)
116
+
117
+ response = client.search(
118
+ query=query,
119
+ num_results=num_results,
120
+ )
121
+ raw_results = response.results
122
+
123
+ return [
124
+ WebSearchResult(result.title, result.url, 3500, 300) for result in raw_results
125
+ ]
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.1.176"
3
+ version = "0.1.177"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"
@@ -85,6 +85,7 @@ neo4j = {version = "^5.14.1", optional = true}
85
85
  agent-search = {version = "^0.0.7", optional = true}
86
86
  python-docx = "^1.1.0"
87
87
  aiohttp = "^3.9.1"
88
+ metaphor-python = {version = "^0.1.23", optional = true}
88
89
 
89
90
  [tool.poetry.extras]
90
91
  # install these using `poetry install -E [...]` where [...] is one of the extras below
@@ -94,7 +95,7 @@ mysql = ["pymysql", "pytest-mysql"]
94
95
  litellm = ["litellm"]
95
96
  neo4j = ["neo4j"]
96
97
  sciphi = ["agent-search"]
97
-
98
+ metaphor = ["metaphor-python"]
98
99
 
99
100
  [tool.poetry.group.dev.dependencies]
100
101
  pytest = "^7.3.1"
File without changes
File without changes