koishi-plugin-chatluna-google-gemini-adapter 1.3.0-alpha.4 → 1.3.0-alpha.6
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 +12 -9
- package/lib/index.mjs +12 -12
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var import_types = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
|
55
55
|
var import_error2 = require("koishi-plugin-chatluna/utils/error");
|
|
56
56
|
|
|
57
57
|
// src/requester.ts
|
|
58
|
-
var
|
|
58
|
+
var import_messages = require("@langchain/core/messages");
|
|
59
59
|
var import_outputs = require("@langchain/core/outputs");
|
|
60
60
|
var import_api = require("koishi-plugin-chatluna/llm-core/platform/api");
|
|
61
61
|
var import_error = require("koishi-plugin-chatluna/utils/error");
|
|
@@ -63,7 +63,6 @@ var import_sse = require("koishi-plugin-chatluna/utils/sse");
|
|
|
63
63
|
var import_stream = require("koishi-plugin-chatluna/utils/stream");
|
|
64
64
|
|
|
65
65
|
// src/utils.ts
|
|
66
|
-
var import_messages = require("@langchain/core/messages");
|
|
67
66
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
68
67
|
var import_v1_shared_adapter = require("@chatluna/v1-shared-adapter");
|
|
69
68
|
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
@@ -72,7 +71,7 @@ async function langchainMessageToGeminiMessage(messages, plugin, model) {
|
|
|
72
71
|
return Promise.all(
|
|
73
72
|
messages.map(async (message) => {
|
|
74
73
|
const role = messageTypeToGeminiRole(message.getType());
|
|
75
|
-
const hasFunctionCall = message.tool_calls != null;
|
|
74
|
+
const hasFunctionCall = message.tool_calls != null && message.tool_calls.length > 0;
|
|
76
75
|
if (role === "function" || hasFunctionCall) {
|
|
77
76
|
return processFunctionMessage(message);
|
|
78
77
|
}
|
|
@@ -121,14 +120,17 @@ __name(extractSystemMessages, "extractSystemMessages");
|
|
|
121
120
|
function parseJsonArgs(args) {
|
|
122
121
|
try {
|
|
123
122
|
const result = JSON.parse(args);
|
|
124
|
-
|
|
123
|
+
if (typeof result === "string") return { response: result };
|
|
124
|
+
if (Array.isArray(result)) return { response: result };
|
|
125
|
+
return result;
|
|
125
126
|
} catch {
|
|
126
|
-
return {
|
|
127
|
+
return { response: args };
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
__name(parseJsonArgs, "parseJsonArgs");
|
|
130
131
|
function processFunctionMessage(message) {
|
|
131
|
-
if (message
|
|
132
|
+
if (message["tool_calls"]) {
|
|
133
|
+
message = message;
|
|
132
134
|
const toolCalls = message.tool_calls;
|
|
133
135
|
return {
|
|
134
136
|
role: "model",
|
|
@@ -143,13 +145,14 @@ function processFunctionMessage(message) {
|
|
|
143
145
|
})
|
|
144
146
|
};
|
|
145
147
|
}
|
|
148
|
+
const finalMessage = message;
|
|
146
149
|
return {
|
|
147
150
|
role: "user",
|
|
148
151
|
parts: [
|
|
149
152
|
{
|
|
150
153
|
functionResponse: {
|
|
151
154
|
name: message.name,
|
|
152
|
-
id:
|
|
155
|
+
id: finalMessage.tool_call_id,
|
|
153
156
|
response: parseJsonArgs(message.content)
|
|
154
157
|
}
|
|
155
158
|
}
|
|
@@ -806,7 +809,7 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
806
809
|
if (groundingContent.length > 0) {
|
|
807
810
|
logger.debug(`grounding content: ${groundingContent}`);
|
|
808
811
|
if (this._pluginConfig.groundingContentDisplay) {
|
|
809
|
-
const groundingMessage = new
|
|
812
|
+
const groundingMessage = new import_messages.AIMessageChunk(
|
|
810
813
|
`
|
|
811
814
|
${groundingContent}`
|
|
812
815
|
);
|
|
@@ -819,7 +822,7 @@ ${groundingContent}`
|
|
|
819
822
|
}
|
|
820
823
|
}
|
|
821
824
|
_createMessageChunk(content, functionCall, imagePart) {
|
|
822
|
-
const messageChunk = new
|
|
825
|
+
const messageChunk = new import_messages.AIMessageChunk({
|
|
823
826
|
content: content ?? "",
|
|
824
827
|
tool_call_chunks: [functionCall].filter(Boolean)
|
|
825
828
|
});
|
package/lib/index.mjs
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
|
|
41
41
|
// src/requester.ts
|
|
42
42
|
import {
|
|
43
|
-
AIMessageChunk
|
|
43
|
+
AIMessageChunk
|
|
44
44
|
} from "@langchain/core/messages";
|
|
45
45
|
import { ChatGenerationChunk } from "@langchain/core/outputs";
|
|
46
46
|
import {
|
|
@@ -54,10 +54,6 @@ import { checkResponse, sseIterable } from "koishi-plugin-chatluna/utils/sse";
|
|
|
54
54
|
import { readableStreamToAsyncIterable } from "koishi-plugin-chatluna/utils/stream";
|
|
55
55
|
|
|
56
56
|
// src/utils.ts
|
|
57
|
-
import {
|
|
58
|
-
AIMessage,
|
|
59
|
-
AIMessageChunk
|
|
60
|
-
} from "@langchain/core/messages";
|
|
61
57
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
62
58
|
import {
|
|
63
59
|
fetchImageUrl,
|
|
@@ -72,7 +68,7 @@ async function langchainMessageToGeminiMessage(messages, plugin, model) {
|
|
|
72
68
|
return Promise.all(
|
|
73
69
|
messages.map(async (message) => {
|
|
74
70
|
const role = messageTypeToGeminiRole(message.getType());
|
|
75
|
-
const hasFunctionCall = message.tool_calls != null;
|
|
71
|
+
const hasFunctionCall = message.tool_calls != null && message.tool_calls.length > 0;
|
|
76
72
|
if (role === "function" || hasFunctionCall) {
|
|
77
73
|
return processFunctionMessage(message);
|
|
78
74
|
}
|
|
@@ -121,14 +117,17 @@ __name(extractSystemMessages, "extractSystemMessages");
|
|
|
121
117
|
function parseJsonArgs(args) {
|
|
122
118
|
try {
|
|
123
119
|
const result = JSON.parse(args);
|
|
124
|
-
|
|
120
|
+
if (typeof result === "string") return { response: result };
|
|
121
|
+
if (Array.isArray(result)) return { response: result };
|
|
122
|
+
return result;
|
|
125
123
|
} catch {
|
|
126
|
-
return {
|
|
124
|
+
return { response: args };
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
__name(parseJsonArgs, "parseJsonArgs");
|
|
130
128
|
function processFunctionMessage(message) {
|
|
131
|
-
if (message
|
|
129
|
+
if (message["tool_calls"]) {
|
|
130
|
+
message = message;
|
|
132
131
|
const toolCalls = message.tool_calls;
|
|
133
132
|
return {
|
|
134
133
|
role: "model",
|
|
@@ -143,13 +142,14 @@ function processFunctionMessage(message) {
|
|
|
143
142
|
})
|
|
144
143
|
};
|
|
145
144
|
}
|
|
145
|
+
const finalMessage = message;
|
|
146
146
|
return {
|
|
147
147
|
role: "user",
|
|
148
148
|
parts: [
|
|
149
149
|
{
|
|
150
150
|
functionResponse: {
|
|
151
151
|
name: message.name,
|
|
152
|
-
id:
|
|
152
|
+
id: finalMessage.tool_call_id,
|
|
153
153
|
response: parseJsonArgs(message.content)
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -806,7 +806,7 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
806
806
|
if (groundingContent.length > 0) {
|
|
807
807
|
logger.debug(`grounding content: ${groundingContent}`);
|
|
808
808
|
if (this._pluginConfig.groundingContentDisplay) {
|
|
809
|
-
const groundingMessage = new
|
|
809
|
+
const groundingMessage = new AIMessageChunk(
|
|
810
810
|
`
|
|
811
811
|
${groundingContent}`
|
|
812
812
|
);
|
|
@@ -819,7 +819,7 @@ ${groundingContent}`
|
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
821
|
_createMessageChunk(content, functionCall, imagePart) {
|
|
822
|
-
const messageChunk = new
|
|
822
|
+
const messageChunk = new AIMessageChunk({
|
|
823
823
|
content: content ?? "",
|
|
824
824
|
tool_call_chunks: [functionCall].filter(Boolean)
|
|
825
825
|
});
|
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.6",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"koishi": "^4.18.7",
|
|
76
|
-
"koishi-plugin-chatluna": "^1.3.0-alpha.
|
|
76
|
+
"koishi-plugin-chatluna": "^1.3.0-alpha.31",
|
|
77
77
|
"koishi-plugin-chatluna-storage-service": "^0.0.8"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|