Moonshot: Map "Request reasoning" to thinking type Fixes #5072

10e8e01a554d1f4fc6b0a358e03b65ab0e84bc76

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +17 -2Showing whitespace changes
public/index.html+1 -1
@@ -2105,7 +2105,7 @@
21052105 <span data-i18n="Allows the model to return its thinking process.">
21062106 Allows the model to return its thinking process.
21072107 </span>
21082108 <strong data-i18n="This setting affects visibility only." data-source-mode="except" data-source="zai,moonshot">
21092109 This setting affects visibility only.
21102110 </strong>
21112111 </div>
public/scripts/openai.js+11 -0
@@ -2736,6 +2736,17 @@ export async function createGenerationParameters(settings, model, type, messages
27362736 generate_data.top_a = Number(settings.top_a_openai);
27372737 }
27382738
2739+ // https://platform.moonshot.ai/docs/api/chat#public-service-address
2740+ if (settings.chat_completion_source === chat_completion_sources.MOONSHOT) {
2741+ // >Kimi API is fully compatible with OpenAI's API format
2742+ if (/kimi-k2.5/.test(model)) {
2743+ delete generate_data.temperature;
2744+ delete generate_data.top_p;
2745+ delete generate_data.frequency_penalty;
2746+ delete generate_data.presence_penalty;
2747+ }
2748+ }
2749+
27392750 if (seedSupportedSources.includes(settings.chat_completion_source) && settings.seed >= 0) {
27402751 generate_data.seed = settings.seed;
27412752 }
src/endpoints/backends/chat-completions.js+5 -1
@@ -2262,7 +2262,11 @@ router.post('/generate', async function (request, response) {
22622262 apiUrl = new URL(request.body.reverse_proxy || API_MOONSHOT).toString();
22632263 apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT);
22642264 headers = {};
22652265 bodyParams = {};
2266+ thinking: {
2267+ type: request.body.include_reasoning ? 'enabled' : 'disabled',
2268+ },
2269+ };
22662270 request.body.json_schema
22672271 ? setJsonObjectFormat(bodyParams, request.body.messages, request.body.json_schema)
22682272 : addAssistantPrefix(request.body.messages, [], 'partial');