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 @@
2105 <span data-i18n="Allows the model to return its thinking process.">2105 <span data-i18n="Allows the model to return its thinking process.">
2106 Allows the model to return its thinking process.2106 Allows the model to return its thinking process.
2107 </span>2107 </span>
2108 <strong data-i18n="This setting affects visibility only." data-source-mode="except" data-source="zai">2108 <strong data-i18n="This setting affects visibility only." data-source-mode="except" data-source="zai,moonshot">
2109 This setting affects visibility only.2109 This setting affects visibility only.
2110 </strong>2110 </strong>
2111 </div>2111 </div>
public/scripts/openai.js+11 -0
@@ -2736,6 +2736,17 @@ export async function createGenerationParameters(settings, model, type, messages
2736 generate_data.top_a = Number(settings.top_a_openai);2736 generate_data.top_a = Number(settings.top_a_openai);
2737 }2737 }
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
2739 if (seedSupportedSources.includes(settings.chat_completion_source) && settings.seed >= 0) {2750 if (seedSupportedSources.includes(settings.chat_completion_source) && settings.seed >= 0) {
2740 generate_data.seed = settings.seed;2751 generate_data.seed = settings.seed;
2741 }2752 }
src/endpoints/backends/chat-completions.js+5 -1
@@ -2262,7 +2262,11 @@ router.post('/generate', async function (request, response) {
2262 apiUrl = new URL(request.body.reverse_proxy || API_MOONSHOT).toString();2262 apiUrl = new URL(request.body.reverse_proxy || API_MOONSHOT).toString();
2263 apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT);2263 apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MOONSHOT);
2264 headers = {};2264 headers = {};
2265 bodyParams = {};2265 bodyParams = {
2266 thinking: {
2267 type: request.body.include_reasoning ? 'enabled' : 'disabled',
2268 },
2269 };
2266 request.body.json_schema2270 request.body.json_schema
2267 ? setJsonObjectFormat(bodyParams, request.body.messages, request.body.json_schema)2271 ? setJsonObjectFormat(bodyParams, request.body.messages, request.body.json_schema)
2268 : addAssistantPrefix(request.body.messages, [], 'partial');2272 : addAssistantPrefix(request.body.messages, [], 'partial');