langroid 0.1.133__py3-none-any.whl → 0.1.134__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.
langroid/agent/base.py CHANGED
@@ -143,6 +143,9 @@ class Agent(ABC):
143
143
  def get_dialog(self) -> List[Tuple[str, str]]:
144
144
  return self.dialog
145
145
 
146
+ def clear_dialog(self) -> None:
147
+ self.dialog = []
148
+
146
149
  def _get_tool_list(
147
150
  self, message_class: Optional[Type[ToolMessage]] = None
148
151
  ) -> List[str]:
langroid/agent/task.py CHANGED
@@ -100,6 +100,7 @@ class Task:
100
100
  if isinstance(agent, ChatAgent) and len(agent.message_history) == 0 or restart:
101
101
  agent = cast(ChatAgent, agent)
102
102
  agent.clear_history(0)
103
+ agent.clear_dialog()
103
104
  # possibly change the system and user messages
104
105
  if system_message:
105
106
  # we always have at least 1 task_message
@@ -1,6 +1,6 @@
1
1
  import logging
2
2
  from enum import Enum
3
- from typing import List
3
+ from typing import Dict, List
4
4
 
5
5
  import tiktoken
6
6
  from pydantic import BaseSettings
@@ -57,22 +57,34 @@ class Parser:
57
57
 
58
58
  # The original metadata.id (if any) is ignored since it will be same for all
59
59
  # chunks and is useless. We want a distinct id for each chunk.
60
+ orig_ids = [c.metadata.id for c in chunks]
60
61
  ids = [Document.hash_id(str(c)) for c in chunks]
61
62
 
63
+ # group the ids by orig_id
64
+ orig_id_to_ids: Dict[str, List[str]] = {}
65
+ for orig_id, id in zip(orig_ids, ids):
66
+ if orig_id not in orig_id_to_ids:
67
+ orig_id_to_ids[orig_id] = [] # type: ignore
68
+ orig_id_to_ids[orig_id].append(id) # type: ignore
69
+
70
+ # now each orig_id maps to a sequence of ids within a single doc
71
+
62
72
  k = self.config.n_neighbor_ids
63
- n = len(ids)
64
- window_ids = [ids[max(0, i - k) : min(n, i + k + 1)] for i in range(n)]
65
- for i, c in enumerate(chunks):
66
- if c.content.strip() == "":
67
- continue
68
- c.metadata.window_ids = window_ids[i]
69
- c.metadata.id = ids[i]
70
- c.metadata.is_chunk = True
73
+ for orig, ids in orig_id_to_ids.items():
74
+ n = len(ids)
75
+ window_ids = [ids[max(0, i - k) : min(n, i + k + 1)] for i in range(n)]
76
+ for i, c in enumerate(chunks):
77
+ if c.content.strip() == "":
78
+ continue
79
+ c.metadata.window_ids = window_ids[i]
80
+ c.metadata.id = ids[i]
81
+ c.metadata.is_chunk = True
71
82
 
72
83
  def split_simple(self, docs: List[Document]) -> List[Document]:
73
84
  if len(self.config.separators) == 0:
74
85
  raise ValueError("Must have at least one separator")
75
86
  final_docs = []
87
+
76
88
  for d in docs:
77
89
  if d.content.strip() == "":
78
90
  continue
@@ -240,6 +252,11 @@ class Parser:
240
252
  def split(self, docs: List[Document]) -> List[Document]:
241
253
  if len(docs) == 0:
242
254
  return []
255
+ # create ids in metadata of docs if absent:
256
+ # we need this to distinguish docs later in add_window_ids
257
+ for d in docs:
258
+ if d.metadata.id is None:
259
+ d.metadata.id = d.id()
243
260
  # some docs are already splits, so don't split them further!
244
261
  chunked_docs = [d for d in docs if d.metadata.is_chunk]
245
262
  big_docs = [d for d in docs if not d.metadata.is_chunk]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.1.133
3
+ Version: 0.1.134
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -100,7 +100,7 @@ Description-Content-Type: text/markdown
100
100
  [![Multi-Architecture DockerHub](https://github.com/langroid/langroid/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/langroid/langroid/actions/workflows/docker-publish.yml)
101
101
 
102
102
  [![Static Badge](https://img.shields.io/badge/Documentation-blue?link=https%3A%2F%2Flangroid.github.io%2Flangroid%2F&link=https%3A%2F%2Flangroid.github.io%2Flangroid%2F)](https://langroid.github.io/langroid)
103
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/langroid_quick_examples.ipynb)
103
+ [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/Langroid_quick_start.ipynb)
104
104
  [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=flat&logo=discord&logoColor=white)](https://discord.gg/ZU36McDgDs)
105
105
  [![Substack](https://img.shields.io/badge/Substack-%23006f5c.svg?style=flat&logo=substack&logoColor=FF6719)](https://langroid.substack.com/p/langroid-harness-llms-with-multi-agent-programming)
106
106
  </div>
@@ -138,7 +138,7 @@ We welcome contributions -- See the [contributions](./CONTRIBUTING.md) document
138
138
  for ideas on what to contribute.
139
139
 
140
140
 
141
- Building LLM Applications? Prasad Chalasani is available for consulting
141
+ Building LLM Applications? [Prasad Chalasani](https://www.linkedin.com/in/pchalasani/) is available for consulting
142
142
  (advisory/development): pchalasani at gmail dot com.
143
143
 
144
144
  Sponsorship is also accepted via [GitHub Sponsors](https://github.com/sponsors/langroid)
@@ -148,12 +148,12 @@ Sponsorship is also accepted via [GitHub Sponsors](https://github.com/sponsors/l
148
148
  # Quick glimpse of coding with Langroid
149
149
  This is just a teaser; there's much more, like function-calling/tools,
150
150
  Multi-Agent Collaboration, Structured Information Extraction, DocChatAgent
151
- (RAG), SQLChatAgent, etc. Scroll down or see docs for more.
152
-
153
- :fire: Just released! See this [Colab](https://colab.research.google.com/drive/190Tk7t4AdY1P9F_NlZ33-YEoGnHweQQ0)
154
- for a walk-through of the new `OpenAIAssistant` class (with near-complete support for the new OpenAI Assistants API)
155
- in a multi-agent setting.
151
+ (RAG), SQLChatAgent, non-OpenAI local/remote LLMs, etc. Scroll down or see docs for more.
156
152
 
153
+ :fire: Just released! Updated Langroid Quick-Start [Colab](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/Langroid_quick_start.ipynb)
154
+ that builds up to a 2-agent chat example using the OpenAI ChatCompletion API.
155
+ See also this [version](https://colab.research.google.com/drive/190Tk7t4AdY1P9F_NlZ33-YEoGnHweQQ0)
156
+ that uses the OpenAI Assistants API instead.
157
157
 
158
158
  ```python
159
159
  from langroid.language_models import OpenAIGPTConfig, OpenAIChatModel, OpenAIGPT
@@ -264,7 +264,7 @@ See [this test](tests/main/test_recipient_tool.py) for example usage.
264
264
  - **Example:** [Answer questions](examples/docqa/chat-search.py) using Google Search + vecdb-retrieval from URL contents.
265
265
  - **0.1.39:** [`GoogleSearchTool`](langroid/agent/tools/google_search_tool.py) to enable Agents (their LLM) to do Google searches via function-calling/tools.
266
266
  See [this chat example](examples/basic/chat-search.py) for how easy it is to add this tool to an agent.
267
- - **Colab notebook** to try the quick-start examples: [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/langroid_quick_examples.ipynb)
267
+ - **Colab notebook** to try the quick-start examples: [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/Langroid_quick_start.ipynb)
268
268
  - **0.1.37:** Added [`SQLChatAgent`](langroid/agent/special/sql_chat_agent.py) -- thanks to our latest contributor [Rithwik Babu](https://github.com/rithwikbabu)!
269
269
  - Multi-agent Example: [Autocorrect chat](examples/basic/autocorrect.py)
270
270
  - **July 2023:**
@@ -515,7 +515,7 @@ for a detailed tutorial.
515
515
 
516
516
  Click to expand any of the code examples below.
517
517
  All of these can be run in a Colab notebook:
518
- [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/langroid_quick_examples.ipynb)
518
+ [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langroid/langroid/blob/main/examples/Langroid_quick_start.ipynb)
519
519
 
520
520
  <details>
521
521
  <summary> <b> Direct interaction with OpenAI LLM </b> </summary>
@@ -1,6 +1,6 @@
1
1
  langroid/__init__.py,sha256=-AWkFhhW0b0paHQ11SORyIVPnXv0nyT2X_0_xh3zLjw,408
2
2
  langroid/agent/__init__.py,sha256=ZqDw3Ktw7XGDl6mC8DN61F71V4ckf0rBoEOydH9l6C4,428
3
- langroid/agent/base.py,sha256=Q3xVpOuE85LjkLKvM32pBjTiViyJQSpadQ7-U08cRMo,31869
3
+ langroid/agent/base.py,sha256=-VWT3gQWgH_uGjVILLPosa5WebzZihVY_JOi_bYYNEQ,31931
4
4
  langroid/agent/batch.py,sha256=Cg7Qv1yGi_M9rMl38_4-hjXPsoLlZrOSXDhbOFqUcKY,5593
5
5
  langroid/agent/chat_agent.py,sha256=if0wV75i8I2roNpeq-4PxSxH6bwJjhxVnm61SvNy_m0,35026
6
6
  langroid/agent/chat_document.py,sha256=dw0m_00qJgOhbzCkEsVBAiktM6BJ62mV8_piu5GruXM,7008
@@ -20,7 +20,7 @@ langroid/agent/special/sql/utils/populate_metadata.py,sha256=zRjw31a1ZXvpx9bcmbt
20
20
  langroid/agent/special/sql/utils/system_message.py,sha256=qKLHkvQWRQodTtPLPxr1GSLUYUFASZU8x-ybV67cB68,1885
21
21
  langroid/agent/special/sql/utils/tools.py,sha256=6uB2424SLtmapui9ggcEr0ZTiB6_dL1-JRGgN8RK9Js,1332
22
22
  langroid/agent/special/table_chat_agent.py,sha256=zejrvv6GaspImVJ1oXWUTVN-h-kDjadTdBDkTRqrYKo,7691
23
- langroid/agent/task.py,sha256=bllafGA9AbVaeL6qk1a-1Wa2sc6fsuzeNEyhKHav3K8,36260
23
+ langroid/agent/task.py,sha256=lMn8zffp0HlA9aLfw8UrWWd8Ni5jbIuCj2COBThBk2U,36293
24
24
  langroid/agent/tool_message.py,sha256=_QS9_JnBdMBmpQw-ocu3PdJz_UzkFCytVky0UdIcMe0,6320
25
25
  langroid/agent/tools/__init__.py,sha256=6le5y_iPEHwh7Tli_0MtwCGOjy3tPQfAdfDC7WBg2e0,172
26
26
  langroid/agent/tools/extract_tool.py,sha256=u5lL9rKBzaLBOrRyLnTAZ97pQ1uxyLP39XsWMnpaZpw,3789
@@ -57,7 +57,7 @@ langroid/parsing/config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  langroid/parsing/document_parser.py,sha256=YC3IXQ9ErpBGBZh6Be9gfJWHcTwGTSMfNQMT5ARrj5g,14615
58
58
  langroid/parsing/json.py,sha256=MVqBUfInALQm1QKbcfEvLzWxBz_UztCIyGk7AK5uFPo,1650
59
59
  langroid/parsing/para_sentence_split.py,sha256=AJBzZojP3zpB-_IMiiHismhqcvkrVBQ3ZINoQyx_bE4,2000
60
- langroid/parsing/parser.py,sha256=kQY6pqToc_x2a96ElrcK2vA3cX9t4KN4c20WTRHPh9A,9297
60
+ langroid/parsing/parser.py,sha256=HU8d8wzzo2rSX2tJFYVLbf_gZ3qtz6goDkctdkNHuzw,10032
61
61
  langroid/parsing/repo_loader.py,sha256=4qCyRRHCKIYd8F1ghT-D8ko1C2sXpF7UYP1L5Im1hRE,27705
62
62
  langroid/parsing/search.py,sha256=xmQdAdTIwZ0REEUeQVFlGZlqf7k8Poah7-ALuyW7Ov0,8440
63
63
  langroid/parsing/spider.py,sha256=w_mHR1B4KOmxsBLoVI8kMkMTEbwTzeK3ath9fOMJrTk,3043
@@ -97,7 +97,7 @@ langroid/vector_store/meilisearch.py,sha256=h4e1MZJ9J3EnFfcUhLshK1Duwy1dpHWH4Ajt
97
97
  langroid/vector_store/momento.py,sha256=otoUrpgwEduFOCUhbFFSZWKEzWF2di1d4-m3n5PIuHI,9964
98
98
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
99
99
  langroid/vector_store/qdrantdb.py,sha256=ZEJnlNIJwWIySGhPz3jBc6spcLCPqOcUDBYBisLF90I,11379
100
- langroid-0.1.133.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
101
- langroid-0.1.133.dist-info/METADATA,sha256=xYZstplklmIMJtwIkpDrUMT_agwXItOwPoUtgp8juoQ,42453
102
- langroid-0.1.133.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
103
- langroid-0.1.133.dist-info/RECORD,,
100
+ langroid-0.1.134.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
101
+ langroid-0.1.134.dist-info/METADATA,sha256=IJPjs9SDcsyMwSqS5yWg0N4vPpxHEJzwzHTqlMaiSvI,42646
102
+ langroid-0.1.134.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
103
+ langroid-0.1.134.dist-info/RECORD,,