refac
This commit is contained in:
1 parent
9acbe3aa0f
commit
d727ee4d1f
1 file changed
+13
-5
@@ -8,7 +8,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from functools import partial, update_wrapper
|
from functools import cache, partial, update_wrapper
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Awaitable,
|
Awaitable,
|
||||||
@@ -781,10 +781,7 @@ async def get_builtin_tools(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate spec from function
|
spec = get_builtin_tool_spec(func)
|
||||||
pydantic_model = convert_function_to_pydantic_model(func)
|
|
||||||
spec = convert_pydantic_model_to_openai_function_spec(pydantic_model)
|
|
||||||
spec = clean_openai_tool_schema(spec)
|
|
||||||
if func.__name__ == 'delegate_task' and not config.get('subagents.background_enabled'):
|
if func.__name__ == 'delegate_task' and not config.get('subagents.background_enabled'):
|
||||||
parameters = spec.get('parameters', {})
|
parameters = spec.get('parameters', {})
|
||||||
parameters.get('properties', {}).pop('background', None)
|
parameters.get('properties', {}).pop('background', None)
|
||||||
@@ -935,6 +932,17 @@ def clean_openai_tool_schema(spec: dict) -> dict:
|
|||||||
return cleaned_spec
|
return cleaned_spec
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def build_builtin_tool_spec(func: Callable) -> dict:
|
||||||
|
pydantic_model = convert_function_to_pydantic_model(func)
|
||||||
|
spec = convert_pydantic_model_to_openai_function_spec(pydantic_model)
|
||||||
|
return clean_openai_tool_schema(spec)
|
||||||
|
|
||||||
|
|
||||||
|
def get_builtin_tool_spec(func: Callable) -> dict:
|
||||||
|
return copy.deepcopy(build_builtin_tool_spec(func))
|
||||||
|
|
||||||
|
|
||||||
def get_functions_from_tool(tool: object) -> list[Callable]:
|
def get_functions_from_tool(tool: object) -> list[Callable]:
|
||||||
return [
|
return [
|
||||||
getattr(tool, func)
|
getattr(tool, func)
|
||||||
|
|||||||
Reference in new issue
Block a user