@chatluna/v1-shared-adapter 1.0.8 → 1.0.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/index.cjs +14 -6
- package/lib/index.mjs +14 -6
- package/lib/requester.d.ts +2 -1
- package/lib/utils.d.ts +2 -2
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -138,7 +138,7 @@ var import_sse = require("koishi-plugin-chatluna/utils/sse");
|
|
|
138
138
|
var import_messages = require("@langchain/core/messages");
|
|
139
139
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
140
140
|
var import_string = require("koishi-plugin-chatluna/utils/string");
|
|
141
|
-
var
|
|
141
|
+
var import_types = require("@langchain/core/utils/types");
|
|
142
142
|
async function langchainMessageToOpenAIMessage(messages, plugin, model, supportImageInput2, removeSystemMessage) {
|
|
143
143
|
const result = [];
|
|
144
144
|
for (const rawMessage of messages) {
|
|
@@ -294,7 +294,7 @@ function formatToolsToOpenAITools(tools, includeGoogleSearch) {
|
|
|
294
294
|
__name(formatToolsToOpenAITools, "formatToolsToOpenAITools");
|
|
295
295
|
function formatToolToOpenAITool(tool) {
|
|
296
296
|
const parameters = removeAdditionalProperties(
|
|
297
|
-
tool.schema
|
|
297
|
+
(0, import_types.isZodSchemaV3)(tool.schema) ? (0, import_zod_to_json_schema.zodToJsonSchema)(tool.schema, {
|
|
298
298
|
allowedAdditionalProperties: void 0
|
|
299
299
|
}) : tool.schema
|
|
300
300
|
);
|
|
@@ -673,21 +673,29 @@ async function createEmbeddings(requestContext, params, embeddingUrl = "embeddin
|
|
|
673
673
|
}
|
|
674
674
|
throw new Error(`Call Embedding Error: ${JSON.stringify(data)}`);
|
|
675
675
|
} catch (e) {
|
|
676
|
-
|
|
676
|
+
if (e instanceof import_error.ChatLunaError) {
|
|
677
|
+
throw e;
|
|
678
|
+
}
|
|
677
679
|
throw new import_error.ChatLunaError(import_error.ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
678
680
|
}
|
|
679
681
|
}
|
|
680
682
|
__name(createEmbeddings, "createEmbeddings");
|
|
681
|
-
async function getModels(requestContext) {
|
|
683
|
+
async function getModels(requestContext, config) {
|
|
682
684
|
const { modelRequester } = requestContext;
|
|
683
685
|
let data;
|
|
684
686
|
try {
|
|
685
|
-
const response = await modelRequester.get(
|
|
687
|
+
const response = await modelRequester.get(
|
|
688
|
+
"models",
|
|
689
|
+
{},
|
|
690
|
+
{ signal: config?.signal }
|
|
691
|
+
);
|
|
686
692
|
data = await response.text();
|
|
687
693
|
data = JSON.parse(data);
|
|
688
694
|
return data.data.map((model) => model.id);
|
|
689
695
|
} catch (e) {
|
|
690
|
-
|
|
696
|
+
if (e instanceof import_error.ChatLunaError) {
|
|
697
|
+
throw e;
|
|
698
|
+
}
|
|
691
699
|
throw new Error(
|
|
692
700
|
"error when listing openai models, Result: " + JSON.stringify(data)
|
|
693
701
|
);
|
package/lib/index.mjs
CHANGED
|
@@ -108,7 +108,7 @@ import {
|
|
|
108
108
|
getImageMimeType,
|
|
109
109
|
isMessageContentImageUrl
|
|
110
110
|
} from "koishi-plugin-chatluna/utils/string";
|
|
111
|
-
import {
|
|
111
|
+
import { isZodSchemaV3 } from "@langchain/core/utils/types";
|
|
112
112
|
async function langchainMessageToOpenAIMessage(messages, plugin, model, supportImageInput2, removeSystemMessage) {
|
|
113
113
|
const result = [];
|
|
114
114
|
for (const rawMessage of messages) {
|
|
@@ -264,7 +264,7 @@ function formatToolsToOpenAITools(tools, includeGoogleSearch) {
|
|
|
264
264
|
__name(formatToolsToOpenAITools, "formatToolsToOpenAITools");
|
|
265
265
|
function formatToolToOpenAITool(tool) {
|
|
266
266
|
const parameters = removeAdditionalProperties(
|
|
267
|
-
tool.schema
|
|
267
|
+
isZodSchemaV3(tool.schema) ? zodToJsonSchema(tool.schema, {
|
|
268
268
|
allowedAdditionalProperties: void 0
|
|
269
269
|
}) : tool.schema
|
|
270
270
|
);
|
|
@@ -643,21 +643,29 @@ async function createEmbeddings(requestContext, params, embeddingUrl = "embeddin
|
|
|
643
643
|
}
|
|
644
644
|
throw new Error(`Call Embedding Error: ${JSON.stringify(data)}`);
|
|
645
645
|
} catch (e) {
|
|
646
|
-
|
|
646
|
+
if (e instanceof ChatLunaError) {
|
|
647
|
+
throw e;
|
|
648
|
+
}
|
|
647
649
|
throw new ChatLunaError(ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
648
650
|
}
|
|
649
651
|
}
|
|
650
652
|
__name(createEmbeddings, "createEmbeddings");
|
|
651
|
-
async function getModels(requestContext) {
|
|
653
|
+
async function getModels(requestContext, config) {
|
|
652
654
|
const { modelRequester } = requestContext;
|
|
653
655
|
let data;
|
|
654
656
|
try {
|
|
655
|
-
const response = await modelRequester.get(
|
|
657
|
+
const response = await modelRequester.get(
|
|
658
|
+
"models",
|
|
659
|
+
{},
|
|
660
|
+
{ signal: config?.signal }
|
|
661
|
+
);
|
|
656
662
|
data = await response.text();
|
|
657
663
|
data = JSON.parse(data);
|
|
658
664
|
return data.data.map((model) => model.id);
|
|
659
665
|
} catch (e) {
|
|
660
|
-
|
|
666
|
+
if (e instanceof ChatLunaError) {
|
|
667
|
+
throw e;
|
|
668
|
+
}
|
|
661
669
|
throw new Error(
|
|
662
670
|
"error when listing openai models, Result: " + JSON.stringify(data)
|
|
663
671
|
);
|
package/lib/requester.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { SSEEvent } from 'koishi-plugin-chatluna/utils/sse';
|
|
|
5
5
|
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
6
6
|
import { Context } from 'koishi';
|
|
7
7
|
import { Response } from 'undici/types/fetch';
|
|
8
|
+
import { RunnableConfig } from '@langchain/core/runnables';
|
|
8
9
|
interface RequestContext<T extends ClientConfig = ClientConfig, R extends ChatLunaPlugin.Config = ChatLunaPlugin.Config> {
|
|
9
10
|
ctx: Context;
|
|
10
11
|
config: T;
|
|
@@ -43,6 +44,6 @@ export declare function processResponse<T extends ClientConfig, R extends ChatLu
|
|
|
43
44
|
export declare function completionStream<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: ModelRequestParams, completionUrl?: string, enableGoogleSearch?: boolean, supportImageInput?: boolean): AsyncGenerator<ChatGenerationChunk>;
|
|
44
45
|
export declare function completion<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: ModelRequestParams, completionUrl?: string, enableGoogleSearch?: boolean, supportImageInput?: boolean): Promise<ChatGenerationChunk>;
|
|
45
46
|
export declare function createEmbeddings<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, params: EmbeddingsRequestParams, embeddingUrl?: string): Promise<number[] | number[][]>;
|
|
46
|
-
export declare function getModels<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R
|
|
47
|
+
export declare function getModels<T extends ClientConfig, R extends ChatLunaPlugin.Config>(requestContext: RequestContext<T, R>, config?: RunnableConfig): Promise<string[]>;
|
|
47
48
|
export declare function createRequestContext<T extends ClientConfig, R extends ChatLunaPlugin.Config>(ctx: Context, config: T, pluginConfig: R, plugin: ChatLunaPlugin, modelRequester: ModelRequester<T, R>): RequestContext<T, R>;
|
|
48
49
|
export {};
|
package/lib/utils.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export declare function messageTypeToOpenAIRole(type: MessageType): ChatCompleti
|
|
|
9
9
|
export declare function formatToolsToOpenAITools(tools: StructuredTool[], includeGoogleSearch: boolean): ChatCompletionTool[];
|
|
10
10
|
export declare function formatToolToOpenAITool(tool: StructuredTool): ChatCompletionTool;
|
|
11
11
|
export declare function removeAdditionalProperties(schema: JsonSchema7Type): JsonSchema7Type;
|
|
12
|
-
export declare function convertMessageToMessageChunk(message: ChatCompletionResponseMessage):
|
|
13
|
-
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum):
|
|
12
|
+
export declare function convertMessageToMessageChunk(message: ChatCompletionResponseMessage): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
|
13
|
+
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatluna/v1-shared-adapter",
|
|
3
3
|
"description": "chatluna shared adapter",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.9",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"koishi": "^4.18.7",
|
|
73
|
-
"koishi-plugin-chatluna": "^1.3.0-alpha.
|
|
73
|
+
"koishi-plugin-chatluna": "^1.3.0-alpha.42"
|
|
74
74
|
}
|
|
75
75
|
}
|