"""Concrete model adapters for DeepSeek, Kimi, and Qwen.""" from typing import Any, Dict from app.model_adapters.base import ModelAdapter class DeepSeekAdapter(ModelAdapter): def _build_payload(self, prompt: str, params: Dict[str, Any]) -> Dict[str, Any]: return { "model": self.model, "messages": [{"role": "user", "content": prompt}], "temperature": params.get("temperature", 0.7), "max_tokens": params.get("max_tokens", 8192), # Disable vendor reasoning mode: thinking tokens would otherwise # exhaust max_tokens and leave `content` empty, and reasoning # behavior is an uncontrolled variable in the prompt-strategy # experiment. "thinking": {"type": "disabled"}, } def _extract_text(self, data: Dict[str, Any]) -> str: return data["choices"][0]["message"]["content"] class KimiAdapter(ModelAdapter): def _build_payload(self, prompt: str, params: Dict[str, Any]) -> Dict[str, Any]: return { "model": self.model, "messages": [{"role": "user", "content": prompt}], # kimi-k2.x rejects any temperature other than 0.6. "temperature": params.get("temperature", 0.6), "max_tokens": params.get("max_tokens", 8192), # No `thinking` switch: kimi-k2.x rejects it, and its built-in # reasoning is short enough to leave room for the answer. } def _extract_text(self, data: Dict[str, Any]) -> str: return data["choices"][0]["message"]["content"] class QwenAdapter(ModelAdapter): def _build_payload(self, prompt: str, params: Dict[str, Any]) -> Dict[str, Any]: return { "model": self.model, "messages": [{"role": "user", "content": prompt}], "temperature": params.get("temperature", 0.7), "max_tokens": params.get("max_tokens", 8192), # Disable vendor reasoning mode: thinking tokens would otherwise # exhaust max_tokens and leave `content` empty, and reasoning # behavior is an uncontrolled variable in the prompt-strategy # experiment. "thinking": {"type": "disabled"}, } def _extract_text(self, data: Dict[str, Any]) -> str: return data["choices"][0]["message"]["content"]