|
8 | 8 | from contextlib import asynccontextmanager |
9 | 9 | from dataclasses import dataclass, field, replace |
10 | 10 | from datetime import datetime |
| 11 | +from functools import cached_property |
11 | 12 | from typing import TYPE_CHECKING, Any, Literal, cast, overload |
12 | 13 |
|
13 | 14 | from pydantic import ValidationError |
@@ -424,15 +425,23 @@ def system(self) -> str: |
424 | 425 | """The model provider.""" |
425 | 426 | return self._provider.name |
426 | 427 |
|
427 | | - def supported_builtin_tools(self, profile: ModelProfile) -> frozenset[type[AbstractBuiltinTool]]: |
428 | | - """Return the set of builtin tool types this model can handle. |
| 428 | + @classmethod |
| 429 | + def supported_builtin_tools(cls) -> frozenset[type[AbstractBuiltinTool]]: |
| 430 | + """Return the set of builtin tool types this model can handle.""" |
| 431 | + return frozenset({WebSearchTool}) |
| 432 | + |
| 433 | + @cached_property |
| 434 | + def profile(self) -> ModelProfile: |
| 435 | + """The model profile. |
429 | 436 |
|
430 | 437 | WebSearchTool is only supported if openai_chat_supports_web_search is True. |
431 | 438 | """ |
432 | | - openai_profile = OpenAIModelProfile.from_profile(profile) |
433 | | - if openai_profile.openai_chat_supports_web_search: |
434 | | - return frozenset({WebSearchTool}) |
435 | | - return frozenset() |
| 439 | + _profile = super().profile |
| 440 | + openai_profile = OpenAIModelProfile.from_profile(_profile) |
| 441 | + if not openai_profile.openai_chat_supports_web_search: |
| 442 | + new_tools = _profile.supported_builtin_tools - {WebSearchTool} |
| 443 | + _profile = replace(_profile, supported_builtin_tools=new_tools) |
| 444 | + return _profile |
436 | 445 |
|
437 | 446 | @property |
438 | 447 | @deprecated('Set the `system_prompt_role` in the `OpenAIModelProfile` instead.') |
@@ -1092,7 +1101,8 @@ def system(self) -> str: |
1092 | 1101 | """The model provider.""" |
1093 | 1102 | return self._provider.name |
1094 | 1103 |
|
1095 | | - def supported_builtin_tools(self, profile: ModelProfile) -> frozenset[type[AbstractBuiltinTool]]: |
| 1104 | + @classmethod |
| 1105 | + def supported_builtin_tools(cls) -> frozenset[type[AbstractBuiltinTool]]: |
1096 | 1106 | """Return the set of builtin tool types this model can handle.""" |
1097 | 1107 | return frozenset({WebSearchTool, CodeExecutionTool, MCPServerTool, ImageGenerationTool}) |
1098 | 1108 |
|
|
0 commit comments