lm-deluge 0.0.49__py3-none-any.whl → 0.0.51__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.

Potentially problematic release.


This version of lm-deluge might be problematic. Click here for more details.

lm_deluge/tool.py CHANGED
@@ -1,14 +1,14 @@
1
1
  import asyncio
2
2
  import inspect
3
- from typing import Any, Callable, Coroutine, Literal, TypedDict, get_type_hints
4
3
  from concurrent.futures import ThreadPoolExecutor
4
+ from typing import Any, Callable, Coroutine, Literal, TypedDict, get_type_hints
5
5
 
6
6
  from fastmcp import Client # pip install fastmcp >= 2.0
7
7
  from mcp.types import Tool as MCPTool
8
8
  from pydantic import BaseModel, Field, field_validator
9
9
 
10
- from lm_deluge.prompt import Text, ToolResultPart
11
10
  from lm_deluge.image import Image
11
+ from lm_deluge.prompt import Text, ToolResultPart
12
12
 
13
13
 
14
14
  async def _load_all_mcp_tools(client: Client) -> list["Tool"]:
@@ -18,10 +18,14 @@ async def _load_all_mcp_tools(client: Client) -> list["Tool"]:
18
18
  async def _async_call(**kw):
19
19
  async with client:
20
20
  # maybe should be call_tool_mcp if don't want to raise error
21
- content_blocks = await client.call_tool(name, kw)
21
+ raw_result = await client.call_tool(name, kw)
22
22
 
23
23
  # for now just concatenate them all into a result string
24
24
  results = []
25
+ if not isinstance(raw_result, list): # newer versions of fastmcp
26
+ content_blocks = raw_result.content
27
+ else:
28
+ content_blocks = raw_result
25
29
  for block in content_blocks:
26
30
  if block.type == "text":
27
31
  results.append(Text(block.text))
@@ -54,14 +58,14 @@ class Tool(BaseModel):
54
58
  """
55
59
 
56
60
  name: str
57
- description: str | None
58
- parameters: dict[str, Any] | None
61
+ description: str | None = None
62
+ parameters: dict[str, Any] | None = None
59
63
  required: list[str] = Field(default_factory=list)
60
64
  additionalProperties: bool | None = None # only
61
65
  # if desired, can provide a callable to run the tool
62
66
  run: Callable | None = None
63
67
  # for built-in tools that don't require schema
64
- built_in: bool = False
68
+ is_built_in: bool = False
65
69
  type: str | None = None
66
70
  built_in_args: dict[str, Any] = Field(default_factory=dict)
67
71
 
@@ -305,7 +309,7 @@ class Tool(BaseModel):
305
309
  def for_openai_completions(
306
310
  self, *, strict: bool = True, **kwargs
307
311
  ) -> dict[str, Any]:
308
- if self.built_in:
312
+ if self.is_built_in:
309
313
  return {"type": self.type, **self.built_in_args, **kwargs}
310
314
  if strict:
311
315
  # For strict mode, remove defaults and make all parameters required
@@ -334,7 +338,7 @@ class Tool(BaseModel):
334
338
  return self.for_openai_completions(strict=strict, **kwargs)
335
339
 
336
340
  def for_openai_responses(self, **kwargs) -> dict[str, Any]:
337
- if self.built_in:
341
+ if self.is_built_in:
338
342
  return {"type": self.type, **self.built_in_args, **kwargs}
339
343
  return {
340
344
  "type": "function",
@@ -345,7 +349,7 @@ class Tool(BaseModel):
345
349
 
346
350
  def for_anthropic(self, **kwargs) -> dict[str, Any]:
347
351
  # built-in tools have "name", "type", maybe metadata
348
- if self.built_in:
352
+ if self.is_built_in:
349
353
  return {
350
354
  "name": self.name,
351
355
  "type": self.type,
@@ -388,6 +392,14 @@ class Tool(BaseModel):
388
392
  return self.for_google()
389
393
  raise ValueError(provider)
390
394
 
395
+ @classmethod
396
+ def built_in(cls, name: str, **kwargs):
397
+ if "type" in kwargs:
398
+ type = kwargs.pop("type")
399
+ else:
400
+ type = name
401
+ return cls(name=name, type=type, is_built_in=True, built_in_args=kwargs)
402
+
391
403
 
392
404
  class OpenAIMCPSpec(TypedDict):
393
405
  type: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lm_deluge
3
- Version: 0.0.49
3
+ Version: 0.0.51
4
4
  Summary: Python utility for using LLM API models.
5
5
  Author-email: Benjamin Anderson <ben@trytaylor.ai>
6
6
  Requires-Python: >=3.10
@@ -13,7 +13,7 @@ lm_deluge/image.py,sha256=5AMXmn2x47yXeYNfMSMAOWcnlrOxxOel-4L8QCJwU70,8928
13
13
  lm_deluge/prompt.py,sha256=2-6bALg_hOfExh9vHeKPFA6E_O8rHe6p9eIdvCulERs,59654
14
14
  lm_deluge/request_context.py,sha256=o33LSEwnK6YPhZeulUoSE_VrdKCXiCQa0tjjixK2K6M,2540
15
15
  lm_deluge/rerank.py,sha256=-NBAJdHz9OB-SWWJnHzkFmeVO4wR6lFV7Vw-SxG7aVo,11457
16
- lm_deluge/tool.py,sha256=_coOKB9nPNVZoseMRumRyQ8BMR7_d0IlstzMHNT69JY,15732
16
+ lm_deluge/tool.py,sha256=3weKo09E_srEKwHlz2WMVhk2BuDr5pJpi1UP0-qlcmo,16210
17
17
  lm_deluge/tracker.py,sha256=EHFPsS94NmsON2u97rSE70q1t6pwCsixUmGV-kIphMs,11531
18
18
  lm_deluge/usage.py,sha256=VMEKghePFIID5JFBObqYxFpgYxnbYm_dnHy7V1-_T6M,4866
19
19
  lm_deluge/api_requests/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
@@ -66,8 +66,8 @@ lm_deluge/util/logprobs.py,sha256=UkBZakOxWluaLqHrjARu7xnJ0uCHVfLGHJdnYlEcutk,11
66
66
  lm_deluge/util/spatial.py,sha256=BsF_UKhE-x0xBirc-bV1xSKZRTUhsOBdGqsMKme20C8,4099
67
67
  lm_deluge/util/validation.py,sha256=hz5dDb3ebvZrZhnaWxOxbNSVMI6nmaOODBkk0htAUhs,1575
68
68
  lm_deluge/util/xml.py,sha256=Ft4zajoYBJR3HHCt2oHwGfymGLdvp_gegVmJ-Wqk4Ck,10547
69
- lm_deluge-0.0.49.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
70
- lm_deluge-0.0.49.dist-info/METADATA,sha256=wxyjPS3Kf3XlXbO_Qc6RcmEWp7Lfe3La3tcDB_OH0_w,13443
71
- lm_deluge-0.0.49.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
72
- lm_deluge-0.0.49.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
73
- lm_deluge-0.0.49.dist-info/RECORD,,
69
+ lm_deluge-0.0.51.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
70
+ lm_deluge-0.0.51.dist-info/METADATA,sha256=sxR1kvdWYelDXwqSq0pIu3ZtQ8ejmNFQ7RWF36_KhRo,13443
71
+ lm_deluge-0.0.51.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
72
+ lm_deluge-0.0.51.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
73
+ lm_deluge-0.0.51.dist-info/RECORD,,