Repository navigation
Expand file tree
/
Copy pathchatfunctiontool.py
More file actions
180 lines (150 loc) · 5.67 KB
/
Copy pathchatfunctiontool.py
File metadata and controls
180 lines (150 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .advisorservertool_openrouter import (
AdvisorServerToolOpenRouter,
AdvisorServerToolOpenRouterTypedDict,
)
from .bashservertool import BashServerTool, BashServerToolTypedDict
from .chatcontentcachecontrol import (
ChatContentCacheControl,
ChatContentCacheControlTypedDict,
)
from .chatsearchmodelsservertool import (
ChatSearchModelsServerTool,
ChatSearchModelsServerToolTypedDict,
)
from .chatwebsearchshorthand import (
ChatWebSearchShorthand,
ChatWebSearchShorthandTypedDict,
)
from .datetimeservertool import DatetimeServerTool, DatetimeServerToolTypedDict
from .filesservertool import FilesServerTool, FilesServerToolTypedDict
from .fusionservertool_openrouter import (
FusionServerToolOpenRouter,
FusionServerToolOpenRouterTypedDict,
)
from .imagegenerationservertool_openrouter import (
ImageGenerationServerToolOpenRouter,
ImageGenerationServerToolOpenRouterTypedDict,
)
from .openrouterwebsearchservertool import (
OpenRouterWebSearchServerTool,
OpenRouterWebSearchServerToolTypedDict,
)
from .subagentservertool_openrouter import (
SubagentServerToolOpenRouter,
SubagentServerToolOpenRouterTypedDict,
)
from .webfetchservertool import WebFetchServerTool, WebFetchServerToolTypedDict
from openrouter.types import (
BaseModel,
Nullable,
OptionalNullable,
UNSET,
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any, Dict, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict
class ChatFunctionToolFunctionFunctionTypedDict(TypedDict):
r"""Function definition for tool calling"""
name: str
r"""Function name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars)"""
description: NotRequired[str]
r"""Function description for the model"""
parameters: NotRequired[Dict[str, Nullable[Any]]]
r"""Function parameters as JSON Schema object"""
strict: NotRequired[Nullable[bool]]
r"""Enable strict schema adherence"""
class ChatFunctionToolFunctionFunction(BaseModel):
r"""Function definition for tool calling"""
name: str
r"""Function name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars)"""
description: Optional[str] = None
r"""Function description for the model"""
parameters: Optional[Dict[str, Nullable[Any]]] = None
r"""Function parameters as JSON Schema object"""
strict: OptionalNullable[bool] = UNSET
r"""Enable strict schema adherence"""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["description", "parameters", "strict"])
nullable_fields = set(["strict"])
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k, serialized.get(n))
is_nullable_and_explicitly_set = (
k in nullable_fields
and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member
)
if val != UNSET_SENTINEL:
if (
val is not None
or k not in optional_fields
or is_nullable_and_explicitly_set
):
m[k] = val
return m
ChatFunctionToolType = Literal["function",]
class ChatFunctionToolFunctionTypedDict(TypedDict):
function: ChatFunctionToolFunctionFunctionTypedDict
r"""Function definition for tool calling"""
type: ChatFunctionToolType
cache_control: NotRequired[ChatContentCacheControlTypedDict]
r"""Cache control for the content part"""
class ChatFunctionToolFunction(BaseModel):
function: ChatFunctionToolFunctionFunction
r"""Function definition for tool calling"""
type: ChatFunctionToolType
cache_control: Optional[ChatContentCacheControl] = None
r"""Cache control for the content part"""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["cache_control"])
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k, serialized.get(n))
if val != UNSET_SENTINEL:
if val is not None or k not in optional_fields:
m[k] = val
return m
ChatFunctionToolTypedDict = TypeAliasType(
"ChatFunctionToolTypedDict",
Union[
AdvisorServerToolOpenRouterTypedDict,
BashServerToolTypedDict,
DatetimeServerToolTypedDict,
FilesServerToolTypedDict,
FusionServerToolOpenRouterTypedDict,
ImageGenerationServerToolOpenRouterTypedDict,
ChatSearchModelsServerToolTypedDict,
SubagentServerToolOpenRouterTypedDict,
WebFetchServerToolTypedDict,
OpenRouterWebSearchServerToolTypedDict,
ChatFunctionToolFunctionTypedDict,
ChatWebSearchShorthandTypedDict,
],
)
r"""Tool definition for function calling (regular function or OpenRouter built-in server tool)"""
ChatFunctionTool = TypeAliasType(
"ChatFunctionTool",
Union[
AdvisorServerToolOpenRouter,
BashServerTool,
DatetimeServerTool,
FilesServerTool,
FusionServerToolOpenRouter,
ImageGenerationServerToolOpenRouter,
ChatSearchModelsServerTool,
SubagentServerToolOpenRouter,
WebFetchServerTool,
OpenRouterWebSearchServerTool,
ChatFunctionToolFunction,
ChatWebSearchShorthand,
],
)
r"""Tool definition for function calling (regular function or OpenRouter built-in server tool)"""