koishi-plugin-chatluna-google-gemini-adapter 1.2.14 → 1.2.16
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 -7
- package/lib/index.cjs +26 -44
- package/lib/index.mjs +26 -44
- package/lib/requester.d.ts +6 -8
- package/package.json +4 -3
package/lib/client.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
2
|
import { PlatformModelAndEmbeddingsClient } from 'koishi-plugin-chatluna/llm-core/platform/client';
|
|
3
3
|
import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
4
|
-
import {
|
|
4
|
+
import { ChatLunaBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
|
|
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
|
-
export declare class GeminiClient extends PlatformModelAndEmbeddingsClient {
|
|
8
|
+
export declare class GeminiClient extends PlatformModelAndEmbeddingsClient<ClientConfig> {
|
|
9
9
|
private _config;
|
|
10
|
+
plugin: ChatLunaPlugin;
|
|
10
11
|
platform: string;
|
|
11
12
|
private _requester;
|
|
12
|
-
|
|
13
|
-
constructor(ctx: Context, _config: Config,
|
|
14
|
-
init(): Promise<void>;
|
|
13
|
+
get logger(): import("reggol");
|
|
14
|
+
constructor(ctx: Context, _config: Config, plugin: ChatLunaPlugin);
|
|
15
15
|
refreshModels(): Promise<ModelInfo[]>;
|
|
16
|
-
|
|
17
|
-
protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
|
|
16
|
+
protected _createModel(model: string): ChatLunaChatModel | ChatLunaBaseEmbeddings;
|
|
18
17
|
}
|
package/lib/index.cjs
CHANGED
|
@@ -37,7 +37,7 @@ var require_en_US_schema = __commonJS({
|
|
|
37
37
|
// src/index.ts
|
|
38
38
|
var index_exports = {};
|
|
39
39
|
__export(index_exports, {
|
|
40
|
-
Config: () =>
|
|
40
|
+
Config: () => Config4,
|
|
41
41
|
apply: () => apply,
|
|
42
42
|
inject: () => inject,
|
|
43
43
|
logger: () => logger,
|
|
@@ -179,14 +179,10 @@ function extractSystemMessages(messages) {
|
|
|
179
179
|
return [
|
|
180
180
|
{
|
|
181
181
|
role: "user",
|
|
182
|
-
parts:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return acc;
|
|
187
|
-
}, []).map((part) => partAsType(part).text).join("\n\n\n")
|
|
188
|
-
}
|
|
189
|
-
]
|
|
182
|
+
parts: systemMessages.reduce((acc, cur) => {
|
|
183
|
+
acc.push(...cur.parts);
|
|
184
|
+
return acc;
|
|
185
|
+
}, [])
|
|
190
186
|
},
|
|
191
187
|
modelMessages
|
|
192
188
|
];
|
|
@@ -322,16 +318,14 @@ __name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
|
|
|
322
318
|
|
|
323
319
|
// src/requester.ts
|
|
324
320
|
var GeminiRequester = class extends import_api.ModelRequester {
|
|
325
|
-
constructor(
|
|
326
|
-
super();
|
|
327
|
-
this._config = _config;
|
|
328
|
-
this._plugin = _plugin;
|
|
321
|
+
constructor(ctx, _configPool, _pluginConfig, _plugin) {
|
|
322
|
+
super(ctx, _configPool, _pluginConfig, _plugin);
|
|
329
323
|
this._pluginConfig = _pluginConfig;
|
|
330
324
|
}
|
|
331
325
|
static {
|
|
332
326
|
__name(this, "GeminiRequester");
|
|
333
327
|
}
|
|
334
|
-
async *
|
|
328
|
+
async *completionStreamInternal(params) {
|
|
335
329
|
try {
|
|
336
330
|
let model = params.model;
|
|
337
331
|
let enabledThinking = null;
|
|
@@ -638,7 +632,7 @@ ${groundingContent}`
|
|
|
638
632
|
});
|
|
639
633
|
}
|
|
640
634
|
_concatUrl(url) {
|
|
641
|
-
const apiEndPoint = this._config.apiEndpoint;
|
|
635
|
+
const apiEndPoint = this._config.value.apiEndpoint;
|
|
642
636
|
let baseURL;
|
|
643
637
|
if (apiEndPoint.endsWith("/")) {
|
|
644
638
|
baseURL = new URL(apiEndPoint + url);
|
|
@@ -646,31 +640,32 @@ ${groundingContent}`
|
|
|
646
640
|
baseURL = new URL(apiEndPoint + "/" + url);
|
|
647
641
|
}
|
|
648
642
|
const searchParams = baseURL.searchParams;
|
|
649
|
-
searchParams.set("key", this._config.apiKey);
|
|
643
|
+
searchParams.set("key", this._config.value.apiKey);
|
|
650
644
|
return baseURL.toString();
|
|
651
645
|
}
|
|
652
646
|
_buildHeaders() {
|
|
653
647
|
return {
|
|
654
|
-
/* Authorization: `Bearer ${this._config.apiKey}`, */
|
|
648
|
+
/* Authorization: `Bearer ${this._config.value.apiKey}`, */
|
|
655
649
|
"Content-Type": "application/json"
|
|
656
650
|
};
|
|
657
651
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
async dispose() {
|
|
652
|
+
get logger() {
|
|
653
|
+
return logger;
|
|
661
654
|
}
|
|
662
655
|
};
|
|
663
656
|
|
|
664
657
|
// src/client.ts
|
|
665
658
|
var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient {
|
|
666
|
-
constructor(ctx, _config,
|
|
667
|
-
super(ctx,
|
|
659
|
+
constructor(ctx, _config, plugin) {
|
|
660
|
+
super(ctx, plugin.platformConfigPool);
|
|
668
661
|
this._config = _config;
|
|
669
|
-
this.
|
|
662
|
+
this.plugin = plugin;
|
|
663
|
+
this.platform = this._config.platform;
|
|
670
664
|
this._requester = new GeminiRequester(
|
|
671
|
-
|
|
672
|
-
plugin,
|
|
673
|
-
this._config
|
|
665
|
+
ctx,
|
|
666
|
+
plugin.platformConfigPool,
|
|
667
|
+
this._config,
|
|
668
|
+
plugin
|
|
674
669
|
);
|
|
675
670
|
}
|
|
676
671
|
static {
|
|
@@ -678,9 +673,8 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
678
673
|
}
|
|
679
674
|
platform = "gemini";
|
|
680
675
|
_requester;
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
await this.getModels();
|
|
676
|
+
get logger() {
|
|
677
|
+
return logger;
|
|
684
678
|
}
|
|
685
679
|
async refreshModels() {
|
|
686
680
|
try {
|
|
@@ -719,18 +713,8 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
719
713
|
throw new import_error2.ChatLunaError(import_error2.ChatLunaErrorCode.MODEL_INIT_ERROR, e);
|
|
720
714
|
}
|
|
721
715
|
}
|
|
722
|
-
async getModels() {
|
|
723
|
-
if (this._models && Object.keys(this._models).length > 0) {
|
|
724
|
-
return Object.values(this._models);
|
|
725
|
-
}
|
|
726
|
-
const models = await this.refreshModels();
|
|
727
|
-
this._models = {};
|
|
728
|
-
for (const model of models) {
|
|
729
|
-
this._models[model.name] = model;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
716
|
_createModel(model) {
|
|
733
|
-
const info = this.
|
|
717
|
+
const info = this._modelInfos[model];
|
|
734
718
|
if (info == null) {
|
|
735
719
|
throw new import_error2.ChatLunaError(import_error2.ChatLunaErrorCode.MODEL_NOT_FOUND);
|
|
736
720
|
}
|
|
@@ -777,14 +761,12 @@ function apply(ctx, config) {
|
|
|
777
761
|
};
|
|
778
762
|
});
|
|
779
763
|
});
|
|
780
|
-
plugin.registerClient(
|
|
781
|
-
(_, clientConfig) => new GeminiClient(ctx, config, clientConfig, plugin)
|
|
782
|
-
);
|
|
764
|
+
plugin.registerClient((ctx2) => new GeminiClient(ctx2, config, plugin));
|
|
783
765
|
await plugin.initClients();
|
|
784
766
|
});
|
|
785
767
|
}
|
|
786
768
|
__name(apply, "apply");
|
|
787
|
-
var
|
|
769
|
+
var Config4 = import_koishi.Schema.intersect([
|
|
788
770
|
import_chat.ChatLunaPlugin.Config,
|
|
789
771
|
import_koishi.Schema.object({
|
|
790
772
|
platform: import_koishi.Schema.string().default("gemini"),
|
package/lib/index.mjs
CHANGED
|
@@ -172,14 +172,10 @@ function extractSystemMessages(messages) {
|
|
|
172
172
|
return [
|
|
173
173
|
{
|
|
174
174
|
role: "user",
|
|
175
|
-
parts:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return acc;
|
|
180
|
-
}, []).map((part) => partAsType(part).text).join("\n\n\n")
|
|
181
|
-
}
|
|
182
|
-
]
|
|
175
|
+
parts: systemMessages.reduce((acc, cur) => {
|
|
176
|
+
acc.push(...cur.parts);
|
|
177
|
+
return acc;
|
|
178
|
+
}, [])
|
|
183
179
|
},
|
|
184
180
|
modelMessages
|
|
185
181
|
];
|
|
@@ -315,16 +311,14 @@ __name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
|
|
|
315
311
|
|
|
316
312
|
// src/requester.ts
|
|
317
313
|
var GeminiRequester = class extends ModelRequester {
|
|
318
|
-
constructor(
|
|
319
|
-
super();
|
|
320
|
-
this._config = _config;
|
|
321
|
-
this._plugin = _plugin;
|
|
314
|
+
constructor(ctx, _configPool, _pluginConfig, _plugin) {
|
|
315
|
+
super(ctx, _configPool, _pluginConfig, _plugin);
|
|
322
316
|
this._pluginConfig = _pluginConfig;
|
|
323
317
|
}
|
|
324
318
|
static {
|
|
325
319
|
__name(this, "GeminiRequester");
|
|
326
320
|
}
|
|
327
|
-
async *
|
|
321
|
+
async *completionStreamInternal(params) {
|
|
328
322
|
try {
|
|
329
323
|
let model = params.model;
|
|
330
324
|
let enabledThinking = null;
|
|
@@ -631,7 +625,7 @@ ${groundingContent}`
|
|
|
631
625
|
});
|
|
632
626
|
}
|
|
633
627
|
_concatUrl(url) {
|
|
634
|
-
const apiEndPoint = this._config.apiEndpoint;
|
|
628
|
+
const apiEndPoint = this._config.value.apiEndpoint;
|
|
635
629
|
let baseURL;
|
|
636
630
|
if (apiEndPoint.endsWith("/")) {
|
|
637
631
|
baseURL = new URL(apiEndPoint + url);
|
|
@@ -639,31 +633,32 @@ ${groundingContent}`
|
|
|
639
633
|
baseURL = new URL(apiEndPoint + "/" + url);
|
|
640
634
|
}
|
|
641
635
|
const searchParams = baseURL.searchParams;
|
|
642
|
-
searchParams.set("key", this._config.apiKey);
|
|
636
|
+
searchParams.set("key", this._config.value.apiKey);
|
|
643
637
|
return baseURL.toString();
|
|
644
638
|
}
|
|
645
639
|
_buildHeaders() {
|
|
646
640
|
return {
|
|
647
|
-
/* Authorization: `Bearer ${this._config.apiKey}`, */
|
|
641
|
+
/* Authorization: `Bearer ${this._config.value.apiKey}`, */
|
|
648
642
|
"Content-Type": "application/json"
|
|
649
643
|
};
|
|
650
644
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
async dispose() {
|
|
645
|
+
get logger() {
|
|
646
|
+
return logger;
|
|
654
647
|
}
|
|
655
648
|
};
|
|
656
649
|
|
|
657
650
|
// src/client.ts
|
|
658
651
|
var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
659
|
-
constructor(ctx, _config,
|
|
660
|
-
super(ctx,
|
|
652
|
+
constructor(ctx, _config, plugin) {
|
|
653
|
+
super(ctx, plugin.platformConfigPool);
|
|
661
654
|
this._config = _config;
|
|
662
|
-
this.
|
|
655
|
+
this.plugin = plugin;
|
|
656
|
+
this.platform = this._config.platform;
|
|
663
657
|
this._requester = new GeminiRequester(
|
|
664
|
-
|
|
665
|
-
plugin,
|
|
666
|
-
this._config
|
|
658
|
+
ctx,
|
|
659
|
+
plugin.platformConfigPool,
|
|
660
|
+
this._config,
|
|
661
|
+
plugin
|
|
667
662
|
);
|
|
668
663
|
}
|
|
669
664
|
static {
|
|
@@ -671,9 +666,8 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
671
666
|
}
|
|
672
667
|
platform = "gemini";
|
|
673
668
|
_requester;
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
await this.getModels();
|
|
669
|
+
get logger() {
|
|
670
|
+
return logger;
|
|
677
671
|
}
|
|
678
672
|
async refreshModels() {
|
|
679
673
|
try {
|
|
@@ -712,18 +706,8 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
712
706
|
throw new ChatLunaError2(ChatLunaErrorCode2.MODEL_INIT_ERROR, e);
|
|
713
707
|
}
|
|
714
708
|
}
|
|
715
|
-
async getModels() {
|
|
716
|
-
if (this._models && Object.keys(this._models).length > 0) {
|
|
717
|
-
return Object.values(this._models);
|
|
718
|
-
}
|
|
719
|
-
const models = await this.refreshModels();
|
|
720
|
-
this._models = {};
|
|
721
|
-
for (const model of models) {
|
|
722
|
-
this._models[model.name] = model;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
709
|
_createModel(model) {
|
|
726
|
-
const info = this.
|
|
710
|
+
const info = this._modelInfos[model];
|
|
727
711
|
if (info == null) {
|
|
728
712
|
throw new ChatLunaError2(ChatLunaErrorCode2.MODEL_NOT_FOUND);
|
|
729
713
|
}
|
|
@@ -770,14 +754,12 @@ function apply(ctx, config) {
|
|
|
770
754
|
};
|
|
771
755
|
});
|
|
772
756
|
});
|
|
773
|
-
plugin.registerClient(
|
|
774
|
-
(_, clientConfig) => new GeminiClient(ctx, config, clientConfig, plugin)
|
|
775
|
-
);
|
|
757
|
+
plugin.registerClient((ctx2) => new GeminiClient(ctx2, config, plugin));
|
|
776
758
|
await plugin.initClients();
|
|
777
759
|
});
|
|
778
760
|
}
|
|
779
761
|
__name(apply, "apply");
|
|
780
|
-
var
|
|
762
|
+
var Config4 = Schema.intersect([
|
|
781
763
|
ChatLunaPlugin.Config,
|
|
782
764
|
Schema.object({
|
|
783
765
|
platform: Schema.string().default("gemini"),
|
|
@@ -810,7 +792,7 @@ var Config3 = Schema.intersect([
|
|
|
810
792
|
var inject = ["chatluna"];
|
|
811
793
|
var name = "chatluna-google-gemini-adapter";
|
|
812
794
|
export {
|
|
813
|
-
|
|
795
|
+
Config4 as Config,
|
|
814
796
|
apply,
|
|
815
797
|
inject,
|
|
816
798
|
logger,
|
package/lib/requester.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
2
2
|
import { EmbeddingsRequester, EmbeddingsRequestParams, ModelRequester, ModelRequestParams } from 'koishi-plugin-chatluna/llm-core/platform/api';
|
|
3
|
-
import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
3
|
+
import { ClientConfig, ClientConfigPool } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
4
4
|
import { Config } from '.';
|
|
5
5
|
import { GeminiModelInfo } from './types';
|
|
6
6
|
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
7
|
+
import { Context } from 'koishi';
|
|
7
8
|
export declare class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(_config: ClientConfig, _plugin: ChatLunaPlugin, _pluginConfig: Config);
|
|
12
|
-
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
9
|
+
_pluginConfig: Config;
|
|
10
|
+
constructor(ctx: Context, _configPool: ClientConfigPool<ClientConfig>, _pluginConfig: Config, _plugin: ChatLunaPlugin);
|
|
11
|
+
completionStreamInternal(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
13
12
|
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
14
13
|
getModels(): Promise<GeminiModelInfo[]>;
|
|
15
14
|
private _post;
|
|
16
15
|
private _get;
|
|
17
16
|
private _concatUrl;
|
|
18
17
|
private _buildHeaders;
|
|
19
|
-
|
|
20
|
-
dispose(): Promise<void>;
|
|
18
|
+
get logger(): import("reggol");
|
|
21
19
|
}
|
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.2.
|
|
4
|
+
"version": "1.2.16",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@langchain/core": "^0.3.43",
|
|
66
66
|
"zod": "^3.25.0-canary.20250211T214501",
|
|
67
|
-
"zod-to-json-schema": "^3.24.5"
|
|
67
|
+
"zod-to-json-schema": "^3.24.5",
|
|
68
|
+
"@chatluna/v1-shared-adapter": "^1.0.1"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"atsc": "^2.1.0",
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
75
|
"koishi": "^4.18.7",
|
|
75
|
-
"koishi-plugin-chatluna": "^1.3.0-alpha.
|
|
76
|
+
"koishi-plugin-chatluna": "^1.3.0-alpha.10"
|
|
76
77
|
},
|
|
77
78
|
"koishi": {
|
|
78
79
|
"description": {
|