@baishuyun/coze-provider 1.0.2 → 1.1.0
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/.turbo/turbo-build.log +23 -22
- package/CHANGELOG.md +12 -0
- package/dist/index.js +31 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/utils/prompt-to-model-msg.ts +38 -31
|
@@ -19,51 +19,58 @@ type userMsg = {
|
|
|
19
19
|
content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return part.text;
|
|
27
|
-
}
|
|
22
|
+
const getPartType = (part: LanguageModelV2TextPart | LanguageModelV2FilePart) => {
|
|
23
|
+
if (part.type === 'text') {
|
|
24
|
+
return 'text';
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
part.mediaType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
27
|
+
const isImg = part.mediaType?.startsWith('image/');
|
|
28
|
+
if (isImg) {
|
|
29
|
+
return 'image';
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const isAudio = part.mediaType?.startsWith('audio/');
|
|
33
|
+
if (isAudio) {
|
|
34
|
+
return 'audio';
|
|
35
|
+
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
return 'file';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const parseMessageContent = (message: LanguageModelV2Message, isTextOnly?: boolean) => {
|
|
41
|
+
if (isTextOnly) {
|
|
42
|
+
return (message.content as Array<LanguageModelV2TextPart>)
|
|
43
|
+
.map((part: LanguageModelV2TextPart) => part.text)
|
|
44
|
+
.join('\n');
|
|
45
|
+
}
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
const result = (message.content as Array<LanguageModelV2TextPart | LanguageModelV2FilePart>).map(
|
|
48
|
+
(part) => {
|
|
49
|
+
const meta = part.providerOptions?.uploadMetadata as Attachment;
|
|
50
|
+
const url = meta?.url;
|
|
47
51
|
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
return {
|
|
53
|
+
type: getPartType(part),
|
|
54
|
+
text: part.type === 'text' ? (part as LanguageModelV2TextPart).text : '',
|
|
55
|
+
file_url: part.type === 'text' ? undefined : url,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
);
|
|
51
59
|
|
|
52
|
-
return result;
|
|
60
|
+
return JSON.stringify(result);
|
|
53
61
|
};
|
|
54
62
|
|
|
63
|
+
const isTextOnlyMsg = (message: userMsg) => message.content.every((part) => part.type === 'text');
|
|
64
|
+
|
|
55
65
|
export const convertPromptToMessages = (messages: LanguageModelV2Prompt) => {
|
|
56
66
|
return messages.map((message) => {
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
const isTextOnly = isTextOnlyMsg(message as userMsg);
|
|
59
68
|
switch (message.role) {
|
|
60
69
|
case 'user':
|
|
61
70
|
return {
|
|
62
71
|
role: RoleType.User,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
content: parseMessageContent(message) || '',
|
|
66
|
-
content_type: 'text',
|
|
72
|
+
content: parseMessageContent(message, isTextOnly),
|
|
73
|
+
content_type: isTextOnly ? 'text' : 'object_string',
|
|
67
74
|
};
|
|
68
75
|
break;
|
|
69
76
|
|