|
1 | | -from typing import Any, Dict, Optional |
2 | | - |
3 | | -from litellm import AdapterCompletionStreamWrapper, ChatCompletionRequest, ModelResponse |
4 | 1 | from litellm.adapters.anthropic_adapter import ( |
5 | 2 | AnthropicAdapter as LitellmAnthropicAdapter, |
6 | 3 | ) |
7 | | -from litellm.types.llms.anthropic import AnthropicResponse |
8 | 4 |
|
9 | | -from codegate.providers.base import StreamGenerator |
10 | | -from codegate.providers.litellmshim import BaseAdapter, anthropic_stream_generator |
| 5 | +from codegate.providers.litellmshim.adapter import ( |
| 6 | + LiteLLMAdapterInputNormalizer, |
| 7 | + LiteLLMAdapterOutputNormalizer, |
| 8 | +) |
11 | 9 |
|
12 | 10 |
|
13 | | -class AnthropicAdapter(BaseAdapter): |
| 11 | +class AnthropicInputNormalizer(LiteLLMAdapterInputNormalizer): |
14 | 12 | """ |
15 | 13 | LiteLLM's adapter class interface is used to translate between the Anthropic data |
16 | 14 | format and the underlying model. The AnthropicAdapter class contains the actual |
17 | 15 | implementation of the interface methods, we just forward the calls to it. |
18 | 16 | """ |
19 | 17 |
|
20 | | - def __init__(self, stream_generator: StreamGenerator = anthropic_stream_generator): |
21 | | - self.litellm_anthropic_adapter = LitellmAnthropicAdapter() |
22 | | - super().__init__(stream_generator) |
| 18 | + def __init__(self): |
| 19 | + super().__init__(LitellmAnthropicAdapter()) |
23 | 20 |
|
24 | | - def translate_completion_input_params( |
25 | | - self, |
26 | | - completion_request: Dict, |
27 | | - ) -> Optional[ChatCompletionRequest]: |
28 | | - return self.litellm_anthropic_adapter.translate_completion_input_params(completion_request) |
29 | 21 |
|
30 | | - def translate_completion_output_params( |
31 | | - self, response: ModelResponse |
32 | | - ) -> Optional[AnthropicResponse]: |
33 | | - return self.litellm_anthropic_adapter.translate_completion_output_params(response) |
| 22 | +class AnthropicOutputNormalizer(LiteLLMAdapterOutputNormalizer): |
| 23 | + """ |
| 24 | + LiteLLM's adapter class interface is used to translate between the Anthropic data |
| 25 | + format and the underlying model. The AnthropicAdapter class contains the actual |
| 26 | + implementation of the interface methods, we just forward the calls to it. |
| 27 | + """ |
34 | 28 |
|
35 | | - def translate_completion_output_params_streaming( |
36 | | - self, completion_stream: Any |
37 | | - ) -> AdapterCompletionStreamWrapper | None: |
38 | | - return self.litellm_anthropic_adapter.translate_completion_output_params_streaming( |
39 | | - completion_stream |
40 | | - ) |
| 29 | + def __init__(self): |
| 30 | + super().__init__(LitellmAnthropicAdapter()) |
0 commit comments