fix: use max_completion_tokens for OpenAI models on OCI GenAI
OpenAI models reject 'max_tokens' and require 'max_completion_tokens'. Also skip 'top_k' for OpenAI as it is unsupported. Detection is based on the provider field in the model catalog.
This commit is contained in:
@@ -868,15 +868,22 @@ def _call_genai(gc: dict, message: str, history: list = None) -> str:
|
||||
chat_history.append(entry)
|
||||
chat_request.chat_history = chat_history
|
||||
else:
|
||||
# ── Generic format (Meta Llama, Google, xAI) - exact chat_demo.py pattern ──
|
||||
# ── Generic format (Meta Llama, Google, xAI, OpenAI) ──
|
||||
chat_request = oci.generative_ai_inference.models.GenericChatRequest()
|
||||
chat_request.api_format = oci.generative_ai_inference.models.BaseChatRequest.API_FORMAT_GENERIC
|
||||
provider = model_info.get("provider", "")
|
||||
is_openai = provider == "openai"
|
||||
# OpenAI models use max_completion_tokens instead of max_tokens
|
||||
# and do not support top_k
|
||||
if is_openai:
|
||||
chat_request.max_completion_tokens = int(gc.get("max_tokens", 6000))
|
||||
else:
|
||||
chat_request.max_tokens = int(gc.get("max_tokens", 6000))
|
||||
chat_request.top_k = int(gc.get("top_k", 1))
|
||||
chat_request.temperature = float(gc.get("temperature", 1))
|
||||
chat_request.frequency_penalty = float(gc.get("frequency_penalty", 0))
|
||||
chat_request.presence_penalty = float(gc.get("presence_penalty", 0))
|
||||
chat_request.top_p = float(gc.get("top_p", 0.95))
|
||||
chat_request.top_k = int(gc.get("top_k", 1))
|
||||
|
||||
messages = []
|
||||
if history:
|
||||
|
||||
Reference in New Issue
Block a user