koishi-plugin-chatluna-google-gemini-adapter 1.3.0-alpha.8 → 1.3.0-alpha.9
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 +2 -1
- package/lib/index.cjs +23 -15
- package/lib/index.mjs +18 -10
- package/lib/requester.d.ts +2 -1
- package/package.json +3 -3
package/lib/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ChatLunaBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatlun
|
|
|
5
5
|
import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
|
|
6
6
|
import { Config } from '.';
|
|
7
7
|
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
8
|
+
import { RunnableConfig } from '@langchain/core/runnables';
|
|
8
9
|
export declare class GeminiClient extends PlatformModelAndEmbeddingsClient<ClientConfig> {
|
|
9
10
|
private _config;
|
|
10
11
|
plugin: ChatLunaPlugin;
|
|
@@ -12,6 +13,6 @@ export declare class GeminiClient extends PlatformModelAndEmbeddingsClient<Clien
|
|
|
12
13
|
private _requester;
|
|
13
14
|
get logger(): import("reggol");
|
|
14
15
|
constructor(ctx: Context, _config: Config, plugin: ChatLunaPlugin);
|
|
15
|
-
refreshModels(): Promise<ModelInfo[]>;
|
|
16
|
+
refreshModels(config?: RunnableConfig): Promise<ModelInfo[]>;
|
|
16
17
|
protected _createModel(model: string): ChatLunaChatModel | ChatLunaBaseEmbeddings;
|
|
17
18
|
}
|
package/lib/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ var import_koishi = require("koishi");
|
|
|
51
51
|
// src/client.ts
|
|
52
52
|
var import_client = require("koishi-plugin-chatluna/llm-core/platform/client");
|
|
53
53
|
var import_model = require("koishi-plugin-chatluna/llm-core/platform/model");
|
|
54
|
-
var
|
|
54
|
+
var import_types2 = 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
|
|
@@ -66,7 +66,7 @@ var import_stream = require("koishi-plugin-chatluna/utils/stream");
|
|
|
66
66
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
67
67
|
var import_v1_shared_adapter = require("@chatluna/v1-shared-adapter");
|
|
68
68
|
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
69
|
-
var
|
|
69
|
+
var import_types = require("@langchain/core/utils/types");
|
|
70
70
|
async function langchainMessageToGeminiMessage(messages, plugin, model) {
|
|
71
71
|
return Promise.all(
|
|
72
72
|
messages.map(async (message) => {
|
|
@@ -287,7 +287,7 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
287
287
|
__name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
288
288
|
function formatToolToGeminiAITool(tool) {
|
|
289
289
|
const parameters = (0, import_v1_shared_adapter.removeAdditionalProperties)(
|
|
290
|
-
tool.schema
|
|
290
|
+
(0, import_types.isZodSchemaV3)(tool.schema) ? (0, import_zod_to_json_schema.zodToJsonSchema)(tool.schema, {
|
|
291
291
|
allowedAdditionalProperties: void 0
|
|
292
292
|
}) : tool.schema
|
|
293
293
|
);
|
|
@@ -522,12 +522,17 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
522
522
|
"error when calling gemini embeddings, Result: " + JSON.stringify(data)
|
|
523
523
|
);
|
|
524
524
|
}
|
|
525
|
-
async getModels() {
|
|
525
|
+
async getModels(config) {
|
|
526
526
|
try {
|
|
527
|
-
const response = await this._get("models"
|
|
527
|
+
const response = await this._get("models", {
|
|
528
|
+
signal: config?.signal
|
|
529
|
+
});
|
|
528
530
|
const data = await this._parseModelsResponse(response);
|
|
529
531
|
return this._filterAndTransformModels(data.models);
|
|
530
532
|
} catch (e) {
|
|
533
|
+
if (e instanceof import_error.ChatLunaError) {
|
|
534
|
+
throw e;
|
|
535
|
+
}
|
|
531
536
|
const error = new Error(
|
|
532
537
|
"error when listing gemini models, Error: " + e.message
|
|
533
538
|
);
|
|
@@ -849,11 +854,12 @@ ${groundingContent}`
|
|
|
849
854
|
...params
|
|
850
855
|
});
|
|
851
856
|
}
|
|
852
|
-
_get(url) {
|
|
857
|
+
_get(url, params = {}) {
|
|
853
858
|
const requestUrl = this._concatUrl(url);
|
|
854
859
|
return this._plugin.fetch(requestUrl, {
|
|
855
860
|
method: "GET",
|
|
856
|
-
headers: this._buildHeaders()
|
|
861
|
+
headers: this._buildHeaders(),
|
|
862
|
+
...params
|
|
857
863
|
});
|
|
858
864
|
}
|
|
859
865
|
_concatUrl(url) {
|
|
@@ -901,9 +907,9 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
901
907
|
get logger() {
|
|
902
908
|
return logger;
|
|
903
909
|
}
|
|
904
|
-
async refreshModels() {
|
|
910
|
+
async refreshModels(config) {
|
|
905
911
|
try {
|
|
906
|
-
const rawModels = await this._requester.getModels();
|
|
912
|
+
const rawModels = await this._requester.getModels(config);
|
|
907
913
|
if (!rawModels.length) {
|
|
908
914
|
throw new import_error2.ChatLunaError(
|
|
909
915
|
import_error2.ChatLunaErrorCode.MODEL_INIT_ERROR,
|
|
@@ -915,10 +921,10 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
915
921
|
const info = {
|
|
916
922
|
name: model.name,
|
|
917
923
|
maxTokens: model.inputTokenLimit,
|
|
918
|
-
type: model.name.includes("embedding") ?
|
|
924
|
+
type: model.name.includes("embedding") ? import_types2.ModelType.embeddings : import_types2.ModelType.llm,
|
|
919
925
|
capabilities: [
|
|
920
|
-
|
|
921
|
-
|
|
926
|
+
import_types2.ModelCapabilities.ImageInput,
|
|
927
|
+
import_types2.ModelCapabilities.ToolCall
|
|
922
928
|
]
|
|
923
929
|
};
|
|
924
930
|
if (model.name.includes("gemini-2.5") && !model.name.includes("pro") && !model.name.includes("image")) {
|
|
@@ -937,6 +943,9 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
937
943
|
}
|
|
938
944
|
return models;
|
|
939
945
|
} catch (e) {
|
|
946
|
+
if (e instanceof import_error2.ChatLunaError) {
|
|
947
|
+
throw e;
|
|
948
|
+
}
|
|
940
949
|
throw new import_error2.ChatLunaError(import_error2.ChatLunaErrorCode.MODEL_INIT_ERROR, e);
|
|
941
950
|
}
|
|
942
951
|
}
|
|
@@ -945,7 +954,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
945
954
|
if (info == null) {
|
|
946
955
|
throw new import_error2.ChatLunaError(import_error2.ChatLunaErrorCode.MODEL_NOT_FOUND);
|
|
947
956
|
}
|
|
948
|
-
if (info.type ===
|
|
957
|
+
if (info.type === import_types2.ModelType.llm) {
|
|
949
958
|
return new import_model.ChatLunaChatModel({
|
|
950
959
|
modelInfo: info,
|
|
951
960
|
requester: this._requester,
|
|
@@ -974,8 +983,7 @@ function apply(ctx, config) {
|
|
|
974
983
|
const plugin = new import_chat.ChatLunaPlugin(ctx, config, config.platform);
|
|
975
984
|
logger = (0, import_logger.createLogger)(ctx, "chatluna-gemini-adapter");
|
|
976
985
|
ctx.on("ready", async () => {
|
|
977
|
-
plugin.
|
|
978
|
-
await plugin.parseConfig((config2) => {
|
|
986
|
+
plugin.parseConfig((config2) => {
|
|
979
987
|
return config2.apiKeys.map(([apiKey, apiEndpoint]) => {
|
|
980
988
|
return {
|
|
981
989
|
apiKey,
|
package/lib/index.mjs
CHANGED
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
isMessageContentImageUrl,
|
|
64
64
|
isMessageContentText
|
|
65
65
|
} from "koishi-plugin-chatluna/utils/string";
|
|
66
|
-
import {
|
|
66
|
+
import { isZodSchemaV3 } from "@langchain/core/utils/types";
|
|
67
67
|
async function langchainMessageToGeminiMessage(messages, plugin, model) {
|
|
68
68
|
return Promise.all(
|
|
69
69
|
messages.map(async (message) => {
|
|
@@ -284,7 +284,7 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
284
284
|
__name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
285
285
|
function formatToolToGeminiAITool(tool) {
|
|
286
286
|
const parameters = removeAdditionalProperties(
|
|
287
|
-
tool.schema
|
|
287
|
+
isZodSchemaV3(tool.schema) ? zodToJsonSchema(tool.schema, {
|
|
288
288
|
allowedAdditionalProperties: void 0
|
|
289
289
|
}) : tool.schema
|
|
290
290
|
);
|
|
@@ -519,12 +519,17 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
519
519
|
"error when calling gemini embeddings, Result: " + JSON.stringify(data)
|
|
520
520
|
);
|
|
521
521
|
}
|
|
522
|
-
async getModels() {
|
|
522
|
+
async getModels(config) {
|
|
523
523
|
try {
|
|
524
|
-
const response = await this._get("models"
|
|
524
|
+
const response = await this._get("models", {
|
|
525
|
+
signal: config?.signal
|
|
526
|
+
});
|
|
525
527
|
const data = await this._parseModelsResponse(response);
|
|
526
528
|
return this._filterAndTransformModels(data.models);
|
|
527
529
|
} catch (e) {
|
|
530
|
+
if (e instanceof ChatLunaError) {
|
|
531
|
+
throw e;
|
|
532
|
+
}
|
|
528
533
|
const error = new Error(
|
|
529
534
|
"error when listing gemini models, Error: " + e.message
|
|
530
535
|
);
|
|
@@ -846,11 +851,12 @@ ${groundingContent}`
|
|
|
846
851
|
...params
|
|
847
852
|
});
|
|
848
853
|
}
|
|
849
|
-
_get(url) {
|
|
854
|
+
_get(url, params = {}) {
|
|
850
855
|
const requestUrl = this._concatUrl(url);
|
|
851
856
|
return this._plugin.fetch(requestUrl, {
|
|
852
857
|
method: "GET",
|
|
853
|
-
headers: this._buildHeaders()
|
|
858
|
+
headers: this._buildHeaders(),
|
|
859
|
+
...params
|
|
854
860
|
});
|
|
855
861
|
}
|
|
856
862
|
_concatUrl(url) {
|
|
@@ -898,9 +904,9 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
898
904
|
get logger() {
|
|
899
905
|
return logger;
|
|
900
906
|
}
|
|
901
|
-
async refreshModels() {
|
|
907
|
+
async refreshModels(config) {
|
|
902
908
|
try {
|
|
903
|
-
const rawModels = await this._requester.getModels();
|
|
909
|
+
const rawModels = await this._requester.getModels(config);
|
|
904
910
|
if (!rawModels.length) {
|
|
905
911
|
throw new ChatLunaError2(
|
|
906
912
|
ChatLunaErrorCode2.MODEL_INIT_ERROR,
|
|
@@ -934,6 +940,9 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
934
940
|
}
|
|
935
941
|
return models;
|
|
936
942
|
} catch (e) {
|
|
943
|
+
if (e instanceof ChatLunaError2) {
|
|
944
|
+
throw e;
|
|
945
|
+
}
|
|
937
946
|
throw new ChatLunaError2(ChatLunaErrorCode2.MODEL_INIT_ERROR, e);
|
|
938
947
|
}
|
|
939
948
|
}
|
|
@@ -971,8 +980,7 @@ function apply(ctx, config) {
|
|
|
971
980
|
const plugin = new ChatLunaPlugin(ctx, config, config.platform);
|
|
972
981
|
logger = createLogger(ctx, "chatluna-gemini-adapter");
|
|
973
982
|
ctx.on("ready", async () => {
|
|
974
|
-
plugin.
|
|
975
|
-
await plugin.parseConfig((config2) => {
|
|
983
|
+
plugin.parseConfig((config2) => {
|
|
976
984
|
return config2.apiKeys.map(([apiKey, apiEndpoint]) => {
|
|
977
985
|
return {
|
|
978
986
|
apiKey,
|
package/lib/requester.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Config } from '.';
|
|
|
5
5
|
import { GeminiModelInfo } from './types';
|
|
6
6
|
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
7
7
|
import { Context } from 'koishi';
|
|
8
|
+
import { RunnableConfig } from '@langchain/core/runnables';
|
|
8
9
|
export declare class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
9
10
|
_pluginConfig: Config;
|
|
10
11
|
constructor(ctx: Context, _configPool: ClientConfigPool<ClientConfig>, _pluginConfig: Config, _plugin: ChatLunaPlugin);
|
|
@@ -15,7 +16,7 @@ export declare class GeminiRequester extends ModelRequester implements Embedding
|
|
|
15
16
|
private _prepareEmbeddingsInput;
|
|
16
17
|
private _createEmbeddingsRequest;
|
|
17
18
|
private _processEmbeddingsResponse;
|
|
18
|
-
getModels(): Promise<GeminiModelInfo[]>;
|
|
19
|
+
getModels(config?: RunnableConfig): Promise<GeminiModelInfo[]>;
|
|
19
20
|
private _parseModelsResponse;
|
|
20
21
|
private _filterAndTransformModels;
|
|
21
22
|
private _processResponse;
|
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.9",
|
|
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.9",
|
|
66
66
|
"@langchain/core": "0.3.62",
|
|
67
67
|
"zod": "3.25.76",
|
|
68
68
|
"zod-to-json-schema": "^3.24.5"
|
|
@@ -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.42",
|
|
77
77
|
"koishi-plugin-chatluna-storage-service": "^0.0.9"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|