Create the main LLM model from configuration.
(config: Config)
| 107 | class CompatibleOpenAIModel(OpenAIChatModel): |
| 108 | """OpenAIChatModel subclass that patches non-standard API proxy responses. |
| 109 | |
| 110 | Some OpenAI-compatible proxies return responses with fields like |
| 111 | choices[].index set to None instead of an integer. This subclass |
| 112 | fixes those fields before pydantic validation runs. |
| 113 | """ |
| 114 | |
| 115 | def _validate_completion(self, response: chat.ChatCompletion) -> chat.ChatCompletion: |
| 116 | # Patch choices[].index: None -> sequential integer (0, 1, 2, ...) |
| 117 | if response.choices: |
| 118 | for i, choice in enumerate(response.choices): |
| 119 | if choice.index is None: |
| 120 | choice.index = i |
| 121 | return super()._validate_completion(response) |
no test coverage detected