stores 0.1.7.dev2__py3-none-any.whl → 0.1.7.dev4__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.
@@ -151,8 +151,14 @@ def get_tool_signature(
151
151
  tool_name = tool_id.split(".")[-1]
152
152
  env_var = env_var or {}
153
153
 
154
+ # We use sockets to pass pass function metadata
155
+ listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
156
+ listener.bind(("localhost", 0))
157
+ listener.listen(1)
158
+ _, port = listener.getsockname()
159
+
154
160
  runner = f"""
155
- import pickle, sys, traceback, inspect, enum
161
+ import pickle, sys, traceback, inspect, enum, socket
156
162
  from typing import Any, Dict, List, Literal, Tuple, Union, get_args, get_origin, get_type_hints
157
163
  import types as T
158
164
 
@@ -206,8 +212,9 @@ def extract_type_info(typ, custom_types: list[str] | None = None):
206
212
 
207
213
  try:
208
214
  from {module_name} import {tool_name}
209
- sig = inspect.signature({tool_name})
210
- hints = get_type_hints({tool_name})
215
+ func = {tool_name}
216
+ sig = inspect.signature(func)
217
+ hints = get_type_hints(func)
211
218
  params = {{}}
212
219
  for name, param in sig.parameters.items():
213
220
  hint = hints.get(name, param.annotation)
@@ -218,33 +225,44 @@ try:
218
225
  return_type = hints.get('return', sig.return_annotation)
219
226
  return_info = extract_type_info(return_type)
220
227
 
221
- pickle.dump(
222
- {{
223
- "ok": True,
224
- "result": {{
225
- "tool_id": "{tool_id}",
226
- "params": params,
227
- "return": return_info,
228
- "iscoroutinefunction": inspect.iscoroutinefunction({tool_name}),
229
- "isgeneratorfunction": inspect.isgeneratorfunction({tool_name}),
230
- "isasyncgenfunction": inspect.isasyncgenfunction({tool_name}),
231
- "doc": inspect.getdoc({tool_name}),
232
- }},
228
+ payload = {{
229
+ "ok": True,
230
+ "result": {{
231
+ "tool_id": "{tool_id}",
232
+ "params": params,
233
+ "return": return_info,
234
+ "iscoroutinefunction": inspect.iscoroutinefunction(func),
235
+ "isgeneratorfunction": inspect.isgeneratorfunction(func),
236
+ "isasyncgenfunction": inspect.isasyncgenfunction(func),
237
+ "doc": inspect.getdoc(func),
233
238
  }},
234
- sys.stdout.buffer,
235
- )
239
+ }}
236
240
  except Exception as e:
237
- err = traceback.format_exc()
238
- pickle.dump({{"ok": False, "error": err}}, sys.stdout.buffer)
241
+ payload = {{"ok": False, "error": traceback.format_exc()}}
242
+
243
+ with socket.create_connection(("localhost", {port})) as s:
244
+ s.sendall(pickle.dumps(payload))
239
245
  """
240
- result = subprocess.run(
246
+ proc = subprocess.Popen(
241
247
  [get_python_command(Path(index_folder) / venv), "-c", runner],
242
- capture_output=True,
243
248
  cwd=index_folder,
244
249
  env=env_var or None,
245
250
  )
251
+
252
+ conn, _ = listener.accept()
253
+ with conn:
254
+ data = b""
255
+ while True:
256
+ chunk = conn.recv(4096)
257
+ if not chunk:
258
+ break
259
+ data += chunk
260
+
261
+ listener.close()
262
+ proc.wait()
263
+
246
264
  try:
247
- response = pickle.loads(result.stdout)
265
+ response = pickle.loads(data)
248
266
  except ModuleNotFoundError as e:
249
267
  raise RuntimeError(
250
268
  f"Error loading tool {tool_id}:\nThe tool most likely has a parameter of a custom type that cannot be exported"
@@ -462,7 +480,7 @@ def run_remote_tool(
462
480
  conn.close()
463
481
 
464
482
  if not stream:
465
- thread = threading.Thread(target=lambda: list(handle_connection_sync()))
483
+ thread = threading.Thread(target=lambda: handle_connection_sync())
466
484
  thread.start()
467
485
 
468
486
  runner = f"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stores
3
- Version: 0.1.7.dev2
3
+ Version: 0.1.7.dev4
4
4
  Summary: Repository of Python functions and tools for LLMs
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
@@ -8,8 +8,8 @@ stores/indexes/base_index.py,sha256=YrEwETZ5eXj3rXK5qxOllRXqFifQoteYdzPAasbvEyg,
8
8
  stores/indexes/index.py,sha256=Cub5mtnYGipHfPR8BexJYRSKfuJmcGPp0B3ou2bGNqs,2901
9
9
  stores/indexes/local_index.py,sha256=Gg9LkEo1L0_NZZYPItsF_-1y6nFP369C3QlPvPyvPx8,3708
10
10
  stores/indexes/remote_index.py,sha256=-GV4l2c7GL6_bcVOQnSK5rzYru237bwC5L6eiO-QFzM,3438
11
- stores/indexes/venv_utils.py,sha256=tS2ZYt2Cf7rqHxBXwn5EoEdUFjyaAIXVRiy8iXjCMb4,17397
12
- stores-0.1.7.dev2.dist-info/METADATA,sha256=AciMTIC_8qRvud2y3guHn78X-F_n5j-rlCOUNeFLBAc,3081
13
- stores-0.1.7.dev2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- stores-0.1.7.dev2.dist-info/licenses/LICENSE,sha256=VTidYE7_Dam0Dwyq095EhhDIqi47g03oVpLAHQgKws0,1066
15
- stores-0.1.7.dev2.dist-info/RECORD,,
11
+ stores/indexes/venv_utils.py,sha256=-6cL9dcW9TVc1rTGHTCFIIrA38FaG8DKElNuwRL9-78,17764
12
+ stores-0.1.7.dev4.dist-info/METADATA,sha256=kmOekRAa1E8TGBgejyKqDNuzt3A7XSCCOeytEfwp1_s,3081
13
+ stores-0.1.7.dev4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ stores-0.1.7.dev4.dist-info/licenses/LICENSE,sha256=VTidYE7_Dam0Dwyq095EhhDIqi47g03oVpLAHQgKws0,1066
15
+ stores-0.1.7.dev4.dist-info/RECORD,,