@chatluna/v1-shared-adapter 1.0.34 → 1.0.36
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 +1 -0
- package/lib/index.cjs +74 -11
- package/lib/index.mjs +72 -11
- package/lib/requester.d.ts +3 -2
- package/lib/types.d.ts +24 -0
- package/package.json +2 -2
package/lib/client.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare function normalizeOpenAIModelName(modelName: string): string;
|
|
|
10
10
|
export declare function isEmbeddingModel(modelName: string): boolean;
|
|
11
11
|
export declare function isNonLLMModel(modelName: string): boolean;
|
|
12
12
|
export declare function isImageGenerationModel(modelName: string): boolean;
|
|
13
|
+
export declare function isRerankerModel(modelName: string): boolean;
|
|
13
14
|
export declare function getModelMaxContextSize(info: ModelInfo): number;
|
|
14
15
|
export declare function supportImageInput(modelName: string): boolean;
|
package/lib/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(index_exports, {
|
|
|
28
28
|
convertMessageToMessageChunk: () => convertMessageToMessageChunk,
|
|
29
29
|
createEmbeddings: () => createEmbeddings,
|
|
30
30
|
createRequestContext: () => createRequestContext,
|
|
31
|
+
createRerank: () => createRerank,
|
|
31
32
|
createUsageMetadata: () => createUsageMetadata,
|
|
32
33
|
expandReasoningEffortModelVariants: () => expandReasoningEffortModelVariants,
|
|
33
34
|
fetchFileLikeUrl: () => fetchFileLikeUrl,
|
|
@@ -40,6 +41,7 @@ __export(index_exports, {
|
|
|
40
41
|
isEmbeddingModel: () => isEmbeddingModel,
|
|
41
42
|
isImageGenerationModel: () => isImageGenerationModel,
|
|
42
43
|
isNonLLMModel: () => isNonLLMModel,
|
|
44
|
+
isRerankerModel: () => isRerankerModel,
|
|
43
45
|
langchainMessageToOpenAIMessage: () => langchainMessageToOpenAIMessage,
|
|
44
46
|
langchainMessageToResponseInput: () => langchainMessageToResponseInput,
|
|
45
47
|
messageTypeToOpenAIRole: () => messageTypeToOpenAIRole,
|
|
@@ -118,7 +120,7 @@ function isNonLLMModel(modelName) {
|
|
|
118
120
|
if (modelName.includes("gemini") && modelName.includes("image")) {
|
|
119
121
|
return false;
|
|
120
122
|
}
|
|
121
|
-
return ["whisper", "tts", "dall-e", "image"
|
|
123
|
+
return ["whisper", "tts", "dall-e", "image"].some(
|
|
122
124
|
(keyword) => modelName.includes(keyword)
|
|
123
125
|
);
|
|
124
126
|
}
|
|
@@ -127,6 +129,10 @@ function isImageGenerationModel(modelName) {
|
|
|
127
129
|
return isNonLLMModel(modelName) && ["dall-e", "image"].some((keyword) => modelName.includes(keyword));
|
|
128
130
|
}
|
|
129
131
|
__name(isImageGenerationModel, "isImageGenerationModel");
|
|
132
|
+
function isRerankerModel(modelName) {
|
|
133
|
+
return modelName.includes("rerank");
|
|
134
|
+
}
|
|
135
|
+
__name(isRerankerModel, "isRerankerModel");
|
|
130
136
|
function getModelMaxContextSize(info) {
|
|
131
137
|
const maxTokens = info.maxTokens;
|
|
132
138
|
if (maxTokens != null) {
|
|
@@ -214,6 +220,7 @@ var import_sse = require("koishi-plugin-chatluna/utils/sse");
|
|
|
214
220
|
var import_messages = require("@langchain/core/messages");
|
|
215
221
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
216
222
|
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
223
|
+
var import_langchain = require("koishi-plugin-chatluna/utils/langchain");
|
|
217
224
|
var import_types = require("@langchain/core/utils/types");
|
|
218
225
|
function createUsageMetadata(data) {
|
|
219
226
|
const inputTokenDetails = {
|
|
@@ -510,22 +517,34 @@ function processInterleavedThinkMessages(convertedMessages, originalMessages) {
|
|
|
510
517
|
if (originalMessages.length === 0) {
|
|
511
518
|
return convertedMessages;
|
|
512
519
|
}
|
|
520
|
+
const hasToolCallRound = convertedMessages.some(
|
|
521
|
+
(message) => message.role === "assistant" && (message.tool_calls?.length ?? 0) > 0
|
|
522
|
+
);
|
|
513
523
|
let lastTurnStartIndex = -1;
|
|
514
524
|
for (let i = originalMessages.length - 1; i >= 0; i--) {
|
|
515
525
|
const message = originalMessages[i];
|
|
516
|
-
if (
|
|
526
|
+
if ((0, import_langchain.isChatLunaUserMessage)(message)) {
|
|
517
527
|
lastTurnStartIndex = i;
|
|
518
528
|
break;
|
|
519
529
|
}
|
|
520
530
|
}
|
|
531
|
+
if (lastTurnStartIndex === -1) {
|
|
532
|
+
for (let i = originalMessages.length - 1; i >= 0; i--) {
|
|
533
|
+
const message = originalMessages[i];
|
|
534
|
+
if (message.getType() === "human") {
|
|
535
|
+
lastTurnStartIndex = i;
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
521
540
|
if (lastTurnStartIndex === -1) {
|
|
522
541
|
lastTurnStartIndex = 0;
|
|
523
542
|
}
|
|
524
543
|
return convertedMessages.map((message, index) => {
|
|
525
|
-
if (index >= lastTurnStartIndex) {
|
|
544
|
+
if (hasToolCallRound || index >= lastTurnStartIndex) {
|
|
526
545
|
const originalMessage = originalMessages[index];
|
|
527
546
|
const reasoningContent = originalMessage?.additional_kwargs?.reasoning_content;
|
|
528
|
-
if (reasoningContent) {
|
|
547
|
+
if (reasoningContent != null) {
|
|
529
548
|
return {
|
|
530
549
|
...message,
|
|
531
550
|
reasoning_content: reasoningContent
|
|
@@ -716,10 +735,10 @@ function removeAdditionalProperties(schema) {
|
|
|
716
735
|
__name(removeAdditionalProperties, "removeAdditionalProperties");
|
|
717
736
|
function convertMessageToMessageChunk(message) {
|
|
718
737
|
const content = message.content ?? "";
|
|
719
|
-
const reasoningContent = message.reasoning_content
|
|
738
|
+
const reasoningContent = message.reasoning_content;
|
|
720
739
|
const role = ((message.role?.length ?? 0) > 0 ? message.role : "assistant").toLowerCase();
|
|
721
740
|
const additionalKwargs = {};
|
|
722
|
-
if (reasoningContent
|
|
741
|
+
if (reasoningContent != null) {
|
|
723
742
|
additionalKwargs.reasoning_content = reasoningContent;
|
|
724
743
|
}
|
|
725
744
|
if (role === "user") {
|
|
@@ -766,7 +785,7 @@ __name(convertMessageToMessageChunk, "convertMessageToMessageChunk");
|
|
|
766
785
|
function convertDeltaToMessageChunk(delta, defaultRole) {
|
|
767
786
|
const role = ((delta.role?.length ?? 0) > 0 ? delta.role : defaultRole).toLowerCase();
|
|
768
787
|
const content = delta.content ?? "";
|
|
769
|
-
const reasoningContent = delta.reasoning_content
|
|
788
|
+
const reasoningContent = delta.reasoning_content;
|
|
770
789
|
let additionalKwargs;
|
|
771
790
|
if (delta.function_call) {
|
|
772
791
|
additionalKwargs = {
|
|
@@ -775,7 +794,7 @@ function convertDeltaToMessageChunk(delta, defaultRole) {
|
|
|
775
794
|
} else {
|
|
776
795
|
additionalKwargs = {};
|
|
777
796
|
}
|
|
778
|
-
if (reasoningContent
|
|
797
|
+
if (reasoningContent != null) {
|
|
779
798
|
additionalKwargs.reasoning_content = reasoningContent;
|
|
780
799
|
}
|
|
781
800
|
if (role === "user") {
|
|
@@ -909,6 +928,7 @@ async function* processStreamResponse(requestContext, iterator) {
|
|
|
909
928
|
let errorCount = 0;
|
|
910
929
|
const reasoningState = {
|
|
911
930
|
content: "",
|
|
931
|
+
seen: false,
|
|
912
932
|
startedAt: Date.now(),
|
|
913
933
|
endedAt: void 0
|
|
914
934
|
};
|
|
@@ -962,8 +982,11 @@ async function* processStreamResponse(requestContext, iterator) {
|
|
|
962
982
|
if (reasoningState.endedAt == null && hasResult) {
|
|
963
983
|
reasoningState.endedAt = Date.now();
|
|
964
984
|
}
|
|
965
|
-
if (
|
|
966
|
-
reasoningState.
|
|
985
|
+
if (Object.hasOwn(delta, "reasoning_content")) {
|
|
986
|
+
reasoningState.seen = true;
|
|
987
|
+
if (reasoningState.endedAt == null && !hasResult && typeof delta.reasoning_content === "string") {
|
|
988
|
+
reasoningState.content += delta.reasoning_content;
|
|
989
|
+
}
|
|
967
990
|
}
|
|
968
991
|
const messageChunk = convertDeltaToMessageChunk(
|
|
969
992
|
{
|
|
@@ -1000,12 +1023,14 @@ async function* processStreamResponse(requestContext, iterator) {
|
|
|
1000
1023
|
errorCount++;
|
|
1001
1024
|
}
|
|
1002
1025
|
}
|
|
1003
|
-
if (reasoningState.content.length > 0) {
|
|
1026
|
+
if (reasoningState.seen || reasoningState.content.length > 0) {
|
|
1004
1027
|
const reasoningTime = (reasoningState.endedAt ?? Date.now()) - reasoningState.startedAt;
|
|
1005
1028
|
yield new import_outputs.ChatGenerationChunk({
|
|
1006
1029
|
message: new import_messages2.AIMessageChunk({
|
|
1007
1030
|
content: "",
|
|
1008
1031
|
additional_kwargs: {
|
|
1032
|
+
// Always emit the field (possibly "") so DeepSeek-V4
|
|
1033
|
+
// thinking mode receives reasoning_content back verbatim.
|
|
1009
1034
|
reasoning_content: reasoningState.content,
|
|
1010
1035
|
...reasoningTime != null ? { reasoning_time: reasoningTime } : {}
|
|
1011
1036
|
}
|
|
@@ -1405,6 +1430,42 @@ async function createEmbeddings(requestContext, params, embeddingUrl = "embeddin
|
|
|
1405
1430
|
}
|
|
1406
1431
|
}
|
|
1407
1432
|
__name(createEmbeddings, "createEmbeddings");
|
|
1433
|
+
async function createRerank(requestContext, params, rerankUrl = "rerank") {
|
|
1434
|
+
const { modelRequester } = requestContext;
|
|
1435
|
+
try {
|
|
1436
|
+
const response = await modelRequester.post(
|
|
1437
|
+
rerankUrl,
|
|
1438
|
+
{
|
|
1439
|
+
model: params.model,
|
|
1440
|
+
query: params.query,
|
|
1441
|
+
documents: params.documents,
|
|
1442
|
+
top_n: params.topN,
|
|
1443
|
+
max_chunks_per_doc: params.maxChunksPerDoc,
|
|
1444
|
+
return_documents: false
|
|
1445
|
+
},
|
|
1446
|
+
{
|
|
1447
|
+
signal: params.signal
|
|
1448
|
+
}
|
|
1449
|
+
);
|
|
1450
|
+
const data = await response.json();
|
|
1451
|
+
if (data.results == null) {
|
|
1452
|
+
throw new import_error.ChatLunaError(
|
|
1453
|
+
import_error.ChatLunaErrorCode.API_REQUEST_FAILED,
|
|
1454
|
+
new Error(`Call Rerank Error: ${JSON.stringify(data)}`)
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
return data.results.map((item) => ({
|
|
1458
|
+
index: item.index,
|
|
1459
|
+
relevanceScore: item.relevance_score
|
|
1460
|
+
}));
|
|
1461
|
+
} catch (e) {
|
|
1462
|
+
if (e instanceof import_error.ChatLunaError) {
|
|
1463
|
+
throw e;
|
|
1464
|
+
}
|
|
1465
|
+
throw new import_error.ChatLunaError(import_error.ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
__name(createRerank, "createRerank");
|
|
1408
1469
|
async function getModels(requestContext, config) {
|
|
1409
1470
|
const { modelRequester } = requestContext;
|
|
1410
1471
|
let data;
|
|
@@ -1467,6 +1528,7 @@ __name(createRequestContext, "createRequestContext");
|
|
|
1467
1528
|
convertMessageToMessageChunk,
|
|
1468
1529
|
createEmbeddings,
|
|
1469
1530
|
createRequestContext,
|
|
1531
|
+
createRerank,
|
|
1470
1532
|
createUsageMetadata,
|
|
1471
1533
|
expandReasoningEffortModelVariants,
|
|
1472
1534
|
fetchFileLikeUrl,
|
|
@@ -1479,6 +1541,7 @@ __name(createRequestContext, "createRequestContext");
|
|
|
1479
1541
|
isEmbeddingModel,
|
|
1480
1542
|
isImageGenerationModel,
|
|
1481
1543
|
isNonLLMModel,
|
|
1544
|
+
isRerankerModel,
|
|
1482
1545
|
langchainMessageToOpenAIMessage,
|
|
1483
1546
|
langchainMessageToResponseInput,
|
|
1484
1547
|
messageTypeToOpenAIRole,
|
package/lib/index.mjs
CHANGED
|
@@ -53,7 +53,7 @@ function isNonLLMModel(modelName) {
|
|
|
53
53
|
if (modelName.includes("gemini") && modelName.includes("image")) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
-
return ["whisper", "tts", "dall-e", "image"
|
|
56
|
+
return ["whisper", "tts", "dall-e", "image"].some(
|
|
57
57
|
(keyword) => modelName.includes(keyword)
|
|
58
58
|
);
|
|
59
59
|
}
|
|
@@ -62,6 +62,10 @@ function isImageGenerationModel(modelName) {
|
|
|
62
62
|
return isNonLLMModel(modelName) && ["dall-e", "image"].some((keyword) => modelName.includes(keyword));
|
|
63
63
|
}
|
|
64
64
|
__name(isImageGenerationModel, "isImageGenerationModel");
|
|
65
|
+
function isRerankerModel(modelName) {
|
|
66
|
+
return modelName.includes("rerank");
|
|
67
|
+
}
|
|
68
|
+
__name(isRerankerModel, "isRerankerModel");
|
|
65
69
|
function getModelMaxContextSize(info) {
|
|
66
70
|
const maxTokens = info.maxTokens;
|
|
67
71
|
if (maxTokens != null) {
|
|
@@ -163,6 +167,7 @@ import {
|
|
|
163
167
|
getMimeTypeFromSource,
|
|
164
168
|
isMessageContentImageUrl
|
|
165
169
|
} from "koishi-plugin-chatluna/utils/string";
|
|
170
|
+
import { isChatLunaUserMessage } from "koishi-plugin-chatluna/utils/langchain";
|
|
166
171
|
import { isZodSchemaV3 } from "@langchain/core/utils/types";
|
|
167
172
|
function createUsageMetadata(data) {
|
|
168
173
|
const inputTokenDetails = {
|
|
@@ -459,22 +464,34 @@ function processInterleavedThinkMessages(convertedMessages, originalMessages) {
|
|
|
459
464
|
if (originalMessages.length === 0) {
|
|
460
465
|
return convertedMessages;
|
|
461
466
|
}
|
|
467
|
+
const hasToolCallRound = convertedMessages.some(
|
|
468
|
+
(message) => message.role === "assistant" && (message.tool_calls?.length ?? 0) > 0
|
|
469
|
+
);
|
|
462
470
|
let lastTurnStartIndex = -1;
|
|
463
471
|
for (let i = originalMessages.length - 1; i >= 0; i--) {
|
|
464
472
|
const message = originalMessages[i];
|
|
465
|
-
if (message
|
|
473
|
+
if (isChatLunaUserMessage(message)) {
|
|
466
474
|
lastTurnStartIndex = i;
|
|
467
475
|
break;
|
|
468
476
|
}
|
|
469
477
|
}
|
|
478
|
+
if (lastTurnStartIndex === -1) {
|
|
479
|
+
for (let i = originalMessages.length - 1; i >= 0; i--) {
|
|
480
|
+
const message = originalMessages[i];
|
|
481
|
+
if (message.getType() === "human") {
|
|
482
|
+
lastTurnStartIndex = i;
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
470
487
|
if (lastTurnStartIndex === -1) {
|
|
471
488
|
lastTurnStartIndex = 0;
|
|
472
489
|
}
|
|
473
490
|
return convertedMessages.map((message, index) => {
|
|
474
|
-
if (index >= lastTurnStartIndex) {
|
|
491
|
+
if (hasToolCallRound || index >= lastTurnStartIndex) {
|
|
475
492
|
const originalMessage = originalMessages[index];
|
|
476
493
|
const reasoningContent = originalMessage?.additional_kwargs?.reasoning_content;
|
|
477
|
-
if (reasoningContent) {
|
|
494
|
+
if (reasoningContent != null) {
|
|
478
495
|
return {
|
|
479
496
|
...message,
|
|
480
497
|
reasoning_content: reasoningContent
|
|
@@ -665,10 +682,10 @@ function removeAdditionalProperties(schema) {
|
|
|
665
682
|
__name(removeAdditionalProperties, "removeAdditionalProperties");
|
|
666
683
|
function convertMessageToMessageChunk(message) {
|
|
667
684
|
const content = message.content ?? "";
|
|
668
|
-
const reasoningContent = message.reasoning_content
|
|
685
|
+
const reasoningContent = message.reasoning_content;
|
|
669
686
|
const role = ((message.role?.length ?? 0) > 0 ? message.role : "assistant").toLowerCase();
|
|
670
687
|
const additionalKwargs = {};
|
|
671
|
-
if (reasoningContent
|
|
688
|
+
if (reasoningContent != null) {
|
|
672
689
|
additionalKwargs.reasoning_content = reasoningContent;
|
|
673
690
|
}
|
|
674
691
|
if (role === "user") {
|
|
@@ -715,7 +732,7 @@ __name(convertMessageToMessageChunk, "convertMessageToMessageChunk");
|
|
|
715
732
|
function convertDeltaToMessageChunk(delta, defaultRole) {
|
|
716
733
|
const role = ((delta.role?.length ?? 0) > 0 ? delta.role : defaultRole).toLowerCase();
|
|
717
734
|
const content = delta.content ?? "";
|
|
718
|
-
const reasoningContent = delta.reasoning_content
|
|
735
|
+
const reasoningContent = delta.reasoning_content;
|
|
719
736
|
let additionalKwargs;
|
|
720
737
|
if (delta.function_call) {
|
|
721
738
|
additionalKwargs = {
|
|
@@ -724,7 +741,7 @@ function convertDeltaToMessageChunk(delta, defaultRole) {
|
|
|
724
741
|
} else {
|
|
725
742
|
additionalKwargs = {};
|
|
726
743
|
}
|
|
727
|
-
if (reasoningContent
|
|
744
|
+
if (reasoningContent != null) {
|
|
728
745
|
additionalKwargs.reasoning_content = reasoningContent;
|
|
729
746
|
}
|
|
730
747
|
if (role === "user") {
|
|
@@ -858,6 +875,7 @@ async function* processStreamResponse(requestContext, iterator) {
|
|
|
858
875
|
let errorCount = 0;
|
|
859
876
|
const reasoningState = {
|
|
860
877
|
content: "",
|
|
878
|
+
seen: false,
|
|
861
879
|
startedAt: Date.now(),
|
|
862
880
|
endedAt: void 0
|
|
863
881
|
};
|
|
@@ -911,8 +929,11 @@ async function* processStreamResponse(requestContext, iterator) {
|
|
|
911
929
|
if (reasoningState.endedAt == null && hasResult) {
|
|
912
930
|
reasoningState.endedAt = Date.now();
|
|
913
931
|
}
|
|
914
|
-
if (
|
|
915
|
-
reasoningState.
|
|
932
|
+
if (Object.hasOwn(delta, "reasoning_content")) {
|
|
933
|
+
reasoningState.seen = true;
|
|
934
|
+
if (reasoningState.endedAt == null && !hasResult && typeof delta.reasoning_content === "string") {
|
|
935
|
+
reasoningState.content += delta.reasoning_content;
|
|
936
|
+
}
|
|
916
937
|
}
|
|
917
938
|
const messageChunk = convertDeltaToMessageChunk(
|
|
918
939
|
{
|
|
@@ -949,12 +970,14 @@ async function* processStreamResponse(requestContext, iterator) {
|
|
|
949
970
|
errorCount++;
|
|
950
971
|
}
|
|
951
972
|
}
|
|
952
|
-
if (reasoningState.content.length > 0) {
|
|
973
|
+
if (reasoningState.seen || reasoningState.content.length > 0) {
|
|
953
974
|
const reasoningTime = (reasoningState.endedAt ?? Date.now()) - reasoningState.startedAt;
|
|
954
975
|
yield new ChatGenerationChunk({
|
|
955
976
|
message: new AIMessageChunk2({
|
|
956
977
|
content: "",
|
|
957
978
|
additional_kwargs: {
|
|
979
|
+
// Always emit the field (possibly "") so DeepSeek-V4
|
|
980
|
+
// thinking mode receives reasoning_content back verbatim.
|
|
958
981
|
reasoning_content: reasoningState.content,
|
|
959
982
|
...reasoningTime != null ? { reasoning_time: reasoningTime } : {}
|
|
960
983
|
}
|
|
@@ -1354,6 +1377,42 @@ async function createEmbeddings(requestContext, params, embeddingUrl = "embeddin
|
|
|
1354
1377
|
}
|
|
1355
1378
|
}
|
|
1356
1379
|
__name(createEmbeddings, "createEmbeddings");
|
|
1380
|
+
async function createRerank(requestContext, params, rerankUrl = "rerank") {
|
|
1381
|
+
const { modelRequester } = requestContext;
|
|
1382
|
+
try {
|
|
1383
|
+
const response = await modelRequester.post(
|
|
1384
|
+
rerankUrl,
|
|
1385
|
+
{
|
|
1386
|
+
model: params.model,
|
|
1387
|
+
query: params.query,
|
|
1388
|
+
documents: params.documents,
|
|
1389
|
+
top_n: params.topN,
|
|
1390
|
+
max_chunks_per_doc: params.maxChunksPerDoc,
|
|
1391
|
+
return_documents: false
|
|
1392
|
+
},
|
|
1393
|
+
{
|
|
1394
|
+
signal: params.signal
|
|
1395
|
+
}
|
|
1396
|
+
);
|
|
1397
|
+
const data = await response.json();
|
|
1398
|
+
if (data.results == null) {
|
|
1399
|
+
throw new ChatLunaError(
|
|
1400
|
+
ChatLunaErrorCode.API_REQUEST_FAILED,
|
|
1401
|
+
new Error(`Call Rerank Error: ${JSON.stringify(data)}`)
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
return data.results.map((item) => ({
|
|
1405
|
+
index: item.index,
|
|
1406
|
+
relevanceScore: item.relevance_score
|
|
1407
|
+
}));
|
|
1408
|
+
} catch (e) {
|
|
1409
|
+
if (e instanceof ChatLunaError) {
|
|
1410
|
+
throw e;
|
|
1411
|
+
}
|
|
1412
|
+
throw new ChatLunaError(ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
__name(createRerank, "createRerank");
|
|
1357
1416
|
async function getModels(requestContext, config) {
|
|
1358
1417
|
const { modelRequester } = requestContext;
|
|
1359
1418
|
let data;
|
|
@@ -1415,6 +1474,7 @@ export {
|
|
|
1415
1474
|
convertMessageToMessageChunk,
|
|
1416
1475
|
createEmbeddings,
|
|
1417
1476
|
createRequestContext,
|
|
1477
|
+
createRerank,
|
|
1418
1478
|
createUsageMetadata,
|
|
1419
1479
|
expandReasoningEffortModelVariants,
|
|
1420
1480
|
fetchFileLikeUrl,
|
|
@@ -1427,6 +1487,7 @@ export {
|
|
|
1427
1487
|
isEmbeddingModel,
|
|
1428
1488
|
isImageGenerationModel,
|
|
1429
1489
|
isNonLLMModel,
|
|
1490
|
+
isRerankerModel,
|
|
1430
1491
|
langchainMessageToOpenAIMessage,
|
|
1431
1492
|
langchainMessageToResponseInput,
|
|
1432
1493
|
messageTypeToOpenAIRole,
|
package/lib/requester.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
2
|
-
import { EmbeddingsRequestParams, ModelRequester, ModelRequestParams } from 'koishi-plugin-chatluna/llm-core/platform/api';
|
|
2
|
+
import { EmbeddingsRequestParams, ModelRequester, ModelRequestParams, RerankerRequestParams, RerankerResult } from 'koishi-plugin-chatluna/llm-core/platform/api';
|
|
3
3
|
import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
4
4
|
import { SSEEvent } from 'koishi-plugin-chatluna/utils/sse';
|
|
5
5
|
import { type ResponseBuiltinTool, ResponseObject, ResponseOutputItem } from './types';
|
|
@@ -54,7 +54,7 @@ export declare function buildResponseParams(params: ModelRequestParams, plugin:
|
|
|
54
54
|
top_p: number;
|
|
55
55
|
prompt_cache_key: string;
|
|
56
56
|
reasoning: {
|
|
57
|
-
effort: "
|
|
57
|
+
effort: "low" | "high" | "minimal" | "medium" | "max" | "xhigh";
|
|
58
58
|
};
|
|
59
59
|
stream: boolean;
|
|
60
60
|
stream_options: {
|
|
@@ -73,6 +73,7 @@ export declare function completion<T extends ClientConfig, R extends ChatLunaPlu
|
|
|
73
73
|
export declare function responseApiCompletionStream<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: ModelRequestParams, opts?: ResponseToolOptions, supportImageInput?: boolean, imageProvider?: ResponseImageProvider): AsyncGenerator<ChatGenerationChunk>;
|
|
74
74
|
export declare function responseApiCompletion<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: ModelRequestParams, opts?: ResponseToolOptions, supportImageInput?: boolean, imageProvider?: ResponseImageProvider): Promise<ChatGenerationChunk>;
|
|
75
75
|
export declare function createEmbeddings<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: EmbeddingsRequestParams, embeddingUrl?: string): Promise<number[] | number[][]>;
|
|
76
|
+
export declare function createRerank<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: RerankerRequestParams, rerankUrl?: string): Promise<RerankerResult[]>;
|
|
76
77
|
export declare function getModels<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, config?: RunnableConfig): Promise<string[]>;
|
|
77
78
|
export declare function createRequestContext<T extends ClientConfig, R extends ChatLunaPlugin.Config>(ctx: Context, config: T, pluginConfig: R, plugin: ChatLunaPlugin, modelRequester: ModelRequester<T, R>): RequestContext<T, R>;
|
|
78
79
|
export {};
|
package/lib/types.d.ts
CHANGED
|
@@ -325,3 +325,27 @@ export interface CreateEmbeddingResponseUsage {
|
|
|
325
325
|
total_tokens: number;
|
|
326
326
|
}
|
|
327
327
|
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'assistant' | 'user' | 'function' | 'tool';
|
|
328
|
+
export interface CreateRerankRequest {
|
|
329
|
+
model: string;
|
|
330
|
+
query: string;
|
|
331
|
+
documents: string[];
|
|
332
|
+
top_n?: number;
|
|
333
|
+
max_chunks_per_doc?: number;
|
|
334
|
+
return_documents?: boolean;
|
|
335
|
+
}
|
|
336
|
+
export interface RerankResultItem {
|
|
337
|
+
index: number;
|
|
338
|
+
relevance_score: number;
|
|
339
|
+
document?: {
|
|
340
|
+
text: string;
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export interface CreateRerankResponse {
|
|
344
|
+
id?: string;
|
|
345
|
+
model?: string;
|
|
346
|
+
results: RerankResultItem[];
|
|
347
|
+
usage?: {
|
|
348
|
+
prompt_tokens?: number;
|
|
349
|
+
total_tokens?: number;
|
|
350
|
+
};
|
|
351
|
+
}
|
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.36",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"koishi": "^4.18.9",
|
|
73
|
-
"koishi-plugin-chatluna": "^1.4.0-alpha.
|
|
73
|
+
"koishi-plugin-chatluna": "^1.4.0-alpha.13"
|
|
74
74
|
}
|
|
75
75
|
}
|