koishi-plugin-chatluna-google-gemini-adapter 1.0.0-beta.14 → 1.0.0-beta.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/README.md +7 -7
- package/lib/index.d.ts +110 -110
- package/lib/index.mjs +6 -1
- package/package.json +2 -2
- package/lib/client.d.ts +0 -17
- package/lib/requester.d.ts +0 -16
- package/lib/types.d.ts +0 -60
- package/lib/utils.d.ts +0 -9
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
## chatluna-google-gemini-adapter
|
|
2
|
-
|
|
3
|
-
## [](https://www.npmjs.com/package/koishi-plugin-chatluna-google-gemini) [](https://www.npmjs.com/package//koishi-plugin-chatluna-google-gemini-adapter)
|
|
4
|
-
|
|
5
|
-
> 为 ChatHub 提供 Google-gemini 支持的适配器
|
|
6
|
-
|
|
7
|
-
[Google-gemini 适配器文档](https://chatluna.dingyi222666.top/guide/configure-model-platform/google-gemini.html)
|
|
1
|
+
## chatluna-google-gemini-adapter
|
|
2
|
+
|
|
3
|
+
## [](https://www.npmjs.com/package/koishi-plugin-chatluna-google-gemini) [](https://www.npmjs.com/package//koishi-plugin-chatluna-google-gemini-adapter)
|
|
4
|
+
|
|
5
|
+
> 为 ChatHub 提供 Google-gemini 支持的适配器
|
|
6
|
+
|
|
7
|
+
[Google-gemini 适配器文档](https://chatluna.dingyi222666.top/guide/configure-model-platform/google-gemini.html)
|
package/lib/index.d.ts
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
2
|
-
import { Context, Logger, Schema } from 'koishi';
|
|
3
|
-
import { AIMessageChunk, BaseMessage, ChatMessageChunk, HumanMessageChunk, MessageType, SystemMessageChunk } from '@langchain/core/messages';
|
|
4
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
5
|
-
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
6
|
-
import { EmbeddingsRequester, EmbeddingsRequestParams, ModelRequester, ModelRequestParams } from 'koishi-plugin-chatluna/llm-core/platform/api';
|
|
7
|
-
import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
8
|
-
import { PlatformModelAndEmbeddingsClient } from 'koishi-plugin-chatluna/llm-core/platform/client';
|
|
9
|
-
import { ChatHubBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
|
|
10
|
-
import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
|
|
11
|
-
export let logger: Logger;
|
|
12
|
-
export function apply(ctx: Context, config: Config): void;
|
|
13
|
-
export interface Config extends ChatLunaPlugin.Config {
|
|
14
|
-
apiKeys: [string, string][];
|
|
15
|
-
maxTokens: number;
|
|
16
|
-
temperature: number;
|
|
17
|
-
}
|
|
18
|
-
export const Config: Schema<Config>;
|
|
19
|
-
export const inject: string[];
|
|
20
|
-
export const name = "chatluna-google-gemini-adapter";
|
|
21
|
-
export interface ChatCompletionResponseMessage {
|
|
22
|
-
role: string;
|
|
23
|
-
parts?: ChatPart[];
|
|
24
|
-
}
|
|
25
|
-
export type ChatPart = ChatMessagePart | ChatUploadDataPart | ChatFunctionCallingPart | ChatFunctionResponsePart;
|
|
26
|
-
export type ChatMessagePart = {
|
|
27
|
-
text: string;
|
|
28
|
-
};
|
|
29
|
-
export type ChatUploadDataPart = {
|
|
30
|
-
inline_data: {
|
|
31
|
-
mime_type: string;
|
|
32
|
-
data?: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export type ChatFunctionCallingPart = {
|
|
36
|
-
functionCall: {
|
|
37
|
-
name: string;
|
|
38
|
-
args?: any;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
export type ChatFunctionResponsePart = {
|
|
42
|
-
functionResponse: {
|
|
43
|
-
name: string;
|
|
44
|
-
response: any;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export interface ChatResponse {
|
|
48
|
-
candidates: {
|
|
49
|
-
content: ChatCompletionResponseMessage;
|
|
50
|
-
finishReason: string;
|
|
51
|
-
index: number;
|
|
52
|
-
safetyRatings: {
|
|
53
|
-
category: string;
|
|
54
|
-
probability: string;
|
|
55
|
-
}[];
|
|
56
|
-
}[];
|
|
57
|
-
promptFeedback: {
|
|
58
|
-
safetyRatings: {
|
|
59
|
-
category: string;
|
|
60
|
-
probability: string;
|
|
61
|
-
}[];
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export interface ChatCompletionFunction {
|
|
65
|
-
name: string;
|
|
66
|
-
description?: string;
|
|
67
|
-
parameters?: {
|
|
68
|
-
[key: string]: any;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export interface ChatCompletionMessageFunctionCall {
|
|
72
|
-
name: string;
|
|
73
|
-
args?: any;
|
|
74
|
-
}
|
|
75
|
-
export interface CreateEmbeddingResponse {
|
|
76
|
-
embedding: {
|
|
77
|
-
values: number[];
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'model' | 'user' | 'function';
|
|
81
|
-
export function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
|
|
82
|
-
export function partAsType<T extends ChatPart>(part: ChatPart): T;
|
|
83
|
-
export function formatToolsToGeminiAITools(tools: StructuredTool[]): ChatCompletionFunction[];
|
|
84
|
-
export function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
85
|
-
export function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
86
|
-
export function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | ChatMessageChunk;
|
|
87
|
-
export class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
88
|
-
private _config;
|
|
89
|
-
constructor(_config: ClientConfig);
|
|
90
|
-
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
91
|
-
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
92
|
-
getModels(): Promise<string[]>;
|
|
93
|
-
private _post;
|
|
94
|
-
private _get;
|
|
95
|
-
private _concatUrl;
|
|
96
|
-
private _buildHeaders;
|
|
97
|
-
init(): Promise<void>;
|
|
98
|
-
dispose(): Promise<void>;
|
|
99
|
-
}
|
|
100
|
-
export class GeminiClient extends PlatformModelAndEmbeddingsClient {
|
|
101
|
-
private _config;
|
|
102
|
-
platform: string;
|
|
103
|
-
private _requester;
|
|
104
|
-
private _models;
|
|
105
|
-
constructor(ctx: Context, _config: Config, clientConfig: ClientConfig);
|
|
106
|
-
init(): Promise<void>;
|
|
107
|
-
refreshModels(): Promise<ModelInfo[]>;
|
|
108
|
-
getModels(): Promise<ModelInfo[]>;
|
|
109
|
-
protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
|
|
110
|
-
}
|
|
1
|
+
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
2
|
+
import { Context, Logger, Schema } from 'koishi';
|
|
3
|
+
import { AIMessageChunk, BaseMessage, ChatMessageChunk, HumanMessageChunk, MessageType, SystemMessageChunk } from '@langchain/core/messages';
|
|
4
|
+
import { StructuredTool } from '@langchain/core/tools';
|
|
5
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
6
|
+
import { EmbeddingsRequester, EmbeddingsRequestParams, ModelRequester, ModelRequestParams } from 'koishi-plugin-chatluna/llm-core/platform/api';
|
|
7
|
+
import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
8
|
+
import { PlatformModelAndEmbeddingsClient } from 'koishi-plugin-chatluna/llm-core/platform/client';
|
|
9
|
+
import { ChatHubBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
|
|
10
|
+
import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
|
|
11
|
+
export let logger: Logger;
|
|
12
|
+
export function apply(ctx: Context, config: Config): void;
|
|
13
|
+
export interface Config extends ChatLunaPlugin.Config {
|
|
14
|
+
apiKeys: [string, string][];
|
|
15
|
+
maxTokens: number;
|
|
16
|
+
temperature: number;
|
|
17
|
+
}
|
|
18
|
+
export const Config: Schema<Config>;
|
|
19
|
+
export const inject: string[];
|
|
20
|
+
export const name = "chatluna-google-gemini-adapter";
|
|
21
|
+
export interface ChatCompletionResponseMessage {
|
|
22
|
+
role: string;
|
|
23
|
+
parts?: ChatPart[];
|
|
24
|
+
}
|
|
25
|
+
export type ChatPart = ChatMessagePart | ChatUploadDataPart | ChatFunctionCallingPart | ChatFunctionResponsePart;
|
|
26
|
+
export type ChatMessagePart = {
|
|
27
|
+
text: string;
|
|
28
|
+
};
|
|
29
|
+
export type ChatUploadDataPart = {
|
|
30
|
+
inline_data: {
|
|
31
|
+
mime_type: string;
|
|
32
|
+
data?: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type ChatFunctionCallingPart = {
|
|
36
|
+
functionCall: {
|
|
37
|
+
name: string;
|
|
38
|
+
args?: any;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type ChatFunctionResponsePart = {
|
|
42
|
+
functionResponse: {
|
|
43
|
+
name: string;
|
|
44
|
+
response: any;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export interface ChatResponse {
|
|
48
|
+
candidates: {
|
|
49
|
+
content: ChatCompletionResponseMessage;
|
|
50
|
+
finishReason: string;
|
|
51
|
+
index: number;
|
|
52
|
+
safetyRatings: {
|
|
53
|
+
category: string;
|
|
54
|
+
probability: string;
|
|
55
|
+
}[];
|
|
56
|
+
}[];
|
|
57
|
+
promptFeedback: {
|
|
58
|
+
safetyRatings: {
|
|
59
|
+
category: string;
|
|
60
|
+
probability: string;
|
|
61
|
+
}[];
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface ChatCompletionFunction {
|
|
65
|
+
name: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
parameters?: {
|
|
68
|
+
[key: string]: any;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface ChatCompletionMessageFunctionCall {
|
|
72
|
+
name: string;
|
|
73
|
+
args?: any;
|
|
74
|
+
}
|
|
75
|
+
export interface CreateEmbeddingResponse {
|
|
76
|
+
embedding: {
|
|
77
|
+
values: number[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'model' | 'user' | 'function';
|
|
81
|
+
export function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
|
|
82
|
+
export function partAsType<T extends ChatPart>(part: ChatPart): T;
|
|
83
|
+
export function formatToolsToGeminiAITools(tools: StructuredTool[]): ChatCompletionFunction[];
|
|
84
|
+
export function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
85
|
+
export function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
86
|
+
export function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | ChatMessageChunk;
|
|
87
|
+
export class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
88
|
+
private _config;
|
|
89
|
+
constructor(_config: ClientConfig);
|
|
90
|
+
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
91
|
+
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
92
|
+
getModels(): Promise<string[]>;
|
|
93
|
+
private _post;
|
|
94
|
+
private _get;
|
|
95
|
+
private _concatUrl;
|
|
96
|
+
private _buildHeaders;
|
|
97
|
+
init(): Promise<void>;
|
|
98
|
+
dispose(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
export class GeminiClient extends PlatformModelAndEmbeddingsClient {
|
|
101
|
+
private _config;
|
|
102
|
+
platform: string;
|
|
103
|
+
private _requester;
|
|
104
|
+
private _models;
|
|
105
|
+
constructor(ctx: Context, _config: Config, clientConfig: ClientConfig);
|
|
106
|
+
init(): Promise<void>;
|
|
107
|
+
refreshModels(): Promise<ModelInfo[]>;
|
|
108
|
+
getModels(): Promise<ModelInfo[]>;
|
|
109
|
+
protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
|
|
110
|
+
}
|
package/lib/index.mjs
CHANGED
|
@@ -35,7 +35,12 @@ import { sse } from "koishi-plugin-chatluna/utils/sse";
|
|
|
35
35
|
import { readableStreamToAsyncIterable } from "koishi-plugin-chatluna/utils/stream";
|
|
36
36
|
|
|
37
37
|
// src/utils.ts
|
|
38
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
AIMessageChunk,
|
|
40
|
+
ChatMessageChunk,
|
|
41
|
+
HumanMessageChunk,
|
|
42
|
+
SystemMessageChunk
|
|
43
|
+
} from "@langchain/core/messages";
|
|
39
44
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
40
45
|
async function langchainMessageToGeminiMessage(messages, model) {
|
|
41
46
|
const mappedMessage = await Promise.all(
|
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.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.15",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"koishi": "^4.17.9",
|
|
62
|
-
"koishi-plugin-chatluna": "^1.0.0-beta.
|
|
62
|
+
"koishi-plugin-chatluna": "^1.0.0-beta.54"
|
|
63
63
|
},
|
|
64
64
|
"koishi": {
|
|
65
65
|
"description": {
|
package/lib/client.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Context } from 'koishi';
|
|
2
|
-
import { PlatformModelAndEmbeddingsClient } from 'koishi-plugin-chatluna/llm-core/platform/client';
|
|
3
|
-
import { ClientConfig } from 'koishi-plugin-chatluna/llm-core/platform/config';
|
|
4
|
-
import { ChatHubBaseEmbeddings, ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model';
|
|
5
|
-
import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types';
|
|
6
|
-
import { Config } from '.';
|
|
7
|
-
export declare class GeminiClient extends PlatformModelAndEmbeddingsClient {
|
|
8
|
-
private _config;
|
|
9
|
-
platform: string;
|
|
10
|
-
private _requester;
|
|
11
|
-
private _models;
|
|
12
|
-
constructor(ctx: Context, _config: Config, clientConfig: ClientConfig);
|
|
13
|
-
init(): Promise<void>;
|
|
14
|
-
refreshModels(): Promise<ModelInfo[]>;
|
|
15
|
-
getModels(): Promise<ModelInfo[]>;
|
|
16
|
-
protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
|
|
17
|
-
}
|
package/lib/requester.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
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';
|
|
4
|
-
export declare class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
5
|
-
private _config;
|
|
6
|
-
constructor(_config: ClientConfig);
|
|
7
|
-
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
8
|
-
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
9
|
-
getModels(): Promise<string[]>;
|
|
10
|
-
private _post;
|
|
11
|
-
private _get;
|
|
12
|
-
private _concatUrl;
|
|
13
|
-
private _buildHeaders;
|
|
14
|
-
init(): Promise<void>;
|
|
15
|
-
dispose(): Promise<void>;
|
|
16
|
-
}
|
package/lib/types.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export interface ChatCompletionResponseMessage {
|
|
2
|
-
role: string;
|
|
3
|
-
parts?: ChatPart[];
|
|
4
|
-
}
|
|
5
|
-
export type ChatPart = ChatMessagePart | ChatUploadDataPart | ChatFunctionCallingPart | ChatFunctionResponsePart;
|
|
6
|
-
export type ChatMessagePart = {
|
|
7
|
-
text: string;
|
|
8
|
-
};
|
|
9
|
-
export type ChatUploadDataPart = {
|
|
10
|
-
inline_data: {
|
|
11
|
-
mime_type: string;
|
|
12
|
-
data?: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export type ChatFunctionCallingPart = {
|
|
16
|
-
functionCall: {
|
|
17
|
-
name: string;
|
|
18
|
-
args?: any;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export type ChatFunctionResponsePart = {
|
|
22
|
-
functionResponse: {
|
|
23
|
-
name: string;
|
|
24
|
-
response: any;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export interface ChatResponse {
|
|
28
|
-
candidates: {
|
|
29
|
-
content: ChatCompletionResponseMessage;
|
|
30
|
-
finishReason: string;
|
|
31
|
-
index: number;
|
|
32
|
-
safetyRatings: {
|
|
33
|
-
category: string;
|
|
34
|
-
probability: string;
|
|
35
|
-
}[];
|
|
36
|
-
}[];
|
|
37
|
-
promptFeedback: {
|
|
38
|
-
safetyRatings: {
|
|
39
|
-
category: string;
|
|
40
|
-
probability: string;
|
|
41
|
-
}[];
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export interface ChatCompletionFunction {
|
|
45
|
-
name: string;
|
|
46
|
-
description?: string;
|
|
47
|
-
parameters?: {
|
|
48
|
-
[key: string]: any;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export interface ChatCompletionMessageFunctionCall {
|
|
52
|
-
name: string;
|
|
53
|
-
args?: any;
|
|
54
|
-
}
|
|
55
|
-
export interface CreateEmbeddingResponse {
|
|
56
|
-
embedding: {
|
|
57
|
-
values: number[];
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'model' | 'user' | 'function';
|
package/lib/utils.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AIMessageChunk, BaseMessage, ChatMessageChunk, HumanMessageChunk, MessageType, SystemMessageChunk } from '@langchain/core/messages';
|
|
2
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { ChatCompletionFunction, ChatCompletionResponseMessage, ChatCompletionResponseMessageRoleEnum, ChatPart } from './types';
|
|
4
|
-
export declare function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
|
|
5
|
-
export declare function partAsType<T extends ChatPart>(part: ChatPart): T;
|
|
6
|
-
export declare function formatToolsToGeminiAITools(tools: StructuredTool[]): ChatCompletionFunction[];
|
|
7
|
-
export declare function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
8
|
-
export declare function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
9
|
-
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | ChatMessageChunk;
|