@llumiverse/core 0.20.0 → 0.21.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/lib/cjs/CompletionStream.js +1 -1
- package/lib/cjs/CompletionStream.js.map +1 -1
- package/lib/cjs/capability/bedrock.js +186 -0
- package/lib/cjs/capability/bedrock.js.map +1 -0
- package/lib/cjs/capability/openai.js +122 -0
- package/lib/cjs/capability/openai.js.map +1 -0
- package/lib/cjs/capability/vertexai.js +90 -0
- package/lib/cjs/capability/vertexai.js.map +1 -0
- package/lib/cjs/capability.js +52 -0
- package/lib/cjs/capability.js.map +1 -0
- package/lib/cjs/formatters/index.js +0 -1
- package/lib/cjs/formatters/index.js.map +1 -1
- package/lib/cjs/options/bedrock.js +343 -0
- package/lib/cjs/options/bedrock.js.map +1 -0
- package/lib/cjs/options/groq.js +37 -0
- package/lib/cjs/options/groq.js.map +1 -0
- package/lib/cjs/options/openai.js +123 -0
- package/lib/cjs/options/openai.js.map +1 -0
- package/lib/cjs/options/vertexai.js +257 -0
- package/lib/cjs/options/vertexai.js.map +1 -0
- package/lib/cjs/options.js +19 -0
- package/lib/cjs/options.js.map +1 -0
- package/lib/cjs/stream.js +3 -1
- package/lib/cjs/stream.js.map +1 -1
- package/lib/cjs/types.js +80 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/esm/CompletionStream.js +1 -1
- package/lib/esm/CompletionStream.js.map +1 -1
- package/lib/esm/capability/bedrock.js +183 -0
- package/lib/esm/capability/bedrock.js.map +1 -0
- package/lib/esm/capability/openai.js +119 -0
- package/lib/esm/capability/openai.js.map +1 -0
- package/lib/esm/capability/vertexai.js +87 -0
- package/lib/esm/capability/vertexai.js.map +1 -0
- package/lib/esm/capability.js +47 -0
- package/lib/esm/capability.js.map +1 -0
- package/lib/esm/formatters/index.js +0 -1
- package/lib/esm/formatters/index.js.map +1 -1
- package/lib/esm/options/bedrock.js +340 -0
- package/lib/esm/options/bedrock.js.map +1 -0
- package/lib/esm/options/groq.js +34 -0
- package/lib/esm/options/groq.js.map +1 -0
- package/lib/esm/options/openai.js +120 -0
- package/lib/esm/options/openai.js.map +1 -0
- package/lib/esm/options/vertexai.js +253 -0
- package/lib/esm/options/vertexai.js.map +1 -0
- package/lib/esm/options.js +16 -0
- package/lib/esm/options.js.map +1 -0
- package/lib/esm/stream.js +3 -1
- package/lib/esm/stream.js.map +1 -1
- package/lib/esm/types.js +77 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/CompletionStream.d.ts +1 -1
- package/lib/types/CompletionStream.d.ts.map +1 -1
- package/lib/types/capability/bedrock.d.ts +6 -0
- package/lib/types/capability/bedrock.d.ts.map +1 -0
- package/lib/types/capability/openai.d.ts +10 -0
- package/lib/types/capability/openai.d.ts.map +1 -0
- package/lib/types/capability/vertexai.d.ts +10 -0
- package/lib/types/capability/vertexai.d.ts.map +1 -0
- package/lib/types/capability.d.ts +4 -0
- package/lib/types/capability.d.ts.map +1 -0
- package/lib/types/formatters/index.d.ts +0 -1
- package/lib/types/formatters/index.d.ts.map +1 -1
- package/lib/types/options/bedrock.d.ts +31 -0
- package/lib/types/options/bedrock.d.ts.map +1 -0
- package/lib/types/options/groq.d.ts +11 -0
- package/lib/types/options/groq.d.ts.map +1 -0
- package/lib/types/options/openai.d.ts +20 -0
- package/lib/types/options/openai.d.ts.map +1 -0
- package/lib/types/options/vertexai.d.ts +51 -0
- package/lib/types/options/vertexai.d.ts.map +1 -0
- package/lib/types/options.d.ts +2 -0
- package/lib/types/options.d.ts.map +1 -0
- package/lib/types/stream.d.ts.map +1 -1
- package/lib/types/types.d.ts +322 -0
- package/lib/types/types.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/CompletionStream.ts +2 -2
- package/src/formatters/index.ts +0 -1
- package/src/stream.ts +3 -1
- package/src/formatters/openai.ts +0 -159
package/src/formatters/openai.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { PromptRole, PromptOptions } from "@llumiverse/common";
|
|
2
|
-
import { readStreamAsBase64 } from "../stream.js";
|
|
3
|
-
import { PromptSegment } from "@llumiverse/common";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export interface OpenAITextMessage {
|
|
7
|
-
content: string;
|
|
8
|
-
role: "system" | "user" | "assistant";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface OpenAIMessage {
|
|
12
|
-
content: (OpenAIContentPartText | OpenAIContentPartImage)[]
|
|
13
|
-
role: "system" | "user" | "assistant";
|
|
14
|
-
name?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface OpenAIToolMessage {
|
|
17
|
-
role: "tool";
|
|
18
|
-
tool_call_id: string;
|
|
19
|
-
content: string;
|
|
20
|
-
}
|
|
21
|
-
export type OpenAIInputMessage = OpenAIMessage | OpenAIToolMessage;
|
|
22
|
-
|
|
23
|
-
export interface OpenAIContentPartText {
|
|
24
|
-
type: "text";
|
|
25
|
-
text: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface OpenAIContentPartImage {
|
|
29
|
-
type: "image_url";
|
|
30
|
-
image_url: {
|
|
31
|
-
detail?: 'auto' | 'low' | 'high'
|
|
32
|
-
url: string
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* OpenAI text only prompts
|
|
38
|
-
* @param segments
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
export function formatOpenAILikeTextPrompt(segments: PromptSegment[]): OpenAITextMessage[] {
|
|
42
|
-
const system: OpenAITextMessage[] = [];
|
|
43
|
-
const safety: OpenAITextMessage[] = [];
|
|
44
|
-
const user: OpenAITextMessage[] = [];
|
|
45
|
-
|
|
46
|
-
for (const msg of segments) {
|
|
47
|
-
if (msg.role === PromptRole.system) {
|
|
48
|
-
system.push({ content: msg.content, role: "system" });
|
|
49
|
-
} else if (msg.role === PromptRole.safety) {
|
|
50
|
-
safety.push({ content: "IMPORTANT: " + msg.content, role: "system" });
|
|
51
|
-
} else if (msg.role !== PromptRole.negative && msg.role !== PromptRole.mask && msg.role !== PromptRole.tool) {
|
|
52
|
-
user.push({
|
|
53
|
-
content: msg.content,
|
|
54
|
-
role: msg.role || 'user',
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// put system messages first and safety last
|
|
60
|
-
return system.concat(user).concat(safety);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export async function formatOpenAILikeMultimodalPrompt(segments: PromptSegment[], opts: PromptOptions & OpenAIPromptFormatterOptions): Promise<OpenAIInputMessage[]> {
|
|
65
|
-
const system: OpenAIMessage[] = [];
|
|
66
|
-
const safety: OpenAIMessage[] = [];
|
|
67
|
-
const others: OpenAIInputMessage[] = [];
|
|
68
|
-
|
|
69
|
-
for (const msg of segments) {
|
|
70
|
-
|
|
71
|
-
const parts: (OpenAIContentPartImage | OpenAIContentPartText)[] = [];
|
|
72
|
-
|
|
73
|
-
//generate the parts based on PromptSegment
|
|
74
|
-
if (msg.files) {
|
|
75
|
-
for (const file of msg.files) {
|
|
76
|
-
const stream = await file.getStream();
|
|
77
|
-
const data = await readStreamAsBase64(stream);
|
|
78
|
-
parts.push({
|
|
79
|
-
type: "image_url",
|
|
80
|
-
image_url: {
|
|
81
|
-
url: `data:${file.mime_type || "image/jpeg"};base64,${data}`,
|
|
82
|
-
//detail: "auto" //This is modified just before execution to "low" | "high" | "auto"
|
|
83
|
-
},
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (msg.content) {
|
|
89
|
-
parts.push({
|
|
90
|
-
text: msg.content,
|
|
91
|
-
type: "text"
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (msg.role === PromptRole.system) {
|
|
97
|
-
system.push({
|
|
98
|
-
role: "system",
|
|
99
|
-
content: parts
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (opts.useToolForFormatting && opts.schema) {
|
|
104
|
-
system.forEach(s => {
|
|
105
|
-
s.content.forEach(c => {
|
|
106
|
-
if (c.type === "text") c.text = "TOOL: " + c.text;
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
} else if (msg.role === PromptRole.safety) {
|
|
112
|
-
const safetyMsg: OpenAIMessage = {
|
|
113
|
-
role: "system",
|
|
114
|
-
content: parts
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
safetyMsg.content.forEach(c => {
|
|
118
|
-
if (c.type === "text") c.text = "DO NOT IGNORE - IMPORTANT: " + c.text;
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
system.push(safetyMsg)
|
|
122
|
-
} else if (msg.role === PromptRole.tool) {
|
|
123
|
-
if (!msg.tool_use_id) {
|
|
124
|
-
throw new Error("Tool use id is required for tool messages")
|
|
125
|
-
}
|
|
126
|
-
others.push({
|
|
127
|
-
role: "tool",
|
|
128
|
-
tool_call_id: msg.tool_use_id,
|
|
129
|
-
content: msg.content
|
|
130
|
-
})
|
|
131
|
-
} else if (msg.role !== PromptRole.negative && msg.role !== PromptRole.mask) {
|
|
132
|
-
others.push({
|
|
133
|
-
role: msg.role ?? 'user',
|
|
134
|
-
content: parts
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (opts.result_schema && !opts.useToolForFormatting) {
|
|
141
|
-
system.push({
|
|
142
|
-
role: "system",
|
|
143
|
-
content: [{
|
|
144
|
-
type: "text",
|
|
145
|
-
text: "IMPORTANT: only answer using JSON, and respecting the schema included below, between the <response_schema> tags. " + `<response_schema>${JSON.stringify(opts.result_schema)}</response_schema>`
|
|
146
|
-
}]
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// put system messages first and safety last
|
|
151
|
-
return ([] as OpenAIInputMessage[]).concat(system).concat(others).concat(safety);
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export interface OpenAIPromptFormatterOptions {
|
|
156
|
-
multimodal?: boolean
|
|
157
|
-
useToolForFormatting?: boolean
|
|
158
|
-
schema?: Object
|
|
159
|
-
}
|