|
6 | 6 | from collections.abc import AsyncIterator, Callable, Iterator, Sequence |
7 | 7 | from typing import Any |
8 | 8 |
|
9 | | -from pydantic import BaseModel |
10 | | - |
11 | 9 | from any_llm.any_llm import AnyLLM |
12 | 10 | from any_llm.config import ClientConfig |
13 | | -from any_llm.exceptions import MissingApiKeyError |
| 11 | +from any_llm.exceptions import MissingApiKeyError, UnsupportedParameterError |
14 | 12 | from any_llm.logging import logger |
15 | 13 | from any_llm.types.completion import ChatCompletion, ChatCompletionChunk, CompletionParams, CreateEmbeddingResponse |
16 | 14 | from any_llm.types.model import Model |
17 | | -from any_llm.utils.instructor import _convert_instructor_response |
18 | 15 |
|
19 | 16 | MISSING_PACKAGES_ERROR = None |
20 | 17 | try: |
@@ -137,28 +134,8 @@ def _completion( |
137 | 134 | completion_kwargs = self._convert_completion_params(params, **kwargs) |
138 | 135 |
|
139 | 136 | if params.response_format: |
140 | | - if params.stream: |
141 | | - msg = "stream is not supported for response_format" |
142 | | - raise ValueError(msg) |
143 | | - |
144 | | - if not isinstance(params.response_format, type) or not issubclass(params.response_format, BaseModel): |
145 | | - msg = "response_format must be a pydantic model" |
146 | | - raise ValueError(msg) |
147 | | - |
148 | | - response = self.client.invoke_endpoint( |
149 | | - EndpointName=params.model_id, |
150 | | - Body=json.dumps(completion_kwargs), |
151 | | - ContentType="application/json", |
152 | | - ) |
153 | | - |
154 | | - response_body = json.loads(response["Body"].read()) |
155 | | - |
156 | | - try: |
157 | | - structured_response = params.response_format.model_validate(response_body) |
158 | | - return _convert_instructor_response(structured_response, params.model_id, "aws") |
159 | | - except (ValueError, TypeError) as e: |
160 | | - logger.warning("Failed to parse structured response: %s", e) |
161 | | - return self._convert_completion_response({"model": params.model_id, **response_body}) |
| 137 | + param = "response_format" |
| 138 | + raise UnsupportedParameterError(param, "sagemaker") |
162 | 139 |
|
163 | 140 | if params.stream: |
164 | 141 | response = self.client.invoke_endpoint_with_response_stream( |
|
0 commit comments