MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / FunctionTool

Class FunctionTool

camel/toolkits/function_tool.py:289–771  ·  view source on GitHub ↗

r"""An abstraction of a function that OpenAI chat models can call. See https://platform.openai.com/docs/api-reference/chat/create. By default, the tool schema will be parsed from the func, or you can provide a user-defined tool schema to override. Args: func (Callable): The

Source from the content-addressed store, hash-verified

287
288
289class FunctionTool:
290 r"""An abstraction of a function that OpenAI chat models can call. See
291 https://platform.openai.com/docs/api-reference/chat/create.
292
293 By default, the tool schema will be parsed from the func, or you can
294 provide a user-defined tool schema to override.
295
296 Args:
297 func (Callable): The function to call. The tool schema is parsed from
298 the function signature and docstring by default.
299 openai_tool_schema (Optional[Dict[str, Any]], optional): A
300 user-defined OpenAI tool schema to override the default result.
301 (default: :obj:`None`)
302 synthesize_schema (Optional[bool], optional): Whether to enable the
303 use of a schema assistant model to automatically synthesize the
304 schema if validation fails or no valid schema is provided.
305 (default: :obj:`False`)
306 synthesize_schema_model (Optional[BaseModelBackend], optional): An
307 assistant model (e.g., an LLM model) used to synthesize the schema
308 if `synthesize_schema` is enabled and no valid schema is
309 provided. (default: :obj:`None`)
310 synthesize_schema_max_retries (int, optional): The maximum
311 number of attempts to retry schema synthesis using the schema
312 assistant model if the previous attempts fail. (default: 2)
313 synthesize_output (Optional[bool], optional): Flag for enabling
314 synthesis output mode, where output is synthesized based on the
315 function's execution. (default: :obj:`False`)
316 synthesize_output_model (Optional[BaseModelBackend], optional):
317 Model used for output synthesis in synthesis mode.
318 (default: :obj:`None`)
319 synthesize_output_format (Optional[Type[BaseModel]], optional): Format
320 for the response when synthesizing output. (default: :obj:`None`)
321 """
322
323 def __init__(
324 self,
325 func: Callable,
326 openai_tool_schema: Optional[Dict[str, Any]] = None,
327 synthesize_schema: Optional[bool] = False,
328 synthesize_schema_model: Optional[BaseModelBackend] = None,
329 synthesize_schema_max_retries: int = 2,
330 synthesize_output: Optional[bool] = False,
331 synthesize_output_model: Optional[BaseModelBackend] = None,
332 synthesize_output_format: Optional[Type[BaseModel]] = None,
333 ) -> None:
334 self.func = func
335 self.openai_tool_schema = openai_tool_schema or get_openai_tool_schema(
336 func
337 )
338 self.synthesize_output = synthesize_output
339 self.synthesize_output_model = synthesize_output_model
340 if synthesize_output and synthesize_output_model is None:
341 self.synthesize_output_model = ModelFactory.create(
342 model_platform=ModelPlatformType.DEFAULT,
343 model_type=ModelType.DEFAULT,
344 )
345 logger.warning(
346 "Warning: No synthesize_output_model provided. "

Callers 15

sync_funcs_to_asyncFunction · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90
get_toolsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected