@chatluna/v1-shared-adapter 1.0.21 → 1.0.22
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 +26 -12
- package/lib/index.mjs +26 -12
- package/lib/utils.d.ts +2 -2
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -215,17 +215,30 @@ async function langchainMessageToOpenAIMessage(messages, plugin, model, supportI
|
|
|
215
215
|
text: rawMessage.content
|
|
216
216
|
}
|
|
217
217
|
];
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
218
|
+
const imageContents = await Promise.all(
|
|
219
|
+
images.map(async (image) => {
|
|
220
|
+
try {
|
|
221
|
+
const url = await fetchImageUrl(plugin, {
|
|
222
|
+
type: "image_url",
|
|
223
|
+
image_url: { url: image }
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
type: "image_url",
|
|
227
|
+
image_url: {
|
|
228
|
+
url,
|
|
229
|
+
detail: "low"
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
} catch {
|
|
233
|
+
return null;
|
|
224
234
|
}
|
|
225
|
-
})
|
|
226
|
-
|
|
235
|
+
})
|
|
236
|
+
);
|
|
237
|
+
msg.content.push(
|
|
238
|
+
...imageContents.filter((content) => content != null)
|
|
239
|
+
);
|
|
227
240
|
} else if (Array.isArray(msg.content) && msg.content.length > 0) {
|
|
228
|
-
|
|
241
|
+
const mappedContent = await Promise.all(
|
|
229
242
|
msg.content.map(async (content) => {
|
|
230
243
|
if (!(0, import_string.isMessageContentImageUrl)(content)) return content;
|
|
231
244
|
try {
|
|
@@ -238,10 +251,11 @@ async function langchainMessageToOpenAIMessage(messages, plugin, model, supportI
|
|
|
238
251
|
}
|
|
239
252
|
};
|
|
240
253
|
} catch {
|
|
241
|
-
return
|
|
254
|
+
return null;
|
|
242
255
|
}
|
|
243
256
|
})
|
|
244
257
|
);
|
|
258
|
+
msg.content = mappedContent.filter((content) => content != null);
|
|
245
259
|
}
|
|
246
260
|
result.push(msg);
|
|
247
261
|
}
|
|
@@ -695,7 +709,7 @@ async function* completionStream(requestContext, params, completionUrl = "chat/c
|
|
|
695
709
|
const iterator = (0, import_sse.sseIterable)(response);
|
|
696
710
|
yield* processStreamResponse(requestContext, iterator);
|
|
697
711
|
} catch (e) {
|
|
698
|
-
if (requestContext.ctx.chatluna.
|
|
712
|
+
if (requestContext.ctx.chatluna.currentConfig.isLog) {
|
|
699
713
|
await (0, import_logger.trackLogToLocal)(
|
|
700
714
|
"Request",
|
|
701
715
|
JSON.stringify(chatCompletionParams),
|
|
@@ -729,7 +743,7 @@ async function completion(requestContext, params, completionUrl = "chat/completi
|
|
|
729
743
|
);
|
|
730
744
|
return await processResponse(requestContext, response);
|
|
731
745
|
} catch (e) {
|
|
732
|
-
if (requestContext.ctx.chatluna.
|
|
746
|
+
if (requestContext.ctx.chatluna.currentConfig.isLog) {
|
|
733
747
|
await (0, import_logger.trackLogToLocal)(
|
|
734
748
|
"Request",
|
|
735
749
|
JSON.stringify(chatCompletionParams),
|
package/lib/index.mjs
CHANGED
|
@@ -181,17 +181,30 @@ async function langchainMessageToOpenAIMessage(messages, plugin, model, supportI
|
|
|
181
181
|
text: rawMessage.content
|
|
182
182
|
}
|
|
183
183
|
];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
const imageContents = await Promise.all(
|
|
185
|
+
images.map(async (image) => {
|
|
186
|
+
try {
|
|
187
|
+
const url = await fetchImageUrl(plugin, {
|
|
188
|
+
type: "image_url",
|
|
189
|
+
image_url: { url: image }
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
type: "image_url",
|
|
193
|
+
image_url: {
|
|
194
|
+
url,
|
|
195
|
+
detail: "low"
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
} catch {
|
|
199
|
+
return null;
|
|
190
200
|
}
|
|
191
|
-
})
|
|
192
|
-
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
msg.content.push(
|
|
204
|
+
...imageContents.filter((content) => content != null)
|
|
205
|
+
);
|
|
193
206
|
} else if (Array.isArray(msg.content) && msg.content.length > 0) {
|
|
194
|
-
|
|
207
|
+
const mappedContent = await Promise.all(
|
|
195
208
|
msg.content.map(async (content) => {
|
|
196
209
|
if (!isMessageContentImageUrl(content)) return content;
|
|
197
210
|
try {
|
|
@@ -204,10 +217,11 @@ async function langchainMessageToOpenAIMessage(messages, plugin, model, supportI
|
|
|
204
217
|
}
|
|
205
218
|
};
|
|
206
219
|
} catch {
|
|
207
|
-
return
|
|
220
|
+
return null;
|
|
208
221
|
}
|
|
209
222
|
})
|
|
210
223
|
);
|
|
224
|
+
msg.content = mappedContent.filter((content) => content != null);
|
|
211
225
|
}
|
|
212
226
|
result.push(msg);
|
|
213
227
|
}
|
|
@@ -661,7 +675,7 @@ async function* completionStream(requestContext, params, completionUrl = "chat/c
|
|
|
661
675
|
const iterator = sseIterable(response);
|
|
662
676
|
yield* processStreamResponse(requestContext, iterator);
|
|
663
677
|
} catch (e) {
|
|
664
|
-
if (requestContext.ctx.chatluna.
|
|
678
|
+
if (requestContext.ctx.chatluna.currentConfig.isLog) {
|
|
665
679
|
await trackLogToLocal(
|
|
666
680
|
"Request",
|
|
667
681
|
JSON.stringify(chatCompletionParams),
|
|
@@ -695,7 +709,7 @@ async function completion(requestContext, params, completionUrl = "chat/completi
|
|
|
695
709
|
);
|
|
696
710
|
return await processResponse(requestContext, response);
|
|
697
711
|
} catch (e) {
|
|
698
|
-
if (requestContext.ctx.chatluna.
|
|
712
|
+
if (requestContext.ctx.chatluna.currentConfig.isLog) {
|
|
699
713
|
await trackLogToLocal(
|
|
700
714
|
"Request",
|
|
701
715
|
JSON.stringify(chatCompletionParams),
|
package/lib/utils.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ export declare function messageTypeToOpenAIRole(type: MessageType): ChatCompleti
|
|
|
11
11
|
export declare function formatToolsToOpenAITools(tools: StructuredTool[], includeGoogleSearch: boolean): ChatCompletionTool[];
|
|
12
12
|
export declare function formatToolToOpenAITool(tool: StructuredTool): ChatCompletionTool;
|
|
13
13
|
export declare function removeAdditionalProperties(schema: JsonSchema7Type): JsonSchema7Type;
|
|
14
|
-
export declare function convertMessageToMessageChunk(message: ChatCompletionResponseMessage):
|
|
15
|
-
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum):
|
|
14
|
+
export declare function convertMessageToMessageChunk(message: ChatCompletionResponseMessage): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | FunctionMessageChunk | ToolMessageChunk | ChatMessageChunk;
|
|
15
|
+
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.22",
|
|
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.9",
|
|
73
|
-
"koishi-plugin-chatluna": "^1.3.
|
|
73
|
+
"koishi-plugin-chatluna": "^1.3.14"
|
|
74
74
|
}
|
|
75
75
|
}
|