koishi-plugin-chatluna-google-gemini-adapter 1.1.0-beta.1 → 1.1.0-beta.2
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 +18 -0
- package/lib/index.cjs +1 -0
- package/lib/index.d.ts +15 -136
- package/lib/index.mjs +2 -1
- package/lib/requester.d.ts +20 -0
- package/lib/types.d.ts +81 -0
- package/lib/utils.d.ts +10 -0
- package/package.json +2 -2
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
8
|
+
export declare class GeminiClient extends PlatformModelAndEmbeddingsClient {
|
|
9
|
+
private _config;
|
|
10
|
+
platform: string;
|
|
11
|
+
private _requester;
|
|
12
|
+
private _models;
|
|
13
|
+
constructor(ctx: Context, _config: Config, clientConfig: ClientConfig, plugin: ChatLunaPlugin);
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
refreshModels(): Promise<ModelInfo[]>;
|
|
16
|
+
getModels(): Promise<ModelInfo[]>;
|
|
17
|
+
protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
|
|
18
|
+
}
|
package/lib/index.cjs
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,136 +1,15 @@
|
|
|
1
|
-
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
2
|
-
import { Context, Logger, Schema } from 'koishi';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
temperature: number;
|
|
17
|
-
googleSearch: boolean;
|
|
18
|
-
searchThreshold: number;
|
|
19
|
-
groundingContentDisplay: boolean;
|
|
20
|
-
}
|
|
21
|
-
export const Config: Schema<Config>;
|
|
22
|
-
export const inject: string[];
|
|
23
|
-
export const name = "chatluna-google-gemini-adapter";
|
|
24
|
-
export interface ChatCompletionResponseMessage {
|
|
25
|
-
role: string;
|
|
26
|
-
parts?: ChatPart[];
|
|
27
|
-
}
|
|
28
|
-
export type ChatPart = ChatMessagePart | ChatUploadDataPart | ChatFunctionCallingPart | ChatFunctionResponsePart;
|
|
29
|
-
export type ChatMessagePart = {
|
|
30
|
-
text: string;
|
|
31
|
-
thought?: boolean;
|
|
32
|
-
};
|
|
33
|
-
export type ChatUploadDataPart = {
|
|
34
|
-
inline_data: {
|
|
35
|
-
mime_type: string;
|
|
36
|
-
data?: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export type ChatFunctionCallingPart = {
|
|
40
|
-
functionCall: {
|
|
41
|
-
name: string;
|
|
42
|
-
args?: any;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
export type ChatFunctionResponsePart = {
|
|
46
|
-
functionResponse: {
|
|
47
|
-
name: string;
|
|
48
|
-
response: any;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
export interface ChatResponse {
|
|
52
|
-
candidates: {
|
|
53
|
-
content: ChatCompletionResponseMessage;
|
|
54
|
-
groundingMetadata: {
|
|
55
|
-
searchEntryPoint: {
|
|
56
|
-
renderedContent: string;
|
|
57
|
-
};
|
|
58
|
-
groundingChunks: {
|
|
59
|
-
web: {
|
|
60
|
-
uri: string;
|
|
61
|
-
title: string;
|
|
62
|
-
};
|
|
63
|
-
}[];
|
|
64
|
-
groundingSupports: {
|
|
65
|
-
segment: {
|
|
66
|
-
endIndex: number;
|
|
67
|
-
text: string;
|
|
68
|
-
};
|
|
69
|
-
groundingChunkIndices: number[];
|
|
70
|
-
confidenceScores: number[];
|
|
71
|
-
}[];
|
|
72
|
-
webSearchQueries: string[];
|
|
73
|
-
};
|
|
74
|
-
finishReason: string;
|
|
75
|
-
index: number;
|
|
76
|
-
safetyRatings: {
|
|
77
|
-
category: string;
|
|
78
|
-
probability: string;
|
|
79
|
-
}[];
|
|
80
|
-
}[];
|
|
81
|
-
promptFeedback: {
|
|
82
|
-
safetyRatings: {
|
|
83
|
-
category: string;
|
|
84
|
-
probability: string;
|
|
85
|
-
}[];
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
export interface ChatCompletionFunction {
|
|
89
|
-
name: string;
|
|
90
|
-
description?: string;
|
|
91
|
-
parameters?: {
|
|
92
|
-
[key: string]: any;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
export interface ChatCompletionMessageFunctionCall {
|
|
96
|
-
name: string;
|
|
97
|
-
args?: any;
|
|
98
|
-
}
|
|
99
|
-
export interface CreateEmbeddingResponse {
|
|
100
|
-
embeddings: {
|
|
101
|
-
values: number[];
|
|
102
|
-
}[];
|
|
103
|
-
}
|
|
104
|
-
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'model' | 'user' | 'function';
|
|
105
|
-
export function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
|
|
106
|
-
export function partAsType<T extends ChatPart>(part: ChatPart): T;
|
|
107
|
-
export function formatToolsToGeminiAITools(tools: StructuredTool[], config: Config, model: string): Record<string, any>;
|
|
108
|
-
export function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
109
|
-
export function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
110
|
-
export function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | ChatMessageChunk;
|
|
111
|
-
export class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
112
|
-
private _config;
|
|
113
|
-
private _plugin;
|
|
114
|
-
private _pluginConfig;
|
|
115
|
-
constructor(_config: ClientConfig, _plugin: ChatLunaPlugin, _pluginConfig: Config);
|
|
116
|
-
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
117
|
-
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
118
|
-
getModels(): Promise<string[]>;
|
|
119
|
-
private _post;
|
|
120
|
-
private _get;
|
|
121
|
-
private _concatUrl;
|
|
122
|
-
private _buildHeaders;
|
|
123
|
-
init(): Promise<void>;
|
|
124
|
-
dispose(): Promise<void>;
|
|
125
|
-
}
|
|
126
|
-
export class GeminiClient extends PlatformModelAndEmbeddingsClient {
|
|
127
|
-
private _config;
|
|
128
|
-
platform: string;
|
|
129
|
-
private _requester;
|
|
130
|
-
private _models;
|
|
131
|
-
constructor(ctx: Context, _config: Config, clientConfig: ClientConfig, plugin: ChatLunaPlugin);
|
|
132
|
-
init(): Promise<void>;
|
|
133
|
-
refreshModels(): Promise<ModelInfo[]>;
|
|
134
|
-
getModels(): Promise<ModelInfo[]>;
|
|
135
|
-
protected _createModel(model: string): ChatLunaChatModel | ChatHubBaseEmbeddings;
|
|
136
|
-
}
|
|
1
|
+
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
2
|
+
import { Context, Logger, Schema } from 'koishi';
|
|
3
|
+
export declare let logger: Logger;
|
|
4
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
5
|
+
export interface Config extends ChatLunaPlugin.Config {
|
|
6
|
+
apiKeys: [string, string][];
|
|
7
|
+
maxTokens: number;
|
|
8
|
+
temperature: number;
|
|
9
|
+
googleSearch: boolean;
|
|
10
|
+
searchThreshold: number;
|
|
11
|
+
groundingContentDisplay: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const Config: Schema<Config>;
|
|
14
|
+
export declare const inject: string[];
|
|
15
|
+
export declare const name = "chatluna-google-gemini-adapter";
|
package/lib/index.mjs
CHANGED
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
ChatLunaError,
|
|
49
49
|
ChatLunaErrorCode
|
|
50
50
|
} from "koishi-plugin-chatluna/utils/error";
|
|
51
|
-
import { sse } from "koishi-plugin-chatluna/utils/sse";
|
|
51
|
+
import { checkResponse, sse } from "koishi-plugin-chatluna/utils/sse";
|
|
52
52
|
import { readableStreamToAsyncIterable } from "koishi-plugin-chatluna/utils/stream";
|
|
53
53
|
|
|
54
54
|
// src/utils.ts
|
|
@@ -406,6 +406,7 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
};
|
|
409
|
+
await checkResponse(response);
|
|
409
410
|
sse(
|
|
410
411
|
response,
|
|
411
412
|
async (rawData) => {
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
import { Config } from '.';
|
|
5
|
+
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
6
|
+
export declare class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
7
|
+
private _config;
|
|
8
|
+
private _plugin;
|
|
9
|
+
private _pluginConfig;
|
|
10
|
+
constructor(_config: ClientConfig, _plugin: ChatLunaPlugin, _pluginConfig: Config);
|
|
11
|
+
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
12
|
+
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
13
|
+
getModels(): Promise<string[]>;
|
|
14
|
+
private _post;
|
|
15
|
+
private _get;
|
|
16
|
+
private _concatUrl;
|
|
17
|
+
private _buildHeaders;
|
|
18
|
+
init(): Promise<void>;
|
|
19
|
+
dispose(): Promise<void>;
|
|
20
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
thought?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type ChatUploadDataPart = {
|
|
11
|
+
inline_data: {
|
|
12
|
+
mime_type: string;
|
|
13
|
+
data?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type ChatFunctionCallingPart = {
|
|
17
|
+
functionCall: {
|
|
18
|
+
name: string;
|
|
19
|
+
args?: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type ChatFunctionResponsePart = {
|
|
23
|
+
functionResponse: {
|
|
24
|
+
name: string;
|
|
25
|
+
response: any;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export interface ChatResponse {
|
|
29
|
+
candidates: {
|
|
30
|
+
content: ChatCompletionResponseMessage;
|
|
31
|
+
groundingMetadata: {
|
|
32
|
+
searchEntryPoint: {
|
|
33
|
+
renderedContent: string;
|
|
34
|
+
};
|
|
35
|
+
groundingChunks: {
|
|
36
|
+
web: {
|
|
37
|
+
uri: string;
|
|
38
|
+
title: string;
|
|
39
|
+
};
|
|
40
|
+
}[];
|
|
41
|
+
groundingSupports: {
|
|
42
|
+
segment: {
|
|
43
|
+
endIndex: number;
|
|
44
|
+
text: string;
|
|
45
|
+
};
|
|
46
|
+
groundingChunkIndices: number[];
|
|
47
|
+
confidenceScores: number[];
|
|
48
|
+
}[];
|
|
49
|
+
webSearchQueries: string[];
|
|
50
|
+
};
|
|
51
|
+
finishReason: string;
|
|
52
|
+
index: number;
|
|
53
|
+
safetyRatings: {
|
|
54
|
+
category: string;
|
|
55
|
+
probability: string;
|
|
56
|
+
}[];
|
|
57
|
+
}[];
|
|
58
|
+
promptFeedback: {
|
|
59
|
+
safetyRatings: {
|
|
60
|
+
category: string;
|
|
61
|
+
probability: string;
|
|
62
|
+
}[];
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface ChatCompletionFunction {
|
|
66
|
+
name: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
parameters?: {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export interface ChatCompletionMessageFunctionCall {
|
|
73
|
+
name: string;
|
|
74
|
+
args?: any;
|
|
75
|
+
}
|
|
76
|
+
export interface CreateEmbeddingResponse {
|
|
77
|
+
embeddings: {
|
|
78
|
+
values: number[];
|
|
79
|
+
}[];
|
|
80
|
+
}
|
|
81
|
+
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'model' | 'user' | 'function';
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import { Config } from '.';
|
|
5
|
+
export declare function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
|
|
6
|
+
export declare function partAsType<T extends ChatPart>(part: ChatPart): T;
|
|
7
|
+
export declare function formatToolsToGeminiAITools(tools: StructuredTool[], config: Config, model: string): Record<string, any>;
|
|
8
|
+
export declare function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
9
|
+
export declare function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
10
|
+
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | ChatMessageChunk;
|
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.1.0-beta.
|
|
4
|
+
"version": "1.1.0-beta.2",
|
|
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.4",
|
|
76
|
-
"koishi-plugin-chatluna": "^1.1.0-beta.
|
|
76
|
+
"koishi-plugin-chatluna": "^1.1.0-beta.14"
|
|
77
77
|
},
|
|
78
78
|
"koishi": {
|
|
79
79
|
"description": {
|