fix(oci/cohere): mark logprobs/logit_bias unsupported and normalize unknown stream finish reasons

Co-authored-by: Yassin Kortam <yassin@berri.ai>
This commit is contained in:
Cursor Agent 2026-05-19 07:59:46 +00:00
parent f9128b77f1
commit bf133568c0
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View file

@ -294,6 +294,12 @@ def handle_cohere_stream_chunk(dict_chunk: dict) -> ModelResponseStream:
finish_reason = "length"
elif finish_reason == "TOOL_CALL":
finish_reason = "tool_calls"
elif finish_reason is not None:
# OCI Cohere can emit error/cancel finish reasons (e.g. ``ERROR``,
# ``ERROR_TOXIC``, ``ERROR_LIMIT``, ``USER_CANCEL``) that aren't part
# of OpenAI's standard set. Normalize them to ``"stop"`` so downstream
# consumers switching on ``finish_reason`` keep working.
finish_reason = "stop"
return ModelResponseStream(
choices=[

View file

@ -209,6 +209,12 @@ class OCIChatConfig(BaseConfig):
# the param dropped under drop_params, rather than silently passing
# through and tripping Pydantic validation on CohereChatRequest.
self.openai_to_oci_cohere_param_map["reasoning_effort"] = False
# CohereChatRequest has no logProbs/logitBias fields, so passing these
# through would be silently dropped by Pydantic. Mark them unsupported
# so get_supported_openai_params doesn't advertise them and callers
# get a clear error (or drop_params behaviour) instead.
self.openai_to_oci_cohere_param_map["logprobs"] = False
self.openai_to_oci_cohere_param_map["logit_bias"] = False
def get_supported_openai_params(self, model: str) -> List[str]:
param_map = (