koishi-plugin-chatluna-google-gemini-adapter 1.3.0-alpha.14 → 1.3.0-alpha.15
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/index.cjs +26 -0
- package/lib/index.mjs +26 -0
- package/lib/types.d.ts +8 -1
- package/package.json +3 -3
package/lib/index.cjs
CHANGED
|
@@ -685,6 +685,18 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
685
685
|
return;
|
|
686
686
|
}
|
|
687
687
|
const transformValue = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
|
|
688
|
+
if (transformValue.usageMetadata) {
|
|
689
|
+
const promptTokens = transformValue.usageMetadata.promptTokenCount;
|
|
690
|
+
const totalTokens = transformValue.usageMetadata.totalTokenCount;
|
|
691
|
+
const completionTokens = transformValue.usageMetadata.candidatesTokenCount ?? totalTokens - promptTokens;
|
|
692
|
+
controller.enqueue({
|
|
693
|
+
usage: {
|
|
694
|
+
promptTokens,
|
|
695
|
+
completionTokens,
|
|
696
|
+
totalTokens
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
688
700
|
if (!transformValue?.candidates) {
|
|
689
701
|
return;
|
|
690
702
|
}
|
|
@@ -723,6 +735,20 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
723
735
|
let errorCount = 0;
|
|
724
736
|
let functionIndex = 0;
|
|
725
737
|
for await (const chunk of iterable) {
|
|
738
|
+
let parsedChunk;
|
|
739
|
+
if (parsedChunk = partAsTypeCheck(
|
|
740
|
+
chunk,
|
|
741
|
+
(chunk2) => chunk2["usage"] != null
|
|
742
|
+
)) {
|
|
743
|
+
const generationChunk = new import_outputs.ChatGenerationChunk({
|
|
744
|
+
message: new import_messages.AIMessageChunk(""),
|
|
745
|
+
text: "",
|
|
746
|
+
generationInfo: {
|
|
747
|
+
tokenUsage: parsedChunk.usage
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
yield { type: "generation", generation: generationChunk };
|
|
751
|
+
}
|
|
726
752
|
try {
|
|
727
753
|
const { updatedContent, updatedReasoning, updatedToolCalling } = await this._processChunk(
|
|
728
754
|
chunk,
|
package/lib/index.mjs
CHANGED
|
@@ -682,6 +682,18 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
682
682
|
return;
|
|
683
683
|
}
|
|
684
684
|
const transformValue = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
|
|
685
|
+
if (transformValue.usageMetadata) {
|
|
686
|
+
const promptTokens = transformValue.usageMetadata.promptTokenCount;
|
|
687
|
+
const totalTokens = transformValue.usageMetadata.totalTokenCount;
|
|
688
|
+
const completionTokens = transformValue.usageMetadata.candidatesTokenCount ?? totalTokens - promptTokens;
|
|
689
|
+
controller.enqueue({
|
|
690
|
+
usage: {
|
|
691
|
+
promptTokens,
|
|
692
|
+
completionTokens,
|
|
693
|
+
totalTokens
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}
|
|
685
697
|
if (!transformValue?.candidates) {
|
|
686
698
|
return;
|
|
687
699
|
}
|
|
@@ -720,6 +732,20 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
720
732
|
let errorCount = 0;
|
|
721
733
|
let functionIndex = 0;
|
|
722
734
|
for await (const chunk of iterable) {
|
|
735
|
+
let parsedChunk;
|
|
736
|
+
if (parsedChunk = partAsTypeCheck(
|
|
737
|
+
chunk,
|
|
738
|
+
(chunk2) => chunk2["usage"] != null
|
|
739
|
+
)) {
|
|
740
|
+
const generationChunk = new ChatGenerationChunk({
|
|
741
|
+
message: new AIMessageChunk(""),
|
|
742
|
+
text: "",
|
|
743
|
+
generationInfo: {
|
|
744
|
+
tokenUsage: parsedChunk.usage
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
yield { type: "generation", generation: generationChunk };
|
|
748
|
+
}
|
|
723
749
|
try {
|
|
724
750
|
const { updatedContent, updatedReasoning, updatedToolCalling } = await this._processChunk(
|
|
725
751
|
chunk,
|
package/lib/types.d.ts
CHANGED
|
@@ -2,11 +2,18 @@ export interface ChatCompletionResponseMessage {
|
|
|
2
2
|
role: string;
|
|
3
3
|
parts?: ChatPart[];
|
|
4
4
|
}
|
|
5
|
-
export type ChatPart = ChatMessagePart | ChatInlineDataPart | ChatFunctionCallingPart | ChatFunctionResponsePart | ChatUploadDataPart;
|
|
5
|
+
export type ChatPart = ChatMessagePart | ChatInlineDataPart | ChatFunctionCallingPart | ChatFunctionResponsePart | ChatUploadDataPart | ChatUsageMetadataPart;
|
|
6
6
|
export type ChatMessagePart = {
|
|
7
7
|
text: string;
|
|
8
8
|
thought?: boolean;
|
|
9
9
|
};
|
|
10
|
+
export type ChatUsageMetadataPart = {
|
|
11
|
+
usage: {
|
|
12
|
+
promptTokens: number;
|
|
13
|
+
completionTokens: number;
|
|
14
|
+
totalTokens: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
10
17
|
export type ChatInlineDataPart = {
|
|
11
18
|
inlineData: {
|
|
12
19
|
mimeType: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-google-gemini-adapter",
|
|
3
3
|
"description": "google-gemini adapter for chatluna",
|
|
4
|
-
"version": "1.3.0-alpha.
|
|
4
|
+
"version": "1.3.0-alpha.15",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"adapter"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@chatluna/v1-shared-adapter": "^1.0.
|
|
65
|
+
"@chatluna/v1-shared-adapter": "^1.0.13",
|
|
66
66
|
"@langchain/core": "0.3.62",
|
|
67
67
|
"zod": "3.25.76",
|
|
68
68
|
"zod-to-json-schema": "^3.24.6"
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"koishi": "^4.18.9",
|
|
76
|
-
"koishi-plugin-chatluna": "^1.3.0-alpha.
|
|
76
|
+
"koishi-plugin-chatluna": "^1.3.0-alpha.56",
|
|
77
77
|
"koishi-plugin-chatluna-storage-service": "^0.0.9"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|