latitude-sdk 1.0.0__py3-none-any.whl → 1.0.1__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.
@@ -204,9 +204,26 @@ class Prompts:
204
204
  # NOTE: FinishedEvent not in on_event
205
205
  return FinishedEvent(uuid=uuid, conversation=conversation, response=response)
206
206
 
207
- def _pause_tool_execution(self) -> ToolResult:
207
+ @staticmethod
208
+ def _pause_tool_execution() -> Any:
208
209
  raise OnToolCallPaused()
209
210
 
211
+ @staticmethod
212
+ async def _wrap_tool_handler(
213
+ handler: OnToolCall, arguments: Dict[str, Any], details: OnToolCallDetails
214
+ ) -> ToolResult:
215
+ tool_result: Dict[str, Any] = {"id": details.id, "name": details.name}
216
+
217
+ try:
218
+ result = await handler(arguments, details)
219
+
220
+ return ToolResult(**tool_result, result=result)
221
+ except Exception as exception:
222
+ if isinstance(exception, OnToolCallPaused):
223
+ raise exception
224
+
225
+ return ToolResult(**tool_result, result=str(exception), is_error=True)
226
+
210
227
  async def _handle_tool_calls(
211
228
  self, result: FinishedEvent, options: Union[RunPromptOptions, ChatPromptOptions]
212
229
  ) -> Optional[FinishedEvent]:
@@ -230,15 +247,22 @@ class Prompts:
230
247
  response=f"Tool {tool_call.name} not supplied",
231
248
  )
232
249
 
233
- details = OnToolCallDetails(
234
- conversation_uuid=result.uuid,
235
- messages=result.conversation,
236
- pause_execution=self._pause_tool_execution,
237
- requested_tool_calls=result.response.tool_calls,
238
- )
239
-
240
250
  tool_results = await asyncio.gather(
241
- *[options.tools[tool_call.name](tool_call, details) for tool_call in result.response.tool_calls],
251
+ *[
252
+ self._wrap_tool_handler(
253
+ options.tools[tool_call.name],
254
+ tool_call.arguments,
255
+ OnToolCallDetails(
256
+ id=tool_call.id,
257
+ name=tool_call.name,
258
+ conversation_uuid=result.uuid,
259
+ messages=result.conversation,
260
+ pause_execution=self._pause_tool_execution,
261
+ requested_tool_calls=result.response.tool_calls,
262
+ ),
263
+ )
264
+ for tool_call in result.response.tool_calls
265
+ ],
242
266
  return_exceptions=False,
243
267
  )
244
268
 
@@ -403,6 +427,7 @@ class Prompts:
403
427
  def _adapt_prompt_config(self, config: Dict[str, Any], adapter: Adapter) -> Dict[str, Any]:
404
428
  adapted_config: Dict[str, Any] = {}
405
429
 
430
+ # NOTE: Should we delete attributes not supported by the provider?
406
431
  for attr, value in config.items():
407
432
  if attr in _PROMPT_ATTR_TO_ADAPTER_ATTR and adapter in _PROMPT_ATTR_TO_ADAPTER_ATTR[attr][1]:
408
433
  adapted_config[_PROMPT_ATTR_TO_ADAPTER_ATTR[attr][0]] = value
latitude_sdk/sdk/types.py CHANGED
@@ -216,6 +216,8 @@ class StreamCallbacks(Model):
216
216
 
217
217
 
218
218
  class OnToolCallDetails(Model):
219
+ id: str
220
+ name: str
219
221
  conversation_uuid: str
220
222
  messages: List[Message]
221
223
  pause_execution: Callable[[], ToolResult]
@@ -224,7 +226,7 @@ class OnToolCallDetails(Model):
224
226
 
225
227
  @runtime_checkable
226
228
  class OnToolCall(Protocol):
227
- async def __call__(self, call: ToolCall, details: OnToolCallDetails) -> ToolResult: ...
229
+ async def __call__(self, arguments: Dict[str, Any], details: OnToolCallDetails) -> Any: ...
228
230
 
229
231
 
230
232
  @runtime_checkable
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: latitude-sdk
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Latitude SDK for Python
5
5
  Project-URL: repository, https://github.com/latitude-dev/latitude-llm/tree/main/packages/sdks/python
6
6
  Project-URL: homepage, https://github.com/latitude-dev/latitude-llm/tree/main/packages/sdks/python#readme
@@ -11,10 +11,10 @@ latitude_sdk/sdk/errors.py,sha256=9GlGdDE8LGy3dE2Ry_BipBg-tDbQx7LWXJfSnTJSSBE,17
11
11
  latitude_sdk/sdk/evaluations.py,sha256=fDGtAWjdPG9OuKLit6u-jufVleC1EnshRplK6RN8iyg,2277
12
12
  latitude_sdk/sdk/latitude.py,sha256=fdOWrAs0k3puLIhyU_zwvLsMyV_f1RxDWpV65_Euenc,2928
13
13
  latitude_sdk/sdk/logs.py,sha256=CyHkRJvPl_p7wTSvR9bgxEI5akS0Tjc9FeQRb2C2vMg,1997
14
- latitude_sdk/sdk/prompts.py,sha256=w3A-dhE_V1ueYjc8LBRXmQn5XZVCnsMdxs7Rau7P_E0,15818
15
- latitude_sdk/sdk/types.py,sha256=D6wKkt5WSC0Ih6QT3QFSaU9YoxURKw8GKM7aH_uQ2-Q,6892
14
+ latitude_sdk/sdk/prompts.py,sha256=HXvJVqcn446VI2nlIT2lCuOrNypNqE0x1Sy0l77MDFM,16756
15
+ latitude_sdk/sdk/types.py,sha256=v8K1zzJqPexos08U4cnsHJ3LrkVRlbgMNvwtKuXoxuQ,6922
16
16
  latitude_sdk/util/__init__.py,sha256=alIDGBnxWH4JvP-UW-7N99seBBi0r1GV1h8f1ERFBec,21
17
17
  latitude_sdk/util/utils.py,sha256=hMOmF-u1QaDgOwXN6ME6n4TaQ70yZKLvijDUqNCMwXI,2844
18
- latitude_sdk-1.0.0.dist-info/METADATA,sha256=nK2qNPBfe6nAZLSVYkMfaU-ub9Y4flAUXyKc6OMRr2k,2060
19
- latitude_sdk-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
- latitude_sdk-1.0.0.dist-info/RECORD,,
18
+ latitude_sdk-1.0.1.dist-info/METADATA,sha256=6eLckfer4mDy1JY6ZzWNJcdh0zk_RmLJ7H2aFEoQfCg,2060
19
+ latitude_sdk-1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
+ latitude_sdk-1.0.1.dist-info/RECORD,,