|
7 | 7 |
|
8 | 8 | MISSING_PACKAGES_ERROR = None |
9 | 9 | try: |
10 | | - from anthropic import Anthropic, AsyncAnthropic |
| 10 | + from anthropic import AsyncAnthropic |
11 | 11 |
|
12 | 12 | from .utils import ( |
13 | 13 | _convert_models_list, |
|
19 | 19 | MISSING_PACKAGES_ERROR = e |
20 | 20 |
|
21 | 21 | if TYPE_CHECKING: |
22 | | - from anthropic.pagination import SyncPage |
23 | 22 | from anthropic.types import Message |
24 | 23 | from anthropic.types.model_info import ModelInfo as AnthropicModelInfo |
25 | 24 |
|
@@ -75,7 +74,7 @@ def _convert_embedding_response(response: Any) -> CreateEmbeddingResponse: |
75 | 74 | raise NotImplementedError(msg) |
76 | 75 |
|
77 | 76 | @staticmethod |
78 | | - def _convert_list_models_response(response: "SyncPage[AnthropicModelInfo]") -> Sequence[Model]: |
| 77 | + def _convert_list_models_response(response: "list[AnthropicModelInfo]") -> Sequence[Model]: |
79 | 78 | """Convert Anthropic models list to OpenAI format.""" |
80 | 79 | return _convert_models_list(response) |
81 | 80 |
|
@@ -111,12 +110,11 @@ async def _acompletion( |
111 | 110 |
|
112 | 111 | return self._convert_completion_response(message) |
113 | 112 |
|
114 | | - def list_models(self, **kwargs: Any) -> Sequence[Model]: |
115 | | - """List available models from Anthropic.""" |
116 | | - client = Anthropic( |
| 113 | + async def _alist_models(self, **kwargs: Any) -> Sequence[Model]: |
| 114 | + client = AsyncAnthropic( |
117 | 115 | api_key=self.config.api_key, |
118 | 116 | base_url=self.config.api_base, |
119 | 117 | **(self.config.client_args if self.config.client_args else {}), |
120 | 118 | ) |
121 | | - models_list = client.models.list(**kwargs) |
122 | | - return self._convert_list_models_response(models_list) |
| 119 | + models_list = await client.models.list(**kwargs) |
| 120 | + return self._convert_list_models_response(models_list.data) |
0 commit comments