langroid 0.17.0__py3-none-any.whl → 0.18.0__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.
@@ -11,7 +11,7 @@ class XMLToolMessage(ToolMessage):
11
11
  Mainly tested for non-nested tool structures.
12
12
 
13
13
  When a subclass defines a field with the attribute `verbatim=True`,
14
- its value will be:
14
+ instructions are sent to the LLM to ensure the field's content is:
15
15
  - preserved as is, including whitespace, indents, quotes, newlines, etc
16
16
  with no escaping, and
17
17
  - enclosed in a CDATA section in the XML output.
@@ -19,6 +19,7 @@ class XMLToolMessage(ToolMessage):
19
19
  results can be far superior compared to sending code in JSON-formatted tools,
20
20
  where code needs to confirm to JSON's strict rules and escaping requirements.
21
21
  (see test_xml_tool_message.py for an example).
22
+
22
23
  """
23
24
 
24
25
  request: str
@@ -39,6 +39,10 @@ ToolTypes = Literal["function"]
39
39
 
40
40
 
41
41
  class LLMConfig(BaseSettings):
42
+ """
43
+ Common configuration for all language models.
44
+ """
45
+
42
46
  type: str = "openai"
43
47
  streamer: Optional[Callable[[Any], None]] = noop_fn
44
48
  api_base: str | None = None
@@ -48,6 +52,7 @@ class LLMConfig(BaseSettings):
48
52
  completion_model: str = ""
49
53
  temperature: float = 0.0
50
54
  chat_context_length: int = 8000
55
+ async_stream_quiet: bool = True # suppress streaming output in async mode?
51
56
  completion_context_length: int = 8000
52
57
  max_output_tokens: int = 1024 # generate at most this many tokens
53
58
  # if input length + max_output_tokens > context length of model,
@@ -149,6 +154,10 @@ class OpenAIToolSpec(BaseModel):
149
154
 
150
155
 
151
156
  class LLMTokenUsage(BaseModel):
157
+ """
158
+ Usage of tokens by an LLM.
159
+ """
160
+
152
161
  prompt_tokens: int = 0
153
162
  completion_tokens: int = 0
154
163
  cost: float = 0.0
@@ -173,6 +182,10 @@ class LLMTokenUsage(BaseModel):
173
182
 
174
183
 
175
184
  class Role(str, Enum):
185
+ """
186
+ Possible roles for a message in a chat.
187
+ """
188
+
176
189
  USER = "user"
177
190
  SYSTEM = "system"
178
191
  ASSISTANT = "assistant"
@@ -708,7 +708,7 @@ class OpenAIGPT(LanguageModel):
708
708
  event_args = ""
709
709
  event_fn_name = ""
710
710
  event_tool_deltas: Optional[List[Dict[str, Any]]] = None
711
-
711
+ silent = is_async and self.config.async_stream_quiet
712
712
  # The first two events in the stream of Azure OpenAI is useless.
713
713
  # In the 1st: choices list is empty, in the 2nd: the dict delta has null content
714
714
  if chat:
@@ -727,42 +727,40 @@ class OpenAIGPT(LanguageModel):
727
727
  event_text = choices[0]["text"]
728
728
  if event_text:
729
729
  completion += event_text
730
- if not is_async:
730
+ if not silent:
731
731
  sys.stdout.write(Colors().GREEN + event_text)
732
732
  sys.stdout.flush()
733
733
  self.config.streamer(event_text)
734
734
  if event_fn_name:
735
735
  function_name = event_fn_name
736
736
  has_function = True
737
- if not is_async:
737
+ if not silent:
738
738
  sys.stdout.write(Colors().GREEN + "FUNC: " + event_fn_name + ": ")
739
739
  sys.stdout.flush()
740
740
  self.config.streamer(event_fn_name)
741
741
 
742
742
  if event_args:
743
743
  function_args += event_args
744
- if not is_async:
744
+ if not silent:
745
745
  sys.stdout.write(Colors().GREEN + event_args)
746
746
  sys.stdout.flush()
747
747
  self.config.streamer(event_args)
748
748
 
749
- if event_tool_deltas is not None:
750
- # print out streaming tool calls
749
+ if event_tool_deltas is not None and not silent:
750
+ # print out streaming tool calls, if not async
751
751
  for td in event_tool_deltas:
752
752
  if td["function"]["name"] is not None:
753
753
  tool_fn_name = td["function"]["name"]
754
- if not is_async:
755
- sys.stdout.write(
756
- Colors().GREEN + "OAI-TOOL: " + tool_fn_name + ": "
757
- )
758
- sys.stdout.flush()
759
- self.config.streamer(tool_fn_name)
754
+ sys.stdout.write(
755
+ Colors().GREEN + "OAI-TOOL: " + tool_fn_name + ": "
756
+ )
757
+ sys.stdout.flush()
758
+ self.config.streamer(tool_fn_name)
760
759
  if td["function"]["arguments"] != "":
761
760
  tool_fn_args = td["function"]["arguments"]
762
- if not is_async:
763
- sys.stdout.write(Colors().GREEN + tool_fn_args)
764
- sys.stdout.flush()
765
- self.config.streamer(tool_fn_args)
761
+ sys.stdout.write(Colors().GREEN + tool_fn_args)
762
+ sys.stdout.flush()
763
+ self.config.streamer(tool_fn_args)
766
764
 
767
765
  # show this delta in the stream
768
766
  if choices[0].get("finish_reason", "") in [
@@ -872,6 +870,7 @@ class OpenAIGPT(LanguageModel):
872
870
  completion=completion,
873
871
  function_args=function_args,
874
872
  function_name=function_name,
873
+ is_async=True,
875
874
  )
876
875
  if is_break:
877
876
  break
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langroid
3
- Version: 0.17.0
3
+ Version: 0.18.0
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  License: MIT
6
6
  Author: Prasad Chalasani
@@ -244,7 +244,7 @@ teacher_task.run()
244
244
  <summary> <b>Click to expand</b></summary>
245
245
 
246
246
  - **Oct 2024:**
247
- - **[0.17.0]** XML-based tools, see [docs](https://langroid.github.io/langroid/tutorials/xml-tools/).
247
+ - **[0.17.0]** XML-based tools, see [docs](https://langroid.github.io/langroid/notes/xml-tools/).
248
248
  - **Sep 2024:**
249
249
  - **[0.16.0](https://github.com/langroid/langroid/releases/tag/0.16.0)** Support for OpenAI `o1-mini` and `o1-preview` models.
250
250
  - **[0.15.0](https://github.com/langroid/langroid/releases/tag/0.15.0)** Cerebras API support -- run llama-3.1 models hosted on Cerebras Cloud (very fast inference).
@@ -46,7 +46,7 @@ langroid/agent/tools/retrieval_tool.py,sha256=2q2pfoYbZNfbWQ0McxrtmfF0ekGglIgRl-
46
46
  langroid/agent/tools/rewind_tool.py,sha256=XAXL3BpNhCmBGYq_qi_sZfHJuIw7NY2jp4wnojJ7WRs,5606
47
47
  langroid/agent/tools/segment_extract_tool.py,sha256=__srZ_VGYLVOdPrITUM8S0HpmX4q7r5FHWMDdHdEv8w,1440
48
48
  langroid/agent/typed_task.py,sha256=oxja0Z3uLTv0BcR1xIMqDpo85MIGOruz4XsZ4ghjsW4,689
49
- langroid/agent/xml_tool_message.py,sha256=W4mjZlvizuYRDGOtttoIzJjfB8wRcV87nE8ZGfg_hqs,9043
49
+ langroid/agent/xml_tool_message.py,sha256=zNrtqSqfGuHJYw5qUq4LejjhoHcWdAoxbZYvm73KEtA,9092
50
50
  langroid/agent_config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
51
  langroid/cachedb/__init__.py,sha256=icAT2s7Vhf-ZGUeqpDQGNU6ob6o0aFEyjwcxxUGRFjg,225
52
52
  langroid/cachedb/base.py,sha256=ztVjB1DtN6pLCujCWnR6xruHxwVj3XkYniRTYAKKqk0,1354
@@ -67,10 +67,10 @@ langroid/language_models/.chainlit/config.toml,sha256=1t5lHORGzc2E6dkaO9P15jYHu2
67
67
  langroid/language_models/.chainlit/translations/en-US.json,sha256=DAFz2HjOFFfboCStrUfKFg2BpplJPK_OOtixwF_GivY,9931
68
68
  langroid/language_models/__init__.py,sha256=1sUGobooTqq77XC7LxKsvME0RgSd5GGmeyrPo9SMh4U,940
69
69
  langroid/language_models/azure_openai.py,sha256=G4le3j4YLHV7IwgB2C37hO3MKijZ1KjynbYlEvpIF7Y,6214
70
- langroid/language_models/base.py,sha256=3DjxxVL7heuTLYRvNMjaIKS-eP8pMDvu8Gbkb6N3B0U,22286
70
+ langroid/language_models/base.py,sha256=L02ToM7o1y5OlM23xYX8QbriRMVUodgwbnHodl3US28,22542
71
71
  langroid/language_models/config.py,sha256=9Q8wk5a7RQr8LGMT_0WkpjY8S4ywK06SalVRjXlfCiI,378
72
72
  langroid/language_models/mock_lm.py,sha256=HuiAvjHiCfffYF5xjFJUq945HVTW0QPbeUUctOnNCzQ,3868
73
- langroid/language_models/openai_gpt.py,sha256=haPcPe3CXAXpdU39rxGThObfv_YV0UivnL2hEdyyaHk,64810
73
+ langroid/language_models/openai_gpt.py,sha256=AlHg-jbf7PBFcS1iqb5z--upokDcWS7RJ4qpAmovsVw,64822
74
74
  langroid/language_models/prompt_formatter/__init__.py,sha256=2-5cdE24XoFDhifOLl8yiscohil1ogbP1ECkYdBlBsk,372
75
75
  langroid/language_models/prompt_formatter/base.py,sha256=eDS1sgRNZVnoajwV_ZIha6cba5Dt8xjgzdRbPITwx3Q,1221
76
76
  langroid/language_models/prompt_formatter/hf_formatter.py,sha256=PVJppmjRvD-2DF-XNC6mE05vTZ9wbu37SmXwZBQhad0,5055
@@ -137,8 +137,8 @@ langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3Hmh
137
137
  langroid/vector_store/momento.py,sha256=qR-zBF1RKVHQZPZQYW_7g-XpTwr46p8HJuYPCkfJbM4,10534
138
138
  langroid/vector_store/qdrant_cloud.py,sha256=3im4Mip0QXLkR6wiqVsjV1QvhSElfxdFSuDKddBDQ-4,188
139
139
  langroid/vector_store/qdrantdb.py,sha256=v88lqFkepADvlN6lByUj9I4NEKa9X9lWH16uTPPbYrE,17457
140
- pyproject.toml,sha256=olj3ishnFpF3nPogWJJYBDdduQUnRQiWD1qM08LKna0,7179
141
- langroid-0.17.0.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
142
- langroid-0.17.0.dist-info/METADATA,sha256=3PBPiOQIuduXHEPuZEqnPV3OjgnfIJpxc33dONV2GM0,56325
143
- langroid-0.17.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
144
- langroid-0.17.0.dist-info/RECORD,,
140
+ pyproject.toml,sha256=_fUfludVj9Fkhs0MdjEi28IBZ4S297bt-hUTh2rq-EE,7179
141
+ langroid-0.18.0.dist-info/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
142
+ langroid-0.18.0.dist-info/METADATA,sha256=H9JT8Ye5P9B8fL-8a_y6sQJvg4qWI1qmHR5I5fU089U,56321
143
+ langroid-0.18.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
144
+ langroid-0.18.0.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langroid"
3
- version = "0.17.0"
3
+ version = "0.18.0"
4
4
  description = "Harness LLMs with Multi-Agent Programming"
5
5
  authors = ["Prasad Chalasani <pchalasani@gmail.com>"]
6
6
  readme = "README.md"