-
Notifications
You must be signed in to change notification settings - Fork 49
Description
When using openAIChat with a custom BaseURL to connect to OpenAI-compatible endpoints (e.g., Google Gemini), the request fails because the toolbox always includes parameters like frequency_penalty, presence_penalty, and top_p in the request body — even at their default values (0, 0, 1).
Some OpenAI-compatible providers reject unknown fields. For example, Gemini returns:
Server returned error indicating: "Invalid JSON payload received. Unknown name "frequency_penalty": Cannot find field."
Steps to reproduce:
chat = openAIChat("You are a helpful assistant", ...
ModelName="gemini-2.5-flash", ...
APIKey=getenv("GEMINI_API_KEY"), ...
BaseURL="https://generativelanguage.googleapis.com/v1beta/openai");
messages = messageHistory;
messages = addUserMessage(messages, "Hello");
generate(chat, messages); Root cause:
In +llms/+internal/buildAzureParameters.m, the mapNVPToParameters loop (lines 48–52) includes any parameter where ~isempty(nvp.(opt)) is true. Since 0 and 1 are not empty, default values for frequency_penalty, presence_penalty, and top_p are always sent.
Suggested fix:
Skip parameters that are at their default/neutral values (e.g., frequency_penalty=0, presence_penalty=0, top_p=1) so they are omitted from the request body. Alternatively, provide an option to control which parameters are included in the request.
Environment:
- MATLAB R2025b
- LLMs with MATLAB v4.8.0