@llumiverse/core 0.15.0 → 0.17.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/README.md +3 -3
- package/lib/cjs/CompletionStream.js +31 -10
- package/lib/cjs/CompletionStream.js.map +1 -1
- package/lib/cjs/Driver.js +20 -22
- package/lib/cjs/Driver.js.map +1 -1
- package/lib/cjs/async.js +3 -2
- package/lib/cjs/async.js.map +1 -1
- package/lib/cjs/formatters/commons.js.map +1 -1
- package/lib/cjs/formatters/generic.js.map +1 -1
- package/lib/cjs/formatters/index.js +1 -3
- package/lib/cjs/formatters/index.js.map +1 -1
- package/lib/cjs/formatters/{claude.js → nova.js} +33 -37
- package/lib/cjs/formatters/nova.js.map +1 -0
- package/lib/cjs/formatters/openai.js +36 -6
- package/lib/cjs/formatters/openai.js.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/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 +54 -0
- package/lib/cjs/options.js.map +1 -0
- package/lib/cjs/types.js +34 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/CompletionStream.js +31 -10
- package/lib/esm/CompletionStream.js.map +1 -1
- package/lib/esm/Driver.js +21 -23
- package/lib/esm/Driver.js.map +1 -1
- package/lib/esm/async.js +3 -2
- package/lib/esm/async.js.map +1 -1
- package/lib/esm/formatters/commons.js.map +1 -1
- package/lib/esm/formatters/generic.js.map +1 -1
- package/lib/esm/formatters/index.js +1 -3
- package/lib/esm/formatters/index.js.map +1 -1
- package/lib/esm/formatters/{claude.js → nova.js} +32 -36
- package/lib/esm/formatters/nova.js.map +1 -0
- package/lib/esm/formatters/openai.js +36 -6
- package/lib/esm/formatters/openai.js.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/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 +50 -0
- package/lib/esm/options.js.map +1 -0
- package/lib/esm/types.js +33 -0
- package/lib/esm/types.js.map +1 -1
- package/lib/types/CompletionStream.d.ts +1 -1
- package/lib/types/CompletionStream.d.ts.map +1 -1
- package/lib/types/Driver.d.ts +5 -4
- package/lib/types/Driver.d.ts.map +1 -1
- package/lib/types/async.d.ts +3 -2
- package/lib/types/async.d.ts.map +1 -1
- package/lib/types/formatters/commons.d.ts +2 -2
- package/lib/types/formatters/commons.d.ts.map +1 -1
- package/lib/types/formatters/generic.d.ts +3 -3
- package/lib/types/formatters/generic.d.ts.map +1 -1
- package/lib/types/formatters/index.d.ts +3 -5
- package/lib/types/formatters/index.d.ts.map +1 -1
- package/lib/types/formatters/nova.d.ts +40 -0
- package/lib/types/formatters/nova.d.ts.map +1 -0
- package/lib/types/formatters/openai.d.ts +13 -1
- package/lib/types/formatters/openai.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/options/bedrock.d.ts +32 -0
- package/lib/types/options/bedrock.d.ts.map +1 -0
- package/lib/types/options/groq.d.ts +12 -0
- package/lib/types/options/groq.d.ts.map +1 -0
- package/lib/types/options/openai.d.ts +21 -0
- package/lib/types/options/openai.d.ts.map +1 -0
- package/lib/types/options/vertexai.d.ts +52 -0
- package/lib/types/options/vertexai.d.ts.map +1 -0
- package/lib/types/options.d.ts +14 -0
- package/lib/types/options.d.ts.map +1 -0
- package/lib/types/types.d.ts +151 -52
- package/lib/types/types.d.ts.map +1 -1
- package/package.json +6 -8
- package/src/CompletionStream.ts +31 -11
- package/src/Driver.ts +30 -26
- package/src/async.ts +7 -5
- package/src/formatters/commons.ts +2 -2
- package/src/formatters/generic.ts +2 -2
- package/src/formatters/index.ts +3 -6
- package/src/formatters/nova.ts +141 -0
- package/src/formatters/openai.ts +52 -12
- package/src/index.ts +2 -1
- package/src/options/bedrock.ts +388 -0
- package/src/options/groq.ts +47 -0
- package/src/options/openai.ts +148 -0
- package/src/options/vertexai.ts +312 -0
- package/src/options.ts +62 -0
- package/src/types.ts +192 -53
- package/lib/cjs/formatters/claude.js.map +0 -1
- package/lib/cjs/formatters/llama2.js +0 -48
- package/lib/cjs/formatters/llama2.js.map +0 -1
- package/lib/cjs/formatters/llama3.js +0 -42
- package/lib/cjs/formatters/llama3.js.map +0 -1
- package/lib/esm/formatters/claude.js.map +0 -1
- package/lib/esm/formatters/llama2.js +0 -45
- package/lib/esm/formatters/llama2.js.map +0 -1
- package/lib/esm/formatters/llama3.js +0 -39
- package/lib/esm/formatters/llama3.js.map +0 -1
- package/lib/types/formatters/claude.d.ts +0 -25
- package/lib/types/formatters/claude.d.ts.map +0 -1
- package/lib/types/formatters/llama2.d.ts +0 -4
- package/lib/types/formatters/llama2.d.ts.map +0 -1
- package/lib/types/formatters/llama3.d.ts +0 -7
- package/lib/types/formatters/llama3.d.ts.map +0 -1
- package/src/formatters/claude.ts +0 -131
- package/src/formatters/llama2.ts +0 -58
- package/src/formatters/llama3.ts +0 -55
package/src/types.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { PromptFormatter } from './formatters/index.js';
|
|
2
|
+
import { JSONObject } from './json.js';
|
|
3
|
+
import { TextFallbackOptions } from './options.js';
|
|
4
|
+
import { BedrockOptions } from './options/bedrock.js';
|
|
5
|
+
import { OpenAiOptions } from './options/openai.js';
|
|
6
|
+
import { VertexAIOptions } from './options/vertexai.js';
|
|
4
7
|
|
|
5
8
|
export interface EmbeddingsOptions {
|
|
6
9
|
/**
|
|
7
|
-
* The
|
|
10
|
+
* The text to generate the embeddings for. One of text or image is required.
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
text?: string;
|
|
10
13
|
/**
|
|
11
|
-
* The
|
|
14
|
+
* The image to generate embeddings for
|
|
12
15
|
*/
|
|
13
|
-
|
|
16
|
+
image?: string
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
16
|
-
* The supported properties depends on the target implementation.
|
|
18
|
+
* The model to use to generate the embeddings. Optional.
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
model?: string;
|
|
21
|
+
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export interface EmbeddingsResult {
|
|
@@ -26,32 +29,63 @@ export interface EmbeddingsResult {
|
|
|
26
29
|
/**
|
|
27
30
|
* The model used to hgenerate the embeddings.
|
|
28
31
|
*/
|
|
29
|
-
model
|
|
32
|
+
model: string;
|
|
30
33
|
/**
|
|
31
34
|
* Number of tokens of the input text.
|
|
32
35
|
*/
|
|
33
36
|
token_count?: number;
|
|
34
|
-
|
|
35
|
-
* Additional properties. Depends on the target implementation.
|
|
36
|
-
*/
|
|
37
|
-
[key: string]: any;
|
|
37
|
+
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export interface ResultValidationError {
|
|
41
|
-
code: 'validation_error' | 'json_error';
|
|
41
|
+
code: 'validation_error' | 'json_error' | 'content_policy_violation';
|
|
42
42
|
message: string;
|
|
43
43
|
data?: string;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
//ResultT should be either JSONObject or string
|
|
47
|
+
//Internal structure used in driver implementation.
|
|
48
|
+
export interface CompletionChunkObject<ResultT = any> {
|
|
49
|
+
result: ResultT;
|
|
50
|
+
token_usage?: ExecutionTokenUsage;
|
|
51
|
+
finish_reason?: "stop" | "length" | string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//Internal structure used in driver implementation.
|
|
55
|
+
export type CompletionChunk = CompletionChunkObject | string;
|
|
56
|
+
|
|
57
|
+
export interface ToolDefinition {
|
|
58
|
+
name: string,
|
|
59
|
+
description?: string,
|
|
60
|
+
input_schema: {
|
|
61
|
+
type: 'object';
|
|
62
|
+
properties?: unknown | null | undefined;
|
|
63
|
+
[k: string]: unknown;
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A tool use instance represents a call to a tool.
|
|
68
|
+
* The id property is used to identify the tool call.
|
|
69
|
+
*/
|
|
70
|
+
export interface ToolUse<ParamsT = JSONObject> {
|
|
71
|
+
id: string,
|
|
72
|
+
tool_name: string,
|
|
73
|
+
tool_input: ParamsT | null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//ResultT should be either JSONObject or string
|
|
46
77
|
export interface Completion<ResultT = any> {
|
|
47
78
|
// the driver impl must return the result and optionally the token_usage. the execution time is computed by the extended abstract driver
|
|
48
79
|
result: ResultT;
|
|
49
80
|
token_usage?: ExecutionTokenUsage;
|
|
50
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Contains the tools from which the model awaits information.
|
|
83
|
+
*/
|
|
84
|
+
tool_use?: ToolUse[];
|
|
51
85
|
/**
|
|
52
86
|
* The finish reason as reported by the model: stop | length or other model specific values
|
|
53
87
|
*/
|
|
54
|
-
finish_reason?: "stop" | "length" | string;
|
|
88
|
+
finish_reason?: "stop" | "length" | "tool_use" | string;
|
|
55
89
|
|
|
56
90
|
/**
|
|
57
91
|
* Set only if a result validation error occured, otherwise if the result is valid the error field is undefined
|
|
@@ -64,6 +98,16 @@ export interface Completion<ResultT = any> {
|
|
|
64
98
|
*/
|
|
65
99
|
original_response?: Record<string, any>;
|
|
66
100
|
|
|
101
|
+
/**
|
|
102
|
+
* The conversation context. This is an opaque structure that can be passed to the next request to restore the context.
|
|
103
|
+
*/
|
|
104
|
+
conversation?: unknown;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ImageGeneration {
|
|
108
|
+
|
|
109
|
+
images?: string[];
|
|
110
|
+
|
|
67
111
|
}
|
|
68
112
|
|
|
69
113
|
export interface ExecutionResponse<PromptT = any> extends Completion {
|
|
@@ -72,6 +116,10 @@ export interface ExecutionResponse<PromptT = any> extends Completion {
|
|
|
72
116
|
* The time it took to execute the request in seconds
|
|
73
117
|
*/
|
|
74
118
|
execution_time?: number;
|
|
119
|
+
/**
|
|
120
|
+
* The number of chunks for streamed executions
|
|
121
|
+
*/
|
|
122
|
+
chunks?: number;
|
|
75
123
|
}
|
|
76
124
|
|
|
77
125
|
|
|
@@ -90,6 +138,27 @@ export interface DriverOptions {
|
|
|
90
138
|
logger?: Logger | "console";
|
|
91
139
|
}
|
|
92
140
|
|
|
141
|
+
export type JSONSchema4TypeName =
|
|
142
|
+
| "string" //
|
|
143
|
+
| "number"
|
|
144
|
+
| "integer"
|
|
145
|
+
| "boolean"
|
|
146
|
+
| "object"
|
|
147
|
+
| "array"
|
|
148
|
+
| "null"
|
|
149
|
+
| "any";
|
|
150
|
+
|
|
151
|
+
export interface JSONSchema {
|
|
152
|
+
type?: JSONSchema4TypeName | JSONSchema4TypeName[];
|
|
153
|
+
description?: string;
|
|
154
|
+
properties?: Record<string, JSONSchema>;
|
|
155
|
+
required?: string[];
|
|
156
|
+
[k: string]: any;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//Options are split into PromptOptions, ModelOptions and ExecutionOptions.
|
|
160
|
+
//ExecutionOptions are most often used within llumiverse as they are the most complete.
|
|
161
|
+
//The base types are useful for external code that needs to interact with llumiverse.
|
|
93
162
|
export interface PromptOptions {
|
|
94
163
|
model: string;
|
|
95
164
|
/**
|
|
@@ -97,52 +166,105 @@ export interface PromptOptions {
|
|
|
97
166
|
* If no one is specified the driver will choose a formatter compatible with the target model
|
|
98
167
|
*/
|
|
99
168
|
format?: PromptFormatter;
|
|
100
|
-
result_schema?:
|
|
169
|
+
result_schema?: JSONSchema;
|
|
101
170
|
}
|
|
102
|
-
export interface ExecutionOptions extends PromptOptions {
|
|
103
|
-
temperature?: number;
|
|
104
|
-
max_tokens?: number;
|
|
105
|
-
stop_sequence?: string | string[];
|
|
106
171
|
|
|
172
|
+
export interface StatelessExecutionOptions extends PromptOptions {
|
|
107
173
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* - 50 - result will be more creative but maintaining a balance between control and creativity
|
|
112
|
-
* - 100 - will lead to more creative and less predictable outputs
|
|
113
|
-
* It will be ignored on OpenAI since it does not support it
|
|
174
|
+
* If set to true the original response from the target LLM will be included in the response under the original_response field.
|
|
175
|
+
* This is useful for debugging and for some advanced use cases.
|
|
176
|
+
* It is ignored on streaming requests
|
|
114
177
|
*/
|
|
115
|
-
|
|
178
|
+
include_original_response?: boolean;
|
|
179
|
+
model_options?: ModelOptions;
|
|
180
|
+
output_modality: Modalities;
|
|
181
|
+
}
|
|
116
182
|
|
|
183
|
+
export interface ExecutionOptions extends StatelessExecutionOptions {
|
|
117
184
|
/**
|
|
118
|
-
*
|
|
119
|
-
* Either use temperature or top_p, not both
|
|
185
|
+
* Available tools for the request
|
|
120
186
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
187
|
+
tools?: ToolDefinition[];
|
|
123
188
|
/**
|
|
124
|
-
*
|
|
189
|
+
* This is an opaque structure that provides a conversation context
|
|
190
|
+
* Each driver implementation will return a conversation property in the execution response
|
|
191
|
+
* that can be passed here to restore the context when a new prompt is sent to the model.
|
|
125
192
|
*/
|
|
126
|
-
|
|
193
|
+
conversation?: unknown | null;
|
|
194
|
+
}
|
|
127
195
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
196
|
+
//Common names to share between different models
|
|
197
|
+
export enum SharedOptions {
|
|
198
|
+
//Text
|
|
199
|
+
max_tokens = "max_tokens",
|
|
200
|
+
temperature = "temperature",
|
|
201
|
+
top_p = "top_p",
|
|
202
|
+
top_k = "top_k",
|
|
203
|
+
presence_penalty = "presence_penalty",
|
|
204
|
+
frequency_penalty = "frequency_penalty",
|
|
205
|
+
stop_sequence = "stop_sequence",
|
|
206
|
+
|
|
207
|
+
//Image
|
|
208
|
+
seed = "seed",
|
|
209
|
+
number_of_images = "number_of_images",
|
|
210
|
+
}
|
|
133
211
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
212
|
+
export enum OptionType {
|
|
213
|
+
numeric = "numeric",
|
|
214
|
+
enum = "enum",
|
|
215
|
+
boolean = "boolean",
|
|
216
|
+
string_list = "string_list"
|
|
217
|
+
}
|
|
139
218
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
219
|
+
// ============== Model Options ===============
|
|
220
|
+
|
|
221
|
+
export type ModelOptions = TextFallbackOptions | VertexAIOptions | BedrockOptions | OpenAiOptions;
|
|
222
|
+
|
|
223
|
+
// ============== Option Info ===============
|
|
224
|
+
|
|
225
|
+
export interface ModelOptionsInfo {
|
|
226
|
+
options: ModelOptionInfoItem[];
|
|
227
|
+
_option_id: string; //Should follow same ids as ModelOptions
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export type ModelOptionInfoItem = NumericOptionInfo | EnumOptionInfo | BooleanOptionInfo | StringListOptionInfo;
|
|
231
|
+
interface OptionInfoPrototype {
|
|
232
|
+
type: OptionType;
|
|
233
|
+
name: string;
|
|
234
|
+
description?: string;
|
|
235
|
+
|
|
236
|
+
//If this is true, whether other options apply is dependent on this option
|
|
237
|
+
//Therefore, if this option is changed, the set of available options should be refreshed.
|
|
238
|
+
refresh?: boolean;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface NumericOptionInfo extends OptionInfoPrototype {
|
|
242
|
+
type: OptionType.numeric;
|
|
243
|
+
value?: number;
|
|
244
|
+
min?: number;
|
|
245
|
+
max?: number;
|
|
246
|
+
step?: number;
|
|
247
|
+
integer?: boolean;
|
|
248
|
+
default?: number;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface EnumOptionInfo extends OptionInfoPrototype {
|
|
252
|
+
type: OptionType.enum;
|
|
253
|
+
value?: string;
|
|
254
|
+
enum: Record<string, string>;
|
|
255
|
+
default?: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface BooleanOptionInfo extends OptionInfoPrototype {
|
|
259
|
+
type: OptionType.boolean;
|
|
260
|
+
value?: boolean;
|
|
261
|
+
default?: boolean;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface StringListOptionInfo extends OptionInfoPrototype {
|
|
265
|
+
type: OptionType.string_list;
|
|
266
|
+
value?: string[];
|
|
267
|
+
default?: string[];
|
|
146
268
|
}
|
|
147
269
|
|
|
148
270
|
// ============== Prompts ===============
|
|
@@ -151,11 +273,21 @@ export enum PromptRole {
|
|
|
151
273
|
system = "system",
|
|
152
274
|
user = "user",
|
|
153
275
|
assistant = "assistant",
|
|
276
|
+
negative = "negative",
|
|
277
|
+
mask = "mask",
|
|
278
|
+
/**
|
|
279
|
+
* Used to send the response of a tool
|
|
280
|
+
*/
|
|
281
|
+
tool = "tool"
|
|
154
282
|
}
|
|
155
283
|
|
|
156
284
|
export interface PromptSegment {
|
|
157
285
|
role: PromptRole;
|
|
158
286
|
content: string;
|
|
287
|
+
/**
|
|
288
|
+
* The tool use id if the segment is a tool response
|
|
289
|
+
*/
|
|
290
|
+
tool_use_id?: string;
|
|
159
291
|
files?: DataSource[]
|
|
160
292
|
}
|
|
161
293
|
|
|
@@ -165,6 +297,11 @@ export interface ExecutionTokenUsage {
|
|
|
165
297
|
total?: number;
|
|
166
298
|
}
|
|
167
299
|
|
|
300
|
+
export enum Modalities {
|
|
301
|
+
text = "text",
|
|
302
|
+
image = "image",
|
|
303
|
+
}
|
|
304
|
+
|
|
168
305
|
|
|
169
306
|
// ============== AI MODEL ==============
|
|
170
307
|
|
|
@@ -181,6 +318,8 @@ export interface AIModel<ProviderKeys = string> {
|
|
|
181
318
|
can_stream?: boolean; //if the model's reponse can be streamed
|
|
182
319
|
is_custom?: boolean; //if the model is a custom model (a trained model)
|
|
183
320
|
is_multimodal?: boolean //if the model support files and images
|
|
321
|
+
input_modalities?: string[]; //if the model support files and images
|
|
322
|
+
environment?: string; //the environment name
|
|
184
323
|
}
|
|
185
324
|
|
|
186
325
|
export enum AIModelStatus {
|
|
@@ -248,7 +387,7 @@ export interface TrainingPromptOptions {
|
|
|
248
387
|
segments: PromptSegment[];
|
|
249
388
|
completion: string | JSONObject;
|
|
250
389
|
model: string; // the model to train
|
|
251
|
-
schema?:
|
|
390
|
+
schema?: JSONSchema; // the resuilt schema f any
|
|
252
391
|
}
|
|
253
392
|
|
|
254
393
|
export enum TrainingJobStatus {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../../src/formatters/claude.ts"],"names":[],"mappings":";;AA6BA,gDA2FC;AAvHD,0CAAwD;AACxD,4CAAkD;AAClD,6CAAmD;AAsBnD;;GAEG;AAEI,KAAK,UAAU,kBAAkB,CAAC,QAAyB,EAAE,MAAoB;IACpF,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAoB,EAAE,CAAC;IAErC,+CAA+C;IAC/C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAE7B,MAAM,KAAK,GAAwB,EAAE,CAAC;QACtC,IAAI,OAAO,CAAC,KAAK;YAAE,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;gBACnC,MAAM,IAAI,GAAG,MAAM,IAAA,8BAAkB,EAAC,MAAM,CAAC,CAAC;gBAC9C,KAAK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GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAChE,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAClF,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,aAAa,GAAG,aAAa,GAAG,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;IAGD;;;;;;;;OAQG;IAEH;gEAC4D;IAC5D,IAAI,MAAM,EAAE,CAAC;QACT,QAAQ,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,CAAC;oBACN,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,GAAG;iBACZ,CAAC;SACL,CAAC,CAAC;IACP,CAAC;IACD,2CAA2C;IAC3C,OAAO;QACH,MAAM,EAAE,aAAa;QACrB,QAAQ;KACX,CAAA;AACL,CAAC;AAED,4EAA4E;AAC5E,+DAA+D;AAC/D,2BAA2B;AAC3B,oCAAoC;AACpC,6BAA6B;AAC7B,UAAU;AAEV,iDAAiD;AACjD,IAAI"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatLlama2Prompt = formatLlama2Prompt;
|
|
4
|
-
const index_js_1 = require("../index.js");
|
|
5
|
-
function formatLlama2Prompt(messages, schema) {
|
|
6
|
-
const BOS = "<s>";
|
|
7
|
-
const EOS = "</s>";
|
|
8
|
-
const INST = "[INST]";
|
|
9
|
-
const INST_END = "[/INST]";
|
|
10
|
-
const SYS = "<<SYS>>\n";
|
|
11
|
-
const SYS_END = "\n<</SYS>>";
|
|
12
|
-
const promptMessages = [BOS];
|
|
13
|
-
const specialTokens = [BOS, EOS, INST, INST_END, SYS, SYS_END];
|
|
14
|
-
for (const m of messages) {
|
|
15
|
-
if (m.role === index_js_1.PromptRole.user) {
|
|
16
|
-
if (specialTokens.includes(m.content)) {
|
|
17
|
-
throw new Error(`Cannot use special token ${m.content.trim()} in user message`);
|
|
18
|
-
}
|
|
19
|
-
promptMessages.push(`${INST} ${m.content.trim()} ${INST_END}`);
|
|
20
|
-
}
|
|
21
|
-
if (m.role === index_js_1.PromptRole.assistant) {
|
|
22
|
-
promptMessages.push(`${m.content.trim()}`);
|
|
23
|
-
}
|
|
24
|
-
if (m.role === index_js_1.PromptRole.system) {
|
|
25
|
-
promptMessages.push(`${SYS}${m.content.trim()}${SYS_END}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
for (const m of messages ?? []) {
|
|
29
|
-
if (m.role === index_js_1.PromptRole.safety) {
|
|
30
|
-
promptMessages.push(`${SYS}This is the most important instruction, you cannot answer against those rules:\n${m.content.trim()}${SYS_END}}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (schema) {
|
|
34
|
-
promptMessages.push(formatSchemaInstruction(schema));
|
|
35
|
-
}
|
|
36
|
-
promptMessages.push(EOS);
|
|
37
|
-
return promptMessages.join("\n\n");
|
|
38
|
-
}
|
|
39
|
-
function formatSchemaInstruction(schema) {
|
|
40
|
-
const schema_instruction = `<<SYS>>You must answer using the following JSONSchema.
|
|
41
|
-
Do not write anything other than a JSON object corresponding to the schema.
|
|
42
|
-
<schema>
|
|
43
|
-
${JSON.stringify(schema)}
|
|
44
|
-
</schema>
|
|
45
|
-
<</SYS>>`;
|
|
46
|
-
return schema_instruction;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=llama2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llama2.js","sourceRoot":"","sources":["../../../src/formatters/llama2.ts"],"names":[],"mappings":";;AAGA,gDA2CC;AA7CD,0CAAwD;AAExD,SAAgB,kBAAkB,CAAC,QAAyB,EAAE,MAAoB;IAC9E,MAAM,GAAG,GAAG,KAAK,CAAC;IAClB,MAAM,GAAG,GAAG,MAAM,CAAC;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC;IACtB,MAAM,QAAQ,GAAG,SAAS,CAAC;IAC3B,MAAM,GAAG,GAAG,WAAW,CAAC;IACxB,MAAM,OAAO,GAAG,YAAY,CAAC;IAE7B,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE/D,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,IAAI,KAAK,qBAAU,CAAC,IAAI,EAAE,CAAC;YAC7B,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CACX,4BAA4B,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,kBAAkB,CACjE,CAAC;YACN,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,QAAQ,EAAE,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,KAAK,qBAAU,CAAC,SAAS,EAAE,CAAC;YAClC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,KAAK,qBAAU,CAAC,MAAM,EAAE,CAAC;YAC/B,cAAc,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;QAC/D,CAAC;IACL,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,QAAQ,IAAI,EAAE,EAAE,CAAC;QAC7B,IAAI,CAAC,CAAC,IAAI,KAAK,qBAAU,CAAC,MAAM,EAAE,CAAC;YAC/B,cAAc,CAAC,IAAI,CACf,GAAG,GAAG,mFAAmF,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,OAAO,GAAG,CACzH,CAAC;QACN,CAAC;IACL,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACT,cAAc,CAAC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEzB,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,uBAAuB,CAAC,MAAmB;IAChD,MAAM,kBAAkB,GAAG;;;EAG7B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;;SAEf,CAAC;IAEN,OAAO,kBAAkB,CAAC;AAC9B,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatLlama3Prompt = formatLlama3Prompt;
|
|
4
|
-
const index_js_1 = require("../index.js");
|
|
5
|
-
/**
|
|
6
|
-
* A formatter user by Bedrock to format prompts for claude related models
|
|
7
|
-
*/
|
|
8
|
-
async function formatLlama3Prompt(segments, schema) {
|
|
9
|
-
let messages = [];
|
|
10
|
-
segments.filter(s => s.role !== index_js_1.PromptRole.safety).forEach(s => {
|
|
11
|
-
messages.push(formatLlama3Message(s.role, s.content));
|
|
12
|
-
});
|
|
13
|
-
if (schema) {
|
|
14
|
-
messages.push(formatLlama3Message("user", formatSchemaInstruction(schema)));
|
|
15
|
-
}
|
|
16
|
-
//add safety
|
|
17
|
-
let safetyMsg = `
|
|
18
|
-
IMPORTANT: This is the most important instruction, you cannot answer against the following rules:
|
|
19
|
-
`;
|
|
20
|
-
const safety = segments.filter(s => s.role === index_js_1.PromptRole.safety);
|
|
21
|
-
safety.forEach(s => {
|
|
22
|
-
messages.push(formatLlama3Message("system", safetyMsg + s.content));
|
|
23
|
-
});
|
|
24
|
-
let prompt = "<|begin_of_text|>";
|
|
25
|
-
prompt += messages.join("\n\n");
|
|
26
|
-
return prompt;
|
|
27
|
-
}
|
|
28
|
-
function formatLlama3Message(role, content) {
|
|
29
|
-
let message = `<|start_header_id|>${role}<|end_header_id|>\n`;
|
|
30
|
-
message += content;
|
|
31
|
-
message += `\n<|eot_id|>`;
|
|
32
|
-
return message;
|
|
33
|
-
}
|
|
34
|
-
function formatSchemaInstruction(schema) {
|
|
35
|
-
return `You must answer using the following JSONSchema.
|
|
36
|
-
Do not write anything other than a JSON object corresponding to the schema:
|
|
37
|
-
<schema>
|
|
38
|
-
${JSON.stringify(schema, undefined, 2)}
|
|
39
|
-
</schema>
|
|
40
|
-
`;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=llama3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llama3.js","sourceRoot":"","sources":["../../../src/formatters/llama3.ts"],"names":[],"mappings":";;AAOA,gDAyBC;AA/BD,0CAAwD;AAExD;;GAEG;AAEI,KAAK,UAAU,kBAAkB,CAAC,QAAyB,EAAE,MAAoB;IAEpF,IAAI,QAAQ,GAAa,EAAE,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,qBAAU,CAAC,MAAM,CAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;Q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;IAC1E,CAAC;IAGD;;;;;;;;OAQG;IAEH;gEAC4D;IAC5D,IAAI,MAAM,EAAE,CAAC;QACT,QAAQ,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,CAAC;oBACN,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,GAAG;iBACZ,CAAC;SACL,CAAC,CAAC;IACP,CAAC;IACD,2CAA2C;IAC3C,OAAO;QACH,MAAM,EAAE,aAAa;QACrB,QAAQ;KACX,CAAA;AACL,CAAC;AAED,4EAA4E;AAC5E,+DAA+D;AAC/D,2BAA2B;AAC3B,oCAAoC;AACpC,6BAA6B;AAC7B,UAAU;AAEV,iDAAiD;AACjD,IAAI"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { PromptRole } from "../index.js";
|
|
2
|
-
export function formatLlama2Prompt(messages, schema) {
|
|
3
|
-
const BOS = "<s>";
|
|
4
|
-
const EOS = "</s>";
|
|
5
|
-
const INST = "[INST]";
|
|
6
|
-
const INST_END = "[/INST]";
|
|
7
|
-
const SYS = "<<SYS>>\n";
|
|
8
|
-
const SYS_END = "\n<</SYS>>";
|
|
9
|
-
const promptMessages = [BOS];
|
|
10
|
-
const specialTokens = [BOS, EOS, INST, INST_END, SYS, SYS_END];
|
|
11
|
-
for (const m of messages) {
|
|
12
|
-
if (m.role === PromptRole.user) {
|
|
13
|
-
if (specialTokens.includes(m.content)) {
|
|
14
|
-
throw new Error(`Cannot use special token ${m.content.trim()} in user message`);
|
|
15
|
-
}
|
|
16
|
-
promptMessages.push(`${INST} ${m.content.trim()} ${INST_END}`);
|
|
17
|
-
}
|
|
18
|
-
if (m.role === PromptRole.assistant) {
|
|
19
|
-
promptMessages.push(`${m.content.trim()}`);
|
|
20
|
-
}
|
|
21
|
-
if (m.role === PromptRole.system) {
|
|
22
|
-
promptMessages.push(`${SYS}${m.content.trim()}${SYS_END}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
for (const m of messages ?? []) {
|
|
26
|
-
if (m.role === PromptRole.safety) {
|
|
27
|
-
promptMessages.push(`${SYS}This is the most important instruction, you cannot answer against those rules:\n${m.content.trim()}${SYS_END}}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (schema) {
|
|
31
|
-
promptMessages.push(formatSchemaInstruction(schema));
|
|
32
|
-
}
|
|
33
|
-
promptMessages.push(EOS);
|
|
34
|
-
return promptMessages.join("\n\n");
|
|
35
|
-
}
|
|
36
|
-
function formatSchemaInstruction(schema) {
|
|
37
|
-
const schema_instruction = `<<SYS>>You must answer using the following JSONSchema.
|
|
38
|
-
Do not write anything other than a JSON object corresponding to the schema.
|
|
39
|
-
<schema>
|
|
40
|
-
${JSON.stringify(schema)}
|
|
41
|
-
</schema>
|
|
42
|
-
<</SYS>>`;
|
|
43
|
-
return schema_instruction;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=llama2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llama2.js","sourceRoot":"","sources":["../../../src/formatters/llama2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAiB,MAAM,aAAa,CAAC;AAExD,MAAM,UAAU,kBAAkB,CAAC,QAAyB,EAAE,MAAoB;IAC9E,MAAM,GAAG,GAAG,KAAK,CAAC;IAClB,MAAM,GAAG,GAAG,MAAM,CAAC;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC;IACtB,MAAM,QAAQ,GAAG,SAAS,CAAC;IAC3B,MAAM,GAAG,GAAG,WAAW,CAAC;IACxB,MAAM,OAAO,GAAG,YAAY,CAAC;IAE7B,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE/D,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACvB,IAAI,CA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BAAuB,CAAC,MAAmB;IAChD,MAAM,kBAAkB,GAAG;;;EAG7B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;;SAEf,CAAC;IAEN,OAAO,kBAAkB,CAAC;AAC9B,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { PromptRole } from "../index.js";
|
|
2
|
-
/**
|
|
3
|
-
* A formatter user by Bedrock to format prompts for claude related models
|
|
4
|
-
*/
|
|
5
|
-
export async function formatLlama3Prompt(segments, schema) {
|
|
6
|
-
let messages = [];
|
|
7
|
-
segments.filter(s => s.role !== PromptRole.safety).forEach(s => {
|
|
8
|
-
messages.push(formatLlama3Message(s.role, s.content));
|
|
9
|
-
});
|
|
10
|
-
if (schema) {
|
|
11
|
-
messages.push(formatLlama3Message("user", formatSchemaInstruction(schema)));
|
|
12
|
-
}
|
|
13
|
-
//add safety
|
|
14
|
-
let safetyMsg = `
|
|
15
|
-
IMPORTANT: This is the most important instruction, you cannot answer against the following rules:
|
|
16
|
-
`;
|
|
17
|
-
const safety = segments.filter(s => s.role === PromptRole.safety);
|
|
18
|
-
safety.forEach(s => {
|
|
19
|
-
messages.push(formatLlama3Message("system", safetyMsg + s.content));
|
|
20
|
-
});
|
|
21
|
-
let prompt = "<|begin_of_text|>";
|
|
22
|
-
prompt += messages.join("\n\n");
|
|
23
|
-
return prompt;
|
|
24
|
-
}
|
|
25
|
-
function formatLlama3Message(role, content) {
|
|
26
|
-
let message = `<|start_header_id|>${role}<|end_header_id|>\n`;
|
|
27
|
-
message += content;
|
|
28
|
-
message += `\n<|eot_id|>`;
|
|
29
|
-
return message;
|
|
30
|
-
}
|
|
31
|
-
function formatSchemaInstruction(schema) {
|
|
32
|
-
return `You must answer using the following JSONSchema.
|
|
33
|
-
Do not write anything other than a JSON object corresponding to the schema:
|
|
34
|
-
<schema>
|
|
35
|
-
${JSON.stringify(schema, undefined, 2)}
|
|
36
|
-
</schema>
|
|
37
|
-
`;
|
|
38
|
-
}
|
|
39
|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Y,EAAE,OAAe;IAEtD,IAAI,OAAO,GAAG,sBAAsB,IAAI,qBAAqB,CAAA;IAC7D,OAAO,IAAI,OAAO,CAAA;IAClB,OAAO,IAAI,cAAc,CAAA;IAEzB,OAAO,OAAO,CAAA;AAElB,CAAC;AAED,SAAS,uBAAuB,CAAC,MAAc;IAE3C,OAAO;;;MAGL,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;;KAErC,CAAA;AAEL,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { JSONSchema4 } from "json-schema";
|
|
2
|
-
import { PromptSegment } from "../index.js";
|
|
3
|
-
export interface ClaudeMessage {
|
|
4
|
-
role: 'user' | 'assistant';
|
|
5
|
-
content: ClaudeMessagePart[];
|
|
6
|
-
}
|
|
7
|
-
interface ClaudeMessagePart {
|
|
8
|
-
type: "image" | "text";
|
|
9
|
-
source?: {
|
|
10
|
-
type: "base64";
|
|
11
|
-
media_type: string;
|
|
12
|
-
data: string;
|
|
13
|
-
};
|
|
14
|
-
text?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface ClaudeMessagesPrompt {
|
|
17
|
-
system?: string;
|
|
18
|
-
messages: ClaudeMessage[];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* A formatter user by Bedrock to format prompts for claude related models
|
|
22
|
-
*/
|
|
23
|
-
export declare function formatClaudePrompt(segments: PromptSegment[], schema?: JSONSchema4): Promise<ClaudeMessagesPrompt>;
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../../src/formatters/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAc,aAAa,EAAE,MAAM,aAAa,CAAC;AAIxD,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,iBAAiB,EAAE,CAAA;CAC/B;AAED,UAAU,iBAAiB;IACvB,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE;QACL,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,oBAAoB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,aAAa,EAAE,CAAA;CAC5B;AAED;;GAEG;AAEH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA2FvH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llama2.d.ts","sourceRoot":"","sources":["../../../src/formatters/llama2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAc,aAAa,EAAE,MAAM,aAAa,CAAC;AAExD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,UA2CjF"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { JSONSchema4 } from "json-schema";
|
|
2
|
-
import { PromptSegment } from "../index.js";
|
|
3
|
-
/**
|
|
4
|
-
* A formatter user by Bedrock to format prompts for claude related models
|
|
5
|
-
*/
|
|
6
|
-
export declare function formatLlama3Prompt(segments: PromptSegment[], schema?: JSONSchema4): Promise<string>;
|
|
7
|
-
//# sourceMappingURL=llama3.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llama3.d.ts","sourceRoot":"","sources":["../../../src/formatters/llama3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAc,aAAa,EAAE,MAAM,aAAa,CAAC;AAExD;;GAEG;AAEH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBzG"}
|