feat: Add AI API Custom Params

This commit is contained in:
FlyLoongZ
2025-08-11 12:12:03 +08:00
parent 39b3b00117
commit be6e34ba52
4 changed files with 44 additions and 0 deletions

View File

@@ -240,6 +240,7 @@ const genOpenAI = ({
model,
temperature,
maxTokens,
apiCustomParams,
}) => {
// 兼容历史上作为systemPrompt的prompt如果prompt中不包含带翻译文本则添加文本到prompt末尾
// if (!prompt.includes(INPUT_PLACE_TEXT)) {
@@ -254,6 +255,8 @@ const genOpenAI = ({
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text);
apiCustomParams = JSON.parse("{" + apiCustomParams + "}");
const data = {
model,
messages: [
@@ -268,6 +271,7 @@ const genOpenAI = ({
],
temperature,
max_completion_tokens: maxTokens,
...apiCustomParams,
};
const init = {
@@ -294,6 +298,7 @@ const genGemini = ({
model,
temperature,
maxTokens,
apiCustomParams,
}) => {
url = url
.replaceAll(INPUT_PLACE_MODEL, model)
@@ -307,6 +312,8 @@ const genGemini = ({
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text);
apiCustomParams = JSON.parse("{" + apiCustomParams + "}");
const data = {
system_instruction: {
parts: {
@@ -325,6 +332,7 @@ const genGemini = ({
// topP: 0.8,
// topK: 10,
},
...apiCustomParams,
};
const init = {
@@ -349,6 +357,7 @@ const genGemini2 = ({
model,
temperature,
maxTokens,
apiCustomParams,
}) => {
systemPrompt = systemPrompt
.replaceAll(INPUT_PLACE_FROM, from)
@@ -359,6 +368,8 @@ const genGemini2 = ({
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text);
apiCustomParams = JSON.parse("{" + apiCustomParams + "}");
const data = {
model,
messages: [
@@ -373,6 +384,7 @@ const genGemini2 = ({
],
temperature,
max_tokens: maxTokens,
...apiCustomParams,
};
const init = {
@@ -398,6 +410,7 @@ const genClaude = ({
model,
temperature,
maxTokens,
apiCustomParams,
}) => {
systemPrompt = systemPrompt
.replaceAll(INPUT_PLACE_FROM, from)
@@ -408,6 +421,8 @@ const genClaude = ({
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text);
apiCustomParams = JSON.parse("{" + apiCustomParams + "}");
const data = {
model,
system: systemPrompt,
@@ -419,6 +434,7 @@ const genClaude = ({
],
temperature,
max_tokens: maxTokens,
...apiCustomParams,
};
const init = {
@@ -444,6 +460,7 @@ const genOllama = ({
systemPrompt,
userPrompt,
model,
apiCustomParams,
}) => {
systemPrompt = systemPrompt
.replaceAll(INPUT_PLACE_FROM, from)
@@ -454,12 +471,15 @@ const genOllama = ({
.replaceAll(INPUT_PLACE_TO, to)
.replaceAll(INPUT_PLACE_TEXT, text);
apiCustomParams = JSON.parse("{" + apiCustomParams + "}");
const data = {
model,
system: systemPrompt,
prompt: userPrompt,
think: think,
stream: false,
...apiCustomParams,
};
const init = {