@chatluna/v1-shared-adapter 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.d.ts +6 -0
- package/lib/index.cjs +88 -17
- package/lib/index.mjs +86 -17
- package/lib/requester.d.ts +6 -0
- package/lib/utils.d.ts +2 -2
- package/package.json +6 -6
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
|
|
2
|
+
export type OpenAIReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
3
|
+
export declare function parseOpenAIModelNameWithReasoningEffort(modelName: string): {
|
|
4
|
+
model: string;
|
|
5
|
+
reasoningEffort?: OpenAIReasoningEffort;
|
|
6
|
+
};
|
|
7
|
+
export declare function normalizeOpenAIModelName(modelName: string): string;
|
|
2
8
|
export declare function isEmbeddingModel(modelName: string): boolean;
|
|
3
9
|
export declare function isNonLLMModel(modelName: string): boolean;
|
|
4
10
|
export declare function getModelMaxContextSize(info: ModelInfo): number;
|
package/lib/index.cjs
CHANGED
|
@@ -36,6 +36,8 @@ __export(index_exports, {
|
|
|
36
36
|
isNonLLMModel: () => isNonLLMModel,
|
|
37
37
|
langchainMessageToOpenAIMessage: () => langchainMessageToOpenAIMessage,
|
|
38
38
|
messageTypeToOpenAIRole: () => messageTypeToOpenAIRole,
|
|
39
|
+
normalizeOpenAIModelName: () => normalizeOpenAIModelName,
|
|
40
|
+
parseOpenAIModelNameWithReasoningEffort: () => parseOpenAIModelNameWithReasoningEffort,
|
|
39
41
|
processDeepSeekThinkMessages: () => processDeepSeekThinkMessages,
|
|
40
42
|
processReasoningContent: () => processReasoningContent,
|
|
41
43
|
processResponse: () => processResponse,
|
|
@@ -48,6 +50,35 @@ module.exports = __toCommonJS(index_exports);
|
|
|
48
50
|
|
|
49
51
|
// src/client.ts
|
|
50
52
|
var import_count_tokens = require("koishi-plugin-chatluna/llm-core/utils/count_tokens");
|
|
53
|
+
function parseOpenAIModelNameWithReasoningEffort(modelName) {
|
|
54
|
+
let model = modelName;
|
|
55
|
+
let reasoningEffort;
|
|
56
|
+
const explicitMatch = model.match(
|
|
57
|
+
/-(none|minimal|low|medium|high|xhigh|tiny)-thinking$/
|
|
58
|
+
);
|
|
59
|
+
if (explicitMatch?.[1]) {
|
|
60
|
+
const level = explicitMatch[1];
|
|
61
|
+
model = model.replace(`-${level}-thinking`, "");
|
|
62
|
+
reasoningEffort = level === "tiny" ? "minimal" : level;
|
|
63
|
+
return { model, reasoningEffort };
|
|
64
|
+
}
|
|
65
|
+
if (model.endsWith("-non-thinking")) {
|
|
66
|
+
model = model.slice(0, -"-non-thinking".length);
|
|
67
|
+
reasoningEffort = "none";
|
|
68
|
+
return { model, reasoningEffort };
|
|
69
|
+
}
|
|
70
|
+
if (model.endsWith("-thinking")) {
|
|
71
|
+
model = model.slice(0, -"-thinking".length);
|
|
72
|
+
reasoningEffort = "medium";
|
|
73
|
+
return { model, reasoningEffort };
|
|
74
|
+
}
|
|
75
|
+
return { model };
|
|
76
|
+
}
|
|
77
|
+
__name(parseOpenAIModelNameWithReasoningEffort, "parseOpenAIModelNameWithReasoningEffort");
|
|
78
|
+
function normalizeOpenAIModelName(modelName) {
|
|
79
|
+
return parseOpenAIModelNameWithReasoningEffort(modelName).model;
|
|
80
|
+
}
|
|
81
|
+
__name(normalizeOpenAIModelName, "normalizeOpenAIModelName");
|
|
51
82
|
function isEmbeddingModel(modelName) {
|
|
52
83
|
return modelName.includes("embed") || modelName.includes("bge") || modelName.includes("instructor-large") || modelName.includes("m3e");
|
|
53
84
|
}
|
|
@@ -66,7 +97,7 @@ function getModelMaxContextSize(info) {
|
|
|
66
97
|
if (maxTokens != null) {
|
|
67
98
|
return maxTokens;
|
|
68
99
|
}
|
|
69
|
-
const modelName = info.name;
|
|
100
|
+
const modelName = normalizeOpenAIModelName(info.name);
|
|
70
101
|
if (modelName.startsWith("gpt") || modelName.startsWith("o1") || modelName.startsWith("o3") || modelName.startsWith("o4")) {
|
|
71
102
|
return (0, import_count_tokens.getModelContextSize)(modelName);
|
|
72
103
|
}
|
|
@@ -128,7 +159,7 @@ var imageModelMatchers = [
|
|
|
128
159
|
"grok-4"
|
|
129
160
|
].map((pattern) => createGlobMatcher(pattern));
|
|
130
161
|
function supportImageInput(modelName) {
|
|
131
|
-
const lowerModel = modelName.toLowerCase();
|
|
162
|
+
const lowerModel = normalizeOpenAIModelName(modelName).toLowerCase();
|
|
132
163
|
return imageModelMatchers.some((matcher) => matcher(lowerModel));
|
|
133
164
|
}
|
|
134
165
|
__name(supportImageInput, "supportImageInput");
|
|
@@ -145,7 +176,8 @@ var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
|
145
176
|
var import_types = require("@langchain/core/utils/types");
|
|
146
177
|
async function langchainMessageToOpenAIMessage(messages, plugin, model, supportImageInput2, removeSystemMessage) {
|
|
147
178
|
const result = [];
|
|
148
|
-
const
|
|
179
|
+
const normalizedModel = model ? normalizeOpenAIModelName(model) : model;
|
|
180
|
+
const isDeepseekThinkModel = normalizedModel?.includes("deepseek-reasoner");
|
|
149
181
|
for (const rawMessage of messages) {
|
|
150
182
|
const role = messageTypeToOpenAIRole(rawMessage.getType());
|
|
151
183
|
const msg = {
|
|
@@ -175,8 +207,8 @@ async function langchainMessageToOpenAIMessage(messages, plugin, model, supportI
|
|
|
175
207
|
}
|
|
176
208
|
}
|
|
177
209
|
const images = rawMessage.additional_kwargs.images;
|
|
178
|
-
const lowerModel =
|
|
179
|
-
if ((lowerModel?.includes("vision") || lowerModel?.includes("gpt-4o") || lowerModel?.includes("claude") || lowerModel?.includes("gemini") || lowerModel?.includes("qwen-vl") || lowerModel?.includes("omni") || lowerModel?.includes("qwen2.5-vl") || lowerModel?.includes("qwen2.5-omni") || lowerModel?.includes("qwen-omni") || lowerModel?.includes("qwen2-vl") || lowerModel?.includes("qvq") ||
|
|
210
|
+
const lowerModel = normalizedModel?.toLowerCase() ?? "";
|
|
211
|
+
if ((lowerModel?.includes("vision") || lowerModel?.includes("gpt-4o") || lowerModel?.includes("claude") || lowerModel?.includes("gemini") || lowerModel?.includes("qwen-vl") || lowerModel?.includes("omni") || lowerModel?.includes("qwen2.5-vl") || lowerModel?.includes("qwen2.5-omni") || lowerModel?.includes("qwen-omni") || lowerModel?.includes("qwen2-vl") || lowerModel?.includes("qvq") || normalizedModel?.includes("o1") || normalizedModel?.includes("o4") || normalizedModel?.includes("o3") || normalizedModel?.includes("gpt-4.1") || normalizedModel?.includes("gpt-5") || supportImageInput2) && images != null) {
|
|
180
212
|
msg.content = [
|
|
181
213
|
{
|
|
182
214
|
type: "text",
|
|
@@ -229,16 +261,13 @@ function processDeepSeekThinkMessages(convertedMessages, originalMessages) {
|
|
|
229
261
|
let lastTurnStartIndex = -1;
|
|
230
262
|
for (let i = originalMessages.length - 1; i >= 0; i--) {
|
|
231
263
|
const message = originalMessages[i];
|
|
232
|
-
if (message.getType() === "
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
lastTurnStartIndex = i;
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
264
|
+
if (message.getType() === "human") {
|
|
265
|
+
lastTurnStartIndex = i;
|
|
266
|
+
break;
|
|
238
267
|
}
|
|
239
268
|
}
|
|
240
269
|
if (lastTurnStartIndex === -1) {
|
|
241
|
-
|
|
270
|
+
lastTurnStartIndex = 0;
|
|
242
271
|
}
|
|
243
272
|
return convertedMessages.map((message, index) => {
|
|
244
273
|
if (index >= lastTurnStartIndex) {
|
|
@@ -473,12 +502,14 @@ var import_string2 = require("koishi-plugin-chatluna/utils/string");
|
|
|
473
502
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
474
503
|
var import_object = require("koishi-plugin-chatluna/utils/object");
|
|
475
504
|
async function buildChatCompletionParams(params, plugin, enableGoogleSearch, supportImageInput2) {
|
|
505
|
+
const parsedModel = parseOpenAIModelNameWithReasoningEffort(params.model);
|
|
506
|
+
const normalizedModel = parsedModel.model;
|
|
476
507
|
const base = {
|
|
477
|
-
model:
|
|
508
|
+
model: normalizedModel,
|
|
478
509
|
messages: await langchainMessageToOpenAIMessage(
|
|
479
510
|
params.input,
|
|
480
511
|
plugin,
|
|
481
|
-
|
|
512
|
+
normalizedModel,
|
|
482
513
|
supportImageInput2
|
|
483
514
|
),
|
|
484
515
|
tools: enableGoogleSearch || params.tools != null ? formatToolsToOpenAITools(
|
|
@@ -486,20 +517,28 @@ async function buildChatCompletionParams(params, plugin, enableGoogleSearch, sup
|
|
|
486
517
|
enableGoogleSearch
|
|
487
518
|
) : void 0,
|
|
488
519
|
stop: params.stop || void 0,
|
|
489
|
-
max_tokens:
|
|
520
|
+
max_tokens: normalizedModel.includes("vision") ? void 0 : params.maxTokens,
|
|
490
521
|
temperature: params.temperature === 0 ? void 0 : params.temperature,
|
|
491
522
|
presence_penalty: params.presencePenalty === 0 ? void 0 : params.presencePenalty,
|
|
492
523
|
frequency_penalty: params.frequencyPenalty === 0 ? void 0 : params.frequencyPenalty,
|
|
493
524
|
n: params.n,
|
|
494
525
|
top_p: params.topP,
|
|
495
526
|
prompt_cache_key: params.id,
|
|
527
|
+
prompt_cache_retention: void 0,
|
|
528
|
+
prediction: void 0,
|
|
529
|
+
reasoning_effort: parsedModel.reasoningEffort,
|
|
530
|
+
response_format: void 0,
|
|
531
|
+
safety_identifier: void 0,
|
|
532
|
+
service_tier: void 0,
|
|
496
533
|
stream: true,
|
|
497
534
|
logit_bias: params.logitBias,
|
|
498
535
|
stream_options: {
|
|
499
536
|
include_usage: true
|
|
500
537
|
}
|
|
501
538
|
};
|
|
502
|
-
|
|
539
|
+
const lowerModel = normalizedModel.toLowerCase();
|
|
540
|
+
const isOpenAIReasoningModel = lowerModel.startsWith("o1") || lowerModel.startsWith("o3") || lowerModel.startsWith("o4") || lowerModel.startsWith("gpt-5");
|
|
541
|
+
if (isOpenAIReasoningModel) {
|
|
503
542
|
delete base.temperature;
|
|
504
543
|
delete base.presence_penalty;
|
|
505
544
|
delete base.frequency_penalty;
|
|
@@ -738,7 +777,37 @@ async function getModels(requestContext, config) {
|
|
|
738
777
|
);
|
|
739
778
|
data = await response.text();
|
|
740
779
|
data = JSON.parse(data);
|
|
741
|
-
|
|
780
|
+
const rawModels = data.data.map((model) => model.id);
|
|
781
|
+
const expanded = [];
|
|
782
|
+
const seen = /* @__PURE__ */ new Set();
|
|
783
|
+
const isOpenAIReasoningModel = /* @__PURE__ */ __name((model) => {
|
|
784
|
+
const lower = model.toLowerCase();
|
|
785
|
+
return lower.startsWith("gpt-5") || lower.startsWith("o1") || lower.startsWith("o3") || lower.startsWith("o4");
|
|
786
|
+
}, "isOpenAIReasoningModel");
|
|
787
|
+
const hasThinkingTag = /* @__PURE__ */ __name((model) => {
|
|
788
|
+
const lower = model.toLowerCase();
|
|
789
|
+
return lower.includes("thinking") || ["minimal", "low", "medium", "high", "xhigh"].some(
|
|
790
|
+
(level) => lower.includes(level)
|
|
791
|
+
);
|
|
792
|
+
}, "hasThinkingTag");
|
|
793
|
+
const push = /* @__PURE__ */ __name((model) => {
|
|
794
|
+
if (seen.has(model)) return;
|
|
795
|
+
seen.add(model);
|
|
796
|
+
expanded.push(model);
|
|
797
|
+
}, "push");
|
|
798
|
+
for (const model of rawModels) {
|
|
799
|
+
push(model);
|
|
800
|
+
if (!isOpenAIReasoningModel(model)) continue;
|
|
801
|
+
if (hasThinkingTag(model)) continue;
|
|
802
|
+
push(`${model}-non-thinking`);
|
|
803
|
+
push(`${model}`);
|
|
804
|
+
push(`${model}-minimal-thinking`);
|
|
805
|
+
push(`${model}-low-thinking`);
|
|
806
|
+
push(`${model}-medium-thinking`);
|
|
807
|
+
push(`${model}-high-thinking`);
|
|
808
|
+
push(`${model}-xhigh-thinking`);
|
|
809
|
+
}
|
|
810
|
+
return expanded;
|
|
742
811
|
} catch (e) {
|
|
743
812
|
if (e instanceof import_error.ChatLunaError) {
|
|
744
813
|
throw e;
|
|
@@ -771,6 +840,8 @@ __name(createRequestContext, "createRequestContext");
|
|
|
771
840
|
isNonLLMModel,
|
|
772
841
|
langchainMessageToOpenAIMessage,
|
|
773
842
|
messageTypeToOpenAIRole,
|
|
843
|
+
normalizeOpenAIModelName,
|
|
844
|
+
parseOpenAIModelNameWithReasoningEffort,
|
|
774
845
|
processDeepSeekThinkMessages,
|
|
775
846
|
processReasoningContent,
|
|
776
847
|
processResponse,
|
package/lib/index.mjs
CHANGED
|
@@ -3,6 +3,35 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/client.ts
|
|
5
5
|
import { getModelContextSize } from "koishi-plugin-chatluna/llm-core/utils/count_tokens";
|
|
6
|
+
function parseOpenAIModelNameWithReasoningEffort(modelName) {
|
|
7
|
+
let model = modelName;
|
|
8
|
+
let reasoningEffort;
|
|
9
|
+
const explicitMatch = model.match(
|
|
10
|
+
/-(none|minimal|low|medium|high|xhigh|tiny)-thinking$/
|
|
11
|
+
);
|
|
12
|
+
if (explicitMatch?.[1]) {
|
|
13
|
+
const level = explicitMatch[1];
|
|
14
|
+
model = model.replace(`-${level}-thinking`, "");
|
|
15
|
+
reasoningEffort = level === "tiny" ? "minimal" : level;
|
|
16
|
+
return { model, reasoningEffort };
|
|
17
|
+
}
|
|
18
|
+
if (model.endsWith("-non-thinking")) {
|
|
19
|
+
model = model.slice(0, -"-non-thinking".length);
|
|
20
|
+
reasoningEffort = "none";
|
|
21
|
+
return { model, reasoningEffort };
|
|
22
|
+
}
|
|
23
|
+
if (model.endsWith("-thinking")) {
|
|
24
|
+
model = model.slice(0, -"-thinking".length);
|
|
25
|
+
reasoningEffort = "medium";
|
|
26
|
+
return { model, reasoningEffort };
|
|
27
|
+
}
|
|
28
|
+
return { model };
|
|
29
|
+
}
|
|
30
|
+
__name(parseOpenAIModelNameWithReasoningEffort, "parseOpenAIModelNameWithReasoningEffort");
|
|
31
|
+
function normalizeOpenAIModelName(modelName) {
|
|
32
|
+
return parseOpenAIModelNameWithReasoningEffort(modelName).model;
|
|
33
|
+
}
|
|
34
|
+
__name(normalizeOpenAIModelName, "normalizeOpenAIModelName");
|
|
6
35
|
function isEmbeddingModel(modelName) {
|
|
7
36
|
return modelName.includes("embed") || modelName.includes("bge") || modelName.includes("instructor-large") || modelName.includes("m3e");
|
|
8
37
|
}
|
|
@@ -21,7 +50,7 @@ function getModelMaxContextSize(info) {
|
|
|
21
50
|
if (maxTokens != null) {
|
|
22
51
|
return maxTokens;
|
|
23
52
|
}
|
|
24
|
-
const modelName = info.name;
|
|
53
|
+
const modelName = normalizeOpenAIModelName(info.name);
|
|
25
54
|
if (modelName.startsWith("gpt") || modelName.startsWith("o1") || modelName.startsWith("o3") || modelName.startsWith("o4")) {
|
|
26
55
|
return getModelContextSize(modelName);
|
|
27
56
|
}
|
|
@@ -83,7 +112,7 @@ var imageModelMatchers = [
|
|
|
83
112
|
"grok-4"
|
|
84
113
|
].map((pattern) => createGlobMatcher(pattern));
|
|
85
114
|
function supportImageInput(modelName) {
|
|
86
|
-
const lowerModel = modelName.toLowerCase();
|
|
115
|
+
const lowerModel = normalizeOpenAIModelName(modelName).toLowerCase();
|
|
87
116
|
return imageModelMatchers.some((matcher) => matcher(lowerModel));
|
|
88
117
|
}
|
|
89
118
|
__name(supportImageInput, "supportImageInput");
|
|
@@ -113,7 +142,8 @@ import {
|
|
|
113
142
|
import { isZodSchemaV3 } from "@langchain/core/utils/types";
|
|
114
143
|
async function langchainMessageToOpenAIMessage(messages, plugin, model, supportImageInput2, removeSystemMessage) {
|
|
115
144
|
const result = [];
|
|
116
|
-
const
|
|
145
|
+
const normalizedModel = model ? normalizeOpenAIModelName(model) : model;
|
|
146
|
+
const isDeepseekThinkModel = normalizedModel?.includes("deepseek-reasoner");
|
|
117
147
|
for (const rawMessage of messages) {
|
|
118
148
|
const role = messageTypeToOpenAIRole(rawMessage.getType());
|
|
119
149
|
const msg = {
|
|
@@ -143,8 +173,8 @@ async function langchainMessageToOpenAIMessage(messages, plugin, model, supportI
|
|
|
143
173
|
}
|
|
144
174
|
}
|
|
145
175
|
const images = rawMessage.additional_kwargs.images;
|
|
146
|
-
const lowerModel =
|
|
147
|
-
if ((lowerModel?.includes("vision") || lowerModel?.includes("gpt-4o") || lowerModel?.includes("claude") || lowerModel?.includes("gemini") || lowerModel?.includes("qwen-vl") || lowerModel?.includes("omni") || lowerModel?.includes("qwen2.5-vl") || lowerModel?.includes("qwen2.5-omni") || lowerModel?.includes("qwen-omni") || lowerModel?.includes("qwen2-vl") || lowerModel?.includes("qvq") ||
|
|
176
|
+
const lowerModel = normalizedModel?.toLowerCase() ?? "";
|
|
177
|
+
if ((lowerModel?.includes("vision") || lowerModel?.includes("gpt-4o") || lowerModel?.includes("claude") || lowerModel?.includes("gemini") || lowerModel?.includes("qwen-vl") || lowerModel?.includes("omni") || lowerModel?.includes("qwen2.5-vl") || lowerModel?.includes("qwen2.5-omni") || lowerModel?.includes("qwen-omni") || lowerModel?.includes("qwen2-vl") || lowerModel?.includes("qvq") || normalizedModel?.includes("o1") || normalizedModel?.includes("o4") || normalizedModel?.includes("o3") || normalizedModel?.includes("gpt-4.1") || normalizedModel?.includes("gpt-5") || supportImageInput2) && images != null) {
|
|
148
178
|
msg.content = [
|
|
149
179
|
{
|
|
150
180
|
type: "text",
|
|
@@ -197,16 +227,13 @@ function processDeepSeekThinkMessages(convertedMessages, originalMessages) {
|
|
|
197
227
|
let lastTurnStartIndex = -1;
|
|
198
228
|
for (let i = originalMessages.length - 1; i >= 0; i--) {
|
|
199
229
|
const message = originalMessages[i];
|
|
200
|
-
if (message.getType() === "
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
lastTurnStartIndex = i;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
230
|
+
if (message.getType() === "human") {
|
|
231
|
+
lastTurnStartIndex = i;
|
|
232
|
+
break;
|
|
206
233
|
}
|
|
207
234
|
}
|
|
208
235
|
if (lastTurnStartIndex === -1) {
|
|
209
|
-
|
|
236
|
+
lastTurnStartIndex = 0;
|
|
210
237
|
}
|
|
211
238
|
return convertedMessages.map((message, index) => {
|
|
212
239
|
if (index >= lastTurnStartIndex) {
|
|
@@ -441,12 +468,14 @@ import { getMessageContent } from "koishi-plugin-chatluna/utils/string";
|
|
|
441
468
|
import { trackLogToLocal } from "koishi-plugin-chatluna/utils/logger";
|
|
442
469
|
import { deepAssign } from "koishi-plugin-chatluna/utils/object";
|
|
443
470
|
async function buildChatCompletionParams(params, plugin, enableGoogleSearch, supportImageInput2) {
|
|
471
|
+
const parsedModel = parseOpenAIModelNameWithReasoningEffort(params.model);
|
|
472
|
+
const normalizedModel = parsedModel.model;
|
|
444
473
|
const base = {
|
|
445
|
-
model:
|
|
474
|
+
model: normalizedModel,
|
|
446
475
|
messages: await langchainMessageToOpenAIMessage(
|
|
447
476
|
params.input,
|
|
448
477
|
plugin,
|
|
449
|
-
|
|
478
|
+
normalizedModel,
|
|
450
479
|
supportImageInput2
|
|
451
480
|
),
|
|
452
481
|
tools: enableGoogleSearch || params.tools != null ? formatToolsToOpenAITools(
|
|
@@ -454,20 +483,28 @@ async function buildChatCompletionParams(params, plugin, enableGoogleSearch, sup
|
|
|
454
483
|
enableGoogleSearch
|
|
455
484
|
) : void 0,
|
|
456
485
|
stop: params.stop || void 0,
|
|
457
|
-
max_tokens:
|
|
486
|
+
max_tokens: normalizedModel.includes("vision") ? void 0 : params.maxTokens,
|
|
458
487
|
temperature: params.temperature === 0 ? void 0 : params.temperature,
|
|
459
488
|
presence_penalty: params.presencePenalty === 0 ? void 0 : params.presencePenalty,
|
|
460
489
|
frequency_penalty: params.frequencyPenalty === 0 ? void 0 : params.frequencyPenalty,
|
|
461
490
|
n: params.n,
|
|
462
491
|
top_p: params.topP,
|
|
463
492
|
prompt_cache_key: params.id,
|
|
493
|
+
prompt_cache_retention: void 0,
|
|
494
|
+
prediction: void 0,
|
|
495
|
+
reasoning_effort: parsedModel.reasoningEffort,
|
|
496
|
+
response_format: void 0,
|
|
497
|
+
safety_identifier: void 0,
|
|
498
|
+
service_tier: void 0,
|
|
464
499
|
stream: true,
|
|
465
500
|
logit_bias: params.logitBias,
|
|
466
501
|
stream_options: {
|
|
467
502
|
include_usage: true
|
|
468
503
|
}
|
|
469
504
|
};
|
|
470
|
-
|
|
505
|
+
const lowerModel = normalizedModel.toLowerCase();
|
|
506
|
+
const isOpenAIReasoningModel = lowerModel.startsWith("o1") || lowerModel.startsWith("o3") || lowerModel.startsWith("o4") || lowerModel.startsWith("gpt-5");
|
|
507
|
+
if (isOpenAIReasoningModel) {
|
|
471
508
|
delete base.temperature;
|
|
472
509
|
delete base.presence_penalty;
|
|
473
510
|
delete base.frequency_penalty;
|
|
@@ -706,7 +743,37 @@ async function getModels(requestContext, config) {
|
|
|
706
743
|
);
|
|
707
744
|
data = await response.text();
|
|
708
745
|
data = JSON.parse(data);
|
|
709
|
-
|
|
746
|
+
const rawModels = data.data.map((model) => model.id);
|
|
747
|
+
const expanded = [];
|
|
748
|
+
const seen = /* @__PURE__ */ new Set();
|
|
749
|
+
const isOpenAIReasoningModel = /* @__PURE__ */ __name((model) => {
|
|
750
|
+
const lower = model.toLowerCase();
|
|
751
|
+
return lower.startsWith("gpt-5") || lower.startsWith("o1") || lower.startsWith("o3") || lower.startsWith("o4");
|
|
752
|
+
}, "isOpenAIReasoningModel");
|
|
753
|
+
const hasThinkingTag = /* @__PURE__ */ __name((model) => {
|
|
754
|
+
const lower = model.toLowerCase();
|
|
755
|
+
return lower.includes("thinking") || ["minimal", "low", "medium", "high", "xhigh"].some(
|
|
756
|
+
(level) => lower.includes(level)
|
|
757
|
+
);
|
|
758
|
+
}, "hasThinkingTag");
|
|
759
|
+
const push = /* @__PURE__ */ __name((model) => {
|
|
760
|
+
if (seen.has(model)) return;
|
|
761
|
+
seen.add(model);
|
|
762
|
+
expanded.push(model);
|
|
763
|
+
}, "push");
|
|
764
|
+
for (const model of rawModels) {
|
|
765
|
+
push(model);
|
|
766
|
+
if (!isOpenAIReasoningModel(model)) continue;
|
|
767
|
+
if (hasThinkingTag(model)) continue;
|
|
768
|
+
push(`${model}-non-thinking`);
|
|
769
|
+
push(`${model}`);
|
|
770
|
+
push(`${model}-minimal-thinking`);
|
|
771
|
+
push(`${model}-low-thinking`);
|
|
772
|
+
push(`${model}-medium-thinking`);
|
|
773
|
+
push(`${model}-high-thinking`);
|
|
774
|
+
push(`${model}-xhigh-thinking`);
|
|
775
|
+
}
|
|
776
|
+
return expanded;
|
|
710
777
|
} catch (e) {
|
|
711
778
|
if (e instanceof ChatLunaError) {
|
|
712
779
|
throw e;
|
|
@@ -738,6 +805,8 @@ export {
|
|
|
738
805
|
isNonLLMModel,
|
|
739
806
|
langchainMessageToOpenAIMessage,
|
|
740
807
|
messageTypeToOpenAIRole,
|
|
808
|
+
normalizeOpenAIModelName,
|
|
809
|
+
parseOpenAIModelNameWithReasoningEffort,
|
|
741
810
|
processDeepSeekThinkMessages,
|
|
742
811
|
processReasoningContent,
|
|
743
812
|
processResponse,
|
package/lib/requester.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export declare function buildChatCompletionParams(params: ModelRequestParams, pl
|
|
|
25
25
|
n: number;
|
|
26
26
|
top_p: number;
|
|
27
27
|
prompt_cache_key: string;
|
|
28
|
+
prompt_cache_retention: any;
|
|
29
|
+
prediction: any;
|
|
30
|
+
reasoning_effort: import("./client").OpenAIReasoningEffort;
|
|
31
|
+
response_format: any;
|
|
32
|
+
safety_identifier: any;
|
|
33
|
+
service_tier: any;
|
|
28
34
|
stream: boolean;
|
|
29
35
|
logit_bias: Record<string, number>;
|
|
30
36
|
stream_options: {
|
package/lib/utils.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ export declare function messageTypeToOpenAIRole(type: MessageType): ChatCompleti
|
|
|
11
11
|
export declare function formatToolsToOpenAITools(tools: StructuredTool[], includeGoogleSearch: boolean): ChatCompletionTool[];
|
|
12
12
|
export declare function formatToolToOpenAITool(tool: StructuredTool): ChatCompletionTool;
|
|
13
13
|
export declare function removeAdditionalProperties(schema: JsonSchema7Type): JsonSchema7Type;
|
|
14
|
-
export declare function convertMessageToMessageChunk(message: ChatCompletionResponseMessage):
|
|
15
|
-
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum):
|
|
14
|
+
export declare function convertMessageToMessageChunk(message: ChatCompletionResponseMessage): AIMessageChunk | HumanMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
|
15
|
+
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): AIMessageChunk | HumanMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatluna/v1-shared-adapter",
|
|
3
3
|
"description": "chatluna shared adapter",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.21",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"node": ">=18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"resolutions": {
|
|
39
|
-
"@langchain/core": "0.3.
|
|
39
|
+
"@langchain/core": "^0.3.80",
|
|
40
40
|
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.21"
|
|
41
41
|
},
|
|
42
42
|
"overrides": {
|
|
43
|
-
"@langchain/core": "0.3.
|
|
43
|
+
"@langchain/core": "^0.3.80",
|
|
44
44
|
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.21"
|
|
45
45
|
},
|
|
46
46
|
"pnpm": {
|
|
47
47
|
"overrides": {
|
|
48
|
-
"@langchain/core": "0.3.
|
|
48
|
+
"@langchain/core": "^0.3.80",
|
|
49
49
|
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.21"
|
|
50
50
|
}
|
|
51
51
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"adapter"
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@langchain/core": "0.3.
|
|
63
|
+
"@langchain/core": "^0.3.80",
|
|
64
64
|
"zod": "3.25.76",
|
|
65
65
|
"zod-to-json-schema": "^3.24.6"
|
|
66
66
|
},
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"koishi": "^4.18.9",
|
|
73
|
-
"koishi-plugin-chatluna": "^1.3.
|
|
73
|
+
"koishi-plugin-chatluna": "^1.3.8"
|
|
74
74
|
}
|
|
75
75
|
}
|