Skip to content

Commit 09dfb8a

Browse files
committed
Tool → FunctionTool
1 parent a77dfa1 commit 09dfb8a

File tree

9 files changed

+29
-26
lines changed

9 files changed

+29
-26
lines changed

src/marvin/_mappings/base_model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pydantic import BaseModel
44
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaMode
55

6-
from marvin.types import Function, Tool, ToolSet
6+
from marvin.types import Function, FunctionTool, ToolSet
77

88

99
class FunctionSchema(GenerateJsonSchema):
@@ -15,10 +15,10 @@ def generate(self, schema: Any, mode: JsonSchemaMode = "validation"):
1515

1616
def cast_model_to_tool(
1717
model: type[BaseModel],
18-
) -> Tool[BaseModel]:
18+
) -> FunctionTool[BaseModel]:
1919
model_name = model.__name__
2020
model_description = model.__doc__
21-
return Tool[BaseModel](
21+
return FunctionTool[BaseModel](
2222
type="function",
2323
function=Function[BaseModel](
2424
name=model_name,

src/marvin/_mappings/types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic.fields import FieldInfo
77

88
from marvin.settings import settings
9-
from marvin.types import Grammar, Tool, ToolSet
9+
from marvin.types import FunctionTool, Grammar, ToolSet
1010

1111
from .base_model import cast_model_to_tool, cast_model_to_toolset
1212

@@ -46,7 +46,7 @@ def cast_type_to_tool(
4646
field_name: str,
4747
field_description: str,
4848
python_function: Optional[Callable[..., Any]] = None,
49-
) -> Tool[BaseModel]:
49+
) -> FunctionTool[BaseModel]:
5050
return cast_model_to_tool(
5151
model=cast_type_to_model(
5252
_type,

src/marvin/beta/applications/applications.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from marvin.beta.assistants import Assistant
77
from marvin.beta.assistants.runs import Run
88
from marvin.tools.assistants import AssistantTool
9-
from marvin.types import Tool
9+
from marvin.types import FunctionTool
1010
from marvin.utilities.jinja import Environment as JinjaEnvironment
1111
from marvin.utilities.tools import tool_from_function
1212

@@ -66,7 +66,7 @@ def get_tools(self) -> list[AssistantTool]:
6666
tools = []
6767

6868
for tool in [self.state.as_tool(name="state")] + self.tools:
69-
if not isinstance(tool, Tool):
69+
if not isinstance(tool, FunctionTool):
7070
kwargs = None
7171
signature = inspect.signature(tool)
7272
for parameter in signature.parameters.values():

src/marvin/beta/applications/state/state.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from jsonpatch import JsonPatch
66
from pydantic import BaseModel, Field, PrivateAttr, SerializeAsAny
77

8-
from marvin.types import Tool
8+
from marvin.types import FunctionTool
99
from marvin.utilities.tools import tool_from_function
1010

1111

@@ -66,7 +66,7 @@ def update_state_jsonpatches(self, patches: list[JSONPatchModel]):
6666
self.set_state(state)
6767
return "Application state updated successfully!"
6868

69-
def as_tool(self, name: str = None) -> "Tool":
69+
def as_tool(self, name: str = None) -> "FunctionTool":
7070
if name is None:
7171
name = "state"
7272
schema = self.get_schema()

src/marvin/beta/assistants/assistants.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import marvin.utilities.openai
99
import marvin.utilities.tools
1010
from marvin.tools.assistants import AssistantTool
11-
from marvin.types import Tool
11+
from marvin.types import FunctionTool
1212
from marvin.utilities.asyncio import (
1313
ExposeSyncMethodsMixin,
1414
expose_sync_method,
@@ -64,7 +64,7 @@ def get_tools(self) -> list[AssistantTool]:
6464
return [
6565
(
6666
tool
67-
if isinstance(tool, Tool)
67+
if isinstance(tool, FunctionTool)
6868
else marvin.utilities.tools.tool_from_function(tool)
6969
)
7070
for tool in self.tools

src/marvin/beta/assistants/runs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import marvin.utilities.openai
1212
import marvin.utilities.tools
1313
from marvin.tools.assistants import AssistantTool, CancelRun
14-
from marvin.types import Tool
14+
from marvin.types import FunctionTool
1515
from marvin.utilities.asyncio import ExposeSyncMethodsMixin, expose_sync_method
1616
from marvin.utilities.logging import get_logger
1717

@@ -61,12 +61,12 @@ class Run(BaseModel, ExposeSyncMethodsMixin):
6161
data: Any = None
6262

6363
@field_validator("tools", "additional_tools", mode="before")
64-
def format_tools(cls, tools: Union[None, list[Union[Tool, Callable]]]):
64+
def format_tools(cls, tools: Union[None, list[Union[FunctionTool, Callable]]]):
6565
if tools is not None:
6666
return [
6767
(
6868
tool
69-
if isinstance(tool, Tool)
69+
if isinstance(tool, FunctionTool)
7070
else marvin.utilities.tools.tool_from_function(tool)
7171
)
7272
for tool in tools

src/marvin/tools/assistants.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from typing import Any, Union
22

3-
from marvin.types import CodeInterpreterTool, RetrievalTool, Tool
3+
from marvin.types import CodeInterpreterTool, FunctionTool, RetrievalTool
44

55
Retrieval = RetrievalTool()
66
CodeInterpreter = CodeInterpreterTool()
77

8-
AssistantTool = Union[RetrievalTool, CodeInterpreterTool, Tool]
8+
AssistantTool = Union[RetrievalTool, CodeInterpreterTool, FunctionTool]
99

1010

1111
class CancelRun(Exception):

src/marvin/types.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,24 @@ def create(
6060
return instance
6161

6262

63-
class Tool(MarvinType, Generic[T]):
63+
class Tool(MarvinType):
6464
type: str
65+
66+
67+
class FunctionTool(Tool, Generic[T]):
6568
function: Optional[Function[T]] = None
6669

6770

6871
class ToolSet(MarvinType, Generic[T]):
69-
tools: Optional[list[Tool[T]]] = None
72+
tools: Optional[list[Union[Tool, FunctionTool[T]]]] = None
7073
tool_choice: Optional[Union[Literal["auto"], dict[str, Any]]] = None
7174

7275

73-
class RetrievalTool(Tool[T]):
76+
class RetrievalTool(FunctionTool[T]):
7477
type: Literal["retrieval"] = "retrieval"
7578

7679

77-
class CodeInterpreterTool(Tool[T]):
80+
class CodeInterpreterTool(FunctionTool[T]):
7881
type: Literal["code_interpreter"] = "code_interpreter"
7982

8083

@@ -244,7 +247,7 @@ class Run(MarvinType, Generic[T]):
244247
status: str
245248
model: str
246249
instructions: Optional[str]
247-
tools: Optional[list[Tool[T]]] = None
250+
tools: Optional[list[FunctionTool[T]]] = None
248251
metadata: dict[str, str]
249252

250253

src/marvin/utilities/tools.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pydantic.fields import FieldInfo
1818
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaMode
1919

20-
from marvin.types import Function, Tool
20+
from marvin.types import Function, FunctionTool
2121
from marvin.utilities.asyncio import run_sync
2222
from marvin.utilities.logging import get_logger
2323

@@ -63,7 +63,7 @@ def generate(self, schema: Any, mode: JsonSchemaMode = "validation"):
6363
return json_schema
6464

6565

66-
def tool_from_type(type_: U, tool_name: str = None) -> Tool[U]:
66+
def tool_from_type(type_: U, tool_name: str = None) -> FunctionTool[U]:
6767
"""
6868
Creates an OpenAI-compatible tool from a Python type.
6969
"""
@@ -99,7 +99,7 @@ def tool_from_model(model: type[M], python_fn: Callable[[str], M] = None):
9999
def tool_fn(**data) -> M:
100100
return TypeAdapter(model).validate_python(data)
101101

102-
return Tool[M](
102+
return FunctionTool[M](
103103
type="function",
104104
function=Function[M].create(
105105
name=model.__name__,
@@ -130,7 +130,7 @@ def tool_from_function(
130130
fn, config=pydantic.ConfigDict(arbitrary_types_allowed=True)
131131
).json_schema()
132132

133-
return Tool[T](
133+
return FunctionTool[T](
134134
type="function",
135135
function=Function[T].create(
136136
name=name or fn.__name__,
@@ -142,7 +142,7 @@ def tool_from_function(
142142

143143

144144
def call_function_tool(
145-
tools: list[Tool],
145+
tools: list[FunctionTool],
146146
function_name: str,
147147
function_arguments_json: str,
148148
return_string: bool = False,

0 commit comments

Comments
 (0)