MCPcopy Create free account
hub / github.com/1rgs/claude-code-proxy / MessagesRequest

Class MessagesRequest

server.py:213–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211
212
213class MessagesRequest(BaseModel):
214 model: str
215 max_tokens: int
216 messages: List[Message]
217 system: Optional[Union[str, List[SystemContent]]] = None
218 stop_sequences: Optional[List[str]] = None
219 stream: Optional[bool] = False
220 temperature: Optional[float] = 1.0
221 top_p: Optional[float] = None
222 top_k: Optional[int] = None
223 metadata: Optional[Dict[str, Any]] = None
224 tools: Optional[List[Tool]] = None
225 tool_choice: Optional[Dict[str, Any]] = None
226 thinking: Optional[ThinkingConfig] = None
227 original_model: Optional[str] = None # Will store the original model name
228
229 @field_validator("model")
230 def validate_model_field(cls, v, info): # Renamed to avoid conflict
231 original_model = v
232 new_model = v # Default to original value
233
234 logger.debug(
235 f"📋 MODEL VALIDATION: Original='{original_model}', Preferred='{PREFERRED_PROVIDER}', BIG='{BIG_MODEL}', SMALL='{SMALL_MODEL}'"
236 )
237
238 # Remove provider prefixes for easier matching
239 clean_v = v
240 if clean_v.startswith("anthropic/"):
241 clean_v = clean_v[10:]
242 elif clean_v.startswith("openai/"):
243 clean_v = clean_v[7:]
244 elif clean_v.startswith("gemini/"):
245 clean_v = clean_v[7:]
246
247 # --- Mapping Logic --- START ---
248 mapped = False
249 if PREFERRED_PROVIDER == "anthropic":
250 # Don't remap to big/small models, just add the prefix
251 new_model = f"anthropic/{clean_v}"
252 mapped = True
253
254 # Map Haiku to SMALL_MODEL based on provider preference
255 elif "haiku" in clean_v.lower():
256 if PREFERRED_PROVIDER == "google" and SMALL_MODEL in GEMINI_MODELS:
257 new_model = f"gemini/{SMALL_MODEL}"
258 mapped = True
259 else:
260 new_model = f"openai/{SMALL_MODEL}"
261 mapped = True
262
263 # Map Sonnet to BIG_MODEL based on provider preference
264 elif "sonnet" in clean_v.lower():
265 if PREFERRED_PROVIDER == "google" and BIG_MODEL in GEMINI_MODELS:
266 new_model = f"gemini/{BIG_MODEL}"
267 mapped = True
268 else:
269 new_model = f"openai/{BIG_MODEL}"
270 mapped = True

Callers 1

count_tokensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected