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

Method __init__

camel/toolkits/function_tool.py:323–383  ·  view source on GitHub ↗
(
        self,
        func: Callable,
        openai_tool_schema: Optional[Dict[str, Any]] = None,
        synthesize_schema: Optional[bool] = False,
        synthesize_schema_model: Optional[BaseModelBackend] = None,
        synthesize_schema_max_retries: int = 2,
        synthesize_output: Optional[bool] = False,
        synthesize_output_model: Optional[BaseModelBackend] = None,
        synthesize_output_format: Optional[Type[BaseModel]] = None,
    )

Source from the content-addressed store, hash-verified

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. "
347 f"Use `{self.synthesize_output_model.model_type}` to "
348 "synthesize the output."
349 )
350 self.synthesize_output_format: Optional[type[BaseModel]] = None
351 return_annotation = inspect.signature(self.func).return_annotation
352 if synthesize_output_format is not None:
353 self.synthesize_output_format = synthesize_output_format
354 elif isinstance(return_annotation, type) and issubclass(
355 return_annotation, BaseModel
356 ):
357 self.synthesize_output_format = return_annotation
358
359 self.synthesize_schema_model = synthesize_schema_model
360 if synthesize_schema:
361 if openai_tool_schema:
362 logger.warning("""The user-defined OpenAI tool schema will be
363 overridden by the schema assistant model.""")
364 if self.synthesize_schema_model is None:
365 self.synthesize_schema_model = ModelFactory.create(
366 model_platform=ModelPlatformType.DEFAULT,
367 model_type=ModelType.DEFAULT,
368 )
369 logger.warning(
370 "Warning: No synthesize_schema_model provided. "
371 f"Use `{self.synthesize_schema_model.model_type}` to "
372 "synthesize the schema."
373 )
374 schema = self.synthesize_openai_tool_schema(
375 synthesize_schema_max_retries
376 )
377 if schema:
378 self.openai_tool_schema = schema
379 else:
380 raise ValueError(

Callers

nothing calls this directly

Calls 3

get_openai_tool_schemaFunction · 0.70
createMethod · 0.45

Tested by

no test coverage detected