ollama接口设置增加<think>块忽略参数

This commit is contained in:
mcz
2025-05-01 23:41:08 +08:00
parent 7a772d2459
commit 471dc05897
4 changed files with 21 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ import {
import { sha256 } from "../libs/utils";
import interpreter from "../libs/interpreter";
import { msAuth } from "../libs/auth";
import {getSettingWithDefault } from "../libs/storage";
/**
* 同步数据
@@ -323,7 +324,8 @@ export const apiTranslate = async ({
case OPT_TRANS_OLLAMA:
case OPT_TRANS_OLLAMA_2:
case OPT_TRANS_OLLAMA_3:
const deepModels = ['deepseek-r1', 'qwen3'];
let deepModels = (await getSettingWithDefault()).transApis[translator]?.thinkIgnore || '';
deepModels = deepModels.split(',').filter(model => model.trim() !== '');
if (deepModels.some(model => res?.model?.startsWith(model))) {
trText = res?.response.replace(/<think>[\s\S]*<\/think>/i, '');
}else{

View File

@@ -186,6 +186,10 @@ export const I18N = {
zh: `最大并发请求数量 (1-100)`,
en: `Maximum Number Of Concurrent Requests (1-100)`,
},
think_ignore: {
zh: `忽略以下模型的<think>输出,逗号(,)分割`,
en: `Ignore the <think> block for the following models, comma (,) separated`,
},
fetch_interval: {
zh: `每次请求间隔时间 (0-5000ms)`,
en: `Time Between Requests (0-5000ms)`,

View File

@@ -541,6 +541,7 @@ const defaultOllamaApi = {
model: "llama3.1",
systemPrompt: `You are a professional, authentic machine translation engine.`,
userPrompt: `Translate the following source text from ${INPUT_PLACE_FROM} to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`,
thinkIgnore:`qwen3,deepseek-r1`,
fetchLimit: 1,
fetchInterval: 500,
};

View File

@@ -117,6 +117,7 @@ function ApiFields({ translator }) {
model = "",
systemPrompt = "",
userPrompt = "",
thinkIgnore = "",
fetchLimit = DEFAULT_FETCH_LIMIT,
fetchInterval = DEFAULT_FETCH_INTERVAL,
dictNo = "",
@@ -246,6 +247,18 @@ function ApiFields({ translator }) {
</>
)}
{(translator.startsWith(OPT_TRANS_OLLAMA)) && (
<>
<TextField
size="small"
label={i18n("think_ignore")}
name="thinkIgnore"
value={thinkIgnore}
onChange={handleChange}
/>
</>
)}
{(translator.startsWith(OPT_TRANS_OPENAI) ||
translator === OPT_TRANS_CLAUDE) && (
<>