@llumiverse/core 0.16.0 → 0.18.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.
Files changed (142) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/CompletionStream.js.map +1 -1
  3. package/lib/cjs/Driver.js +7 -7
  4. package/lib/cjs/Driver.js.map +1 -1
  5. package/lib/cjs/async.js +3 -3
  6. package/lib/cjs/async.js.map +1 -1
  7. package/lib/cjs/capability/bedrock.js +183 -0
  8. package/lib/cjs/capability/bedrock.js.map +1 -0
  9. package/lib/cjs/capability/openai.js +122 -0
  10. package/lib/cjs/capability/openai.js.map +1 -0
  11. package/lib/cjs/capability/vertexai.js +86 -0
  12. package/lib/cjs/capability/vertexai.js.map +1 -0
  13. package/lib/cjs/capability.js +52 -0
  14. package/lib/cjs/capability.js.map +1 -0
  15. package/lib/cjs/formatters/commons.js.map +1 -1
  16. package/lib/cjs/formatters/generic.js +6 -6
  17. package/lib/cjs/formatters/generic.js.map +1 -1
  18. package/lib/cjs/formatters/index.js.map +1 -1
  19. package/lib/cjs/formatters/nova.js +11 -11
  20. package/lib/cjs/formatters/nova.js.map +1 -1
  21. package/lib/cjs/formatters/openai.js +25 -11
  22. package/lib/cjs/formatters/openai.js.map +1 -1
  23. package/lib/cjs/index.js +2 -1
  24. package/lib/cjs/index.js.map +1 -1
  25. package/lib/cjs/json.js +1 -1
  26. package/lib/cjs/json.js.map +1 -1
  27. package/lib/cjs/options.js +8 -43
  28. package/lib/cjs/options.js.map +1 -1
  29. package/lib/cjs/resolver.js +2 -2
  30. package/lib/esm/CompletionStream.js.map +1 -1
  31. package/lib/esm/Driver.js +4 -4
  32. package/lib/esm/Driver.js.map +1 -1
  33. package/lib/esm/async.js +3 -3
  34. package/lib/esm/async.js.map +1 -1
  35. package/lib/esm/capability/bedrock.js +180 -0
  36. package/lib/esm/capability/bedrock.js.map +1 -0
  37. package/lib/esm/capability/openai.js +119 -0
  38. package/lib/esm/capability/openai.js.map +1 -0
  39. package/lib/esm/capability/vertexai.js +83 -0
  40. package/lib/esm/capability/vertexai.js.map +1 -0
  41. package/lib/esm/capability.js +47 -0
  42. package/lib/esm/capability.js.map +1 -0
  43. package/lib/esm/formatters/commons.js.map +1 -1
  44. package/lib/esm/formatters/generic.js +1 -1
  45. package/lib/esm/formatters/generic.js.map +1 -1
  46. package/lib/esm/formatters/index.js.map +1 -1
  47. package/lib/esm/formatters/nova.js +5 -5
  48. package/lib/esm/formatters/nova.js.map +1 -1
  49. package/lib/esm/formatters/openai.js +17 -4
  50. package/lib/esm/formatters/openai.js.map +1 -1
  51. package/lib/esm/index.js +2 -1
  52. package/lib/esm/index.js.map +1 -1
  53. package/lib/esm/json.js +1 -1
  54. package/lib/esm/json.js.map +1 -1
  55. package/lib/esm/options.js +3 -37
  56. package/lib/esm/options.js.map +1 -1
  57. package/lib/esm/resolver.js +2 -2
  58. package/lib/types/CompletionStream.d.ts +1 -1
  59. package/lib/types/CompletionStream.d.ts.map +1 -1
  60. package/lib/types/Driver.d.ts +3 -3
  61. package/lib/types/Driver.d.ts.map +1 -1
  62. package/lib/types/async.d.ts +2 -2
  63. package/lib/types/async.d.ts.map +1 -1
  64. package/lib/types/capability/bedrock.d.ts +7 -0
  65. package/lib/types/capability/bedrock.d.ts.map +1 -0
  66. package/lib/types/capability/openai.d.ts +11 -0
  67. package/lib/types/capability/openai.d.ts.map +1 -0
  68. package/lib/types/capability/vertexai.d.ts +11 -0
  69. package/lib/types/capability/vertexai.d.ts.map +1 -0
  70. package/lib/types/capability.d.ts +5 -0
  71. package/lib/types/capability.d.ts.map +1 -0
  72. package/lib/types/formatters/commons.d.ts +2 -2
  73. package/lib/types/formatters/commons.d.ts.map +1 -1
  74. package/lib/types/formatters/generic.d.ts +4 -4
  75. package/lib/types/formatters/generic.d.ts.map +1 -1
  76. package/lib/types/formatters/index.d.ts +0 -3
  77. package/lib/types/formatters/index.d.ts.map +1 -1
  78. package/lib/types/formatters/nova.d.ts +3 -3
  79. package/lib/types/formatters/nova.d.ts.map +1 -1
  80. package/lib/types/formatters/openai.d.ts +3 -2
  81. package/lib/types/formatters/openai.d.ts.map +1 -1
  82. package/lib/types/index.d.ts +2 -1
  83. package/lib/types/index.d.ts.map +1 -1
  84. package/lib/types/json.d.ts +1 -7
  85. package/lib/types/json.d.ts.map +1 -1
  86. package/lib/types/options.d.ts +2 -13
  87. package/lib/types/options.d.ts.map +1 -1
  88. package/lib/types/validation.d.ts +1 -1
  89. package/lib/types/validation.d.ts.map +1 -1
  90. package/package.json +4 -5
  91. package/src/CompletionStream.ts +5 -5
  92. package/src/Driver.ts +6 -6
  93. package/src/async.ts +5 -8
  94. package/src/capability/bedrock.ts +187 -0
  95. package/src/capability/openai.ts +124 -0
  96. package/src/capability/vertexai.ts +88 -0
  97. package/src/capability.ts +49 -0
  98. package/src/formatters/commons.ts +2 -2
  99. package/src/formatters/generic.ts +3 -3
  100. package/src/formatters/index.ts +0 -6
  101. package/src/formatters/nova.ts +7 -7
  102. package/src/formatters/openai.ts +19 -5
  103. package/src/index.ts +3 -2
  104. package/src/json.ts +2 -10
  105. package/src/options.ts +12 -50
  106. package/src/resolver.ts +2 -2
  107. package/src/validation.ts +3 -3
  108. package/lib/cjs/options/bedrock.js +0 -343
  109. package/lib/cjs/options/bedrock.js.map +0 -1
  110. package/lib/cjs/options/groq.js +0 -37
  111. package/lib/cjs/options/groq.js.map +0 -1
  112. package/lib/cjs/options/openai.js +0 -123
  113. package/lib/cjs/options/openai.js.map +0 -1
  114. package/lib/cjs/options/vertexai.js +0 -257
  115. package/lib/cjs/options/vertexai.js.map +0 -1
  116. package/lib/cjs/types.js +0 -80
  117. package/lib/cjs/types.js.map +0 -1
  118. package/lib/esm/options/bedrock.js +0 -340
  119. package/lib/esm/options/bedrock.js.map +0 -1
  120. package/lib/esm/options/groq.js +0 -34
  121. package/lib/esm/options/groq.js.map +0 -1
  122. package/lib/esm/options/openai.js +0 -120
  123. package/lib/esm/options/openai.js.map +0 -1
  124. package/lib/esm/options/vertexai.js +0 -253
  125. package/lib/esm/options/vertexai.js.map +0 -1
  126. package/lib/esm/types.js +0 -77
  127. package/lib/esm/types.js.map +0 -1
  128. package/lib/types/options/bedrock.d.ts +0 -32
  129. package/lib/types/options/bedrock.d.ts.map +0 -1
  130. package/lib/types/options/groq.d.ts +0 -12
  131. package/lib/types/options/groq.d.ts.map +0 -1
  132. package/lib/types/options/openai.d.ts +0 -21
  133. package/lib/types/options/openai.d.ts.map +0 -1
  134. package/lib/types/options/vertexai.d.ts +0 -52
  135. package/lib/types/options/vertexai.d.ts.map +0 -1
  136. package/lib/types/types.d.ts +0 -308
  137. package/lib/types/types.d.ts.map +0 -1
  138. package/src/options/bedrock.ts +0 -388
  139. package/src/options/groq.ts +0 -47
  140. package/src/options/openai.ts +0 -148
  141. package/src/options/vertexai.ts +0 -312
  142. package/src/types.ts +0 -381
@@ -1,312 +0,0 @@
1
- import { ModelOptionsInfo, ModelOptionInfoItem, OptionType, SharedOptions, ModelOptions } from "../types.js";
2
- import { textOptionsFallback } from "../options.js";
3
-
4
- // Union type of all Bedrock options
5
- export type VertexAIOptions = ImagenOptions | VertexAIClaudeOptions;
6
-
7
- export enum ImagenTaskType {
8
- TEXT_IMAGE = "TEXT_IMAGE",
9
- EDIT_MODE_INPAINT_REMOVAL = "EDIT_MODE_INPAINT_REMOVAL",
10
- EDIT_MODE_INPAINT_INSERTION = "EDIT_MODE_INPAINT_INSERTION",
11
- EDIT_MODE_BGSWAP = "EDIT_MODE_BGSWAP",
12
- EDIT_MODE_OUTPAINT = "EDIT_MODE_OUTPAINT",
13
- CUSTOMIZATION_SUBJECT = "CUSTOMIZATION_SUBJECT",
14
- CUSTOMIZATION_STYLE = "CUSTOMIZATION_STYLE",
15
- CUSTOMIZATION_CONTROLLED = "CUSTOMIZATION_CONTROLLED",
16
- CUSTOMIZATION_INSTRUCT = "CUSTOMIZATION_INSTRUCT",
17
- }
18
-
19
- export enum ImagenMaskMode {
20
- MASK_MODE_USER_PROVIDED = "MASK_MODE_USER_PROVIDED",
21
- MASK_MODE_BACKGROUND = "MASK_MODE_BACKGROUND",
22
- MASK_MODE_FOREGROUND = "MASK_MODE_FOREGROUND",
23
- MASK_MODE_SEMANTIC = "MASK_MODE_SEMANTIC",
24
- }
25
-
26
- export interface ImagenOptions {
27
- _option_id: "vertexai-imagen"
28
-
29
- //General and generate options
30
- number_of_images?: number;
31
- seed?: number;
32
- person_generation?: "dont_allow" | "allow_adults" | "allow_all";
33
- safety_setting?: "block_none" | "block_only_high" | "block_medium_and_above" | "block_low_and_above"; //The "off" option does not seem to work for Imagen 3, might be only for text models
34
- image_file_type?: "image/jpeg" | "image/png";
35
- jpeg_compression_quality?: number;
36
- aspect_ratio?: "1:1" | "4:3" | "3:4" | "16:9" | "9:16";
37
- add_watermark?: boolean;
38
- enhance_prompt?: boolean;
39
-
40
- //Capability options
41
- edit_mode?: ImagenTaskType
42
- guidance_scale?: number;
43
- edit_steps?: number;
44
- mask_mode?: ImagenMaskMode;
45
- mask_dilation?: number;
46
- mask_class?: number[];
47
-
48
- //Customization options
49
- controlType: "CONTROL_TYPE_FACE_MESH" | "CONTROL_TYPE_CANNY" | "CONTROL_TYPE_SCRIBBLE";
50
- controlImageComputation?: boolean;
51
- subjectType: "SUBJECT_TYPE_PERSON" | "SUBJECT_TYPE_ANIMAL" | "SUBJECT_TYPE_PRODUCT" | "SUBJECT_TYPE_DEFAULT";
52
- }
53
-
54
- export interface VertexAIClaudeOptions {
55
- _option_id: "vertexai-claude"
56
- max_tokens?: number;
57
- temperature?: number;
58
- top_p?: number;
59
- top_k?: number;
60
- stop_sequence?: string[];
61
- thinking_mode?: boolean;
62
- thinking_budget_tokens?: number;
63
- }
64
-
65
- export function getVertexAiOptions(model: string, option?: ModelOptions): ModelOptionsInfo {
66
- if (model.includes("imagen-3.0")) {
67
- const commonOptions: ModelOptionInfoItem[] = [
68
- {
69
- name: SharedOptions.number_of_images, type: OptionType.numeric, min: 1, max: 4, default: 1,
70
- integer: true, description: "Number of Images to generate",
71
- },
72
- {
73
- name: SharedOptions.seed, type: OptionType.numeric, min: 0, max: 4294967295, default: 12,
74
- integer: true, description: "The seed of the generated image"
75
- },
76
- {
77
- name: "person_generation", type: OptionType.enum, enum: { "Disallow the inclusion of people or faces in images": "dont_allow", "Allow generation of adults only": "allow_adult", "Allow generation of people of all ages": "allow_all" },
78
- default: "allow_adult", description: "The safety setting for allowing the generation of people in the image"
79
- },
80
- {
81
- name: "safety_setting", type: OptionType.enum, enum: { "Block very few problematic prompts and responses": "block_none", "Block only few problematic prompts and responses": "block_only_high", "Block some problematic prompts and responses": "block_medium_and_above", "Strictest filtering": "block_low_and_above" },
82
- default: "block_medium_and_above", description: "The overall safety setting"
83
- },
84
- ];
85
-
86
-
87
- const outputOptions: ModelOptionInfoItem[] = [
88
- {
89
- name: "image_file_type", type: OptionType.enum, enum: { "JPEG": "image/jpeg", "PNG": "image/png" },
90
- default: "image/png", description: "The file type of the generated image",
91
- refresh: true,
92
- },
93
- ]
94
-
95
- const jpegQuality: ModelOptionInfoItem = {
96
- name: "jpeg_compression_quality", type: OptionType.numeric, min: 0, max: 100, default: 75,
97
- integer: true, description: "The compression quality of the JPEG image",
98
- }
99
-
100
- if ((option as ImagenOptions)?.image_file_type === "image/jpeg") {
101
- outputOptions.push(jpegQuality);
102
- }
103
- if (model.includes("generate")) {
104
- //Generate models
105
- const modeOptions: ModelOptionInfoItem[]
106
- = [
107
- {
108
- name: "aspect_ratio", type: OptionType.enum, enum: { "1:1": "1:1", "4:3": "4:3", "3:4": "3:4", "16:9": "16:9", "9:16": "9:16" },
109
- default: "1:1", description: "The aspect ratio of the generated image"
110
- },
111
- {
112
- name: "add_watermark", type: OptionType.boolean, default: false, description: "Add an invisible watermark to the generated image, useful for detection of AI images"
113
- },
114
-
115
- ];
116
-
117
- const enhanceOptions: ModelOptionInfoItem[] = !model.includes("generate-001") ? [
118
- {
119
- name: "enhance_prompt", type: OptionType.boolean, default: true, description: "VertexAI automatically rewrites the prompt to better reflect the prompt's intent."
120
- },
121
- ] : [];
122
-
123
- return {
124
- _option_id: "vertexai-imagen",
125
- options: [
126
- ...commonOptions,
127
- ...modeOptions,
128
- ...outputOptions,
129
- ...enhanceOptions,
130
- ]
131
- };
132
- }
133
- if (model.includes("capability")) {
134
- //Edit models
135
- let guidanceScaleDefault = 75;
136
- if ((option as ImagenOptions)?.edit_mode === ImagenTaskType.EDIT_MODE_INPAINT_INSERTION) {
137
- guidanceScaleDefault = 60;
138
- }
139
-
140
- const modeOptions: ModelOptionInfoItem[] = [
141
- {
142
- name: "edit_mode", type: OptionType.enum,
143
- enum: {
144
- "EDIT_MODE_INPAINT_REMOVAL": "EDIT_MODE_INPAINT_REMOVAL",
145
- "EDIT_MODE_INPAINT_INSERTION": "EDIT_MODE_INPAINT_INSERTION",
146
- "EDIT_MODE_BGSWAP": "EDIT_MODE_BGSWAP",
147
- "EDIT_MODE_OUTPAINT": "EDIT_MODE_OUTPAINT",
148
- "CUSTOMIZATION_SUBJECT": "CUSTOMIZATION_SUBJECT",
149
- "CUSTOMIZATION_STYLE": "CUSTOMIZATION_STYLE",
150
- "CUSTOMIZATION_CONTROLLED": "CUSTOMIZATION_CONTROLLED",
151
- "CUSTOMIZATION_INSTRUCT": "CUSTOMIZATION_INSTRUCT",
152
- },
153
- description: "The editing mode. CUSTOMIZATION options use few-shot learning to generate images based on a few examples."
154
- },
155
-
156
- {
157
- name: "guidance_scale", type: OptionType.numeric, min: 0, max: 500, default: guidanceScaleDefault,
158
- integer: true, description: "How closely the generation follows the prompt"
159
- }
160
- ];
161
-
162
- const maskOptions: ModelOptionInfoItem[] = ((option as ImagenOptions)?.edit_mode?.includes("EDIT")) ? [
163
- {
164
- name: "mask_mode", type: OptionType.enum,
165
- enum: {
166
- "MASK_MODE_USER_PROVIDED": "MASK_MODE_USER_PROVIDED",
167
- "MASK_MODE_BACKGROUND": "MASK_MODE_BACKGROUND",
168
- "MASK_MODE_FOREGROUND": "MASK_MODE_FOREGROUND",
169
- "MASK_MODE_SEMANTIC": "MASK_MODE_SEMANTIC",
170
- },
171
- default: "MASK_MODE_USER_PROVIDED",
172
- description: "How should the mask for the generation be provided"
173
- },
174
- {
175
- name: "mask_dilation", type: OptionType.numeric, min: 0, max: 1,
176
- integer: true, description: "The mask dilation, grows the mask by a percetage of image width to compensate for imprecise masks."
177
- },
178
- ] : [];
179
-
180
- const maskClassOptions: ModelOptionInfoItem[] = ((option as ImagenOptions)?.mask_mode === ImagenMaskMode.MASK_MODE_SEMANTIC) ? [
181
- {
182
- name: "mask_class", type: OptionType.string_list, default: [],
183
- description: "Input Class IDs. Create a mask based on image class, based on https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api-customization#segment-ids"
184
- }
185
- ] : [];
186
-
187
- const editOptions: ModelOptionInfoItem[] = (option as ImagenOptions)?.edit_mode?.includes("EDIT") ? [
188
- {
189
- name: "edit_steps", type: OptionType.numeric, default: 75,
190
- integer: true, description: "The number of steps for the base image generation, more steps means more time and better quality"
191
- },
192
- ] : [];
193
-
194
- const customizationOptions: ModelOptionInfoItem[] = (option as ImagenOptions)?.edit_mode === ImagenTaskType.CUSTOMIZATION_CONTROLLED
195
- || (option as ImagenOptions)?.edit_mode === ImagenTaskType.CUSTOMIZATION_SUBJECT ? [
196
- {
197
- name: "controlType", type: OptionType.enum, enum: { "Face Mesh": "CONTROL_TYPE_FACE_MESH", "Canny": "CONTROL_TYPE_CANNY", "Scribble": "CONTROL_TYPE_SCRIBBLE" },
198
- default: "CONTROL_TYPE_CANNY", description: "Method used to generate the control image"
199
- },
200
- {
201
- name: "controlImageComputation", type: OptionType.boolean, default: true, description: "Should the control image be computed from the input image, or is it provided"
202
- }
203
- ] : [];
204
-
205
- return {
206
- _option_id: "vertexai-imagen",
207
- options: [
208
- ...modeOptions,
209
- ...commonOptions,
210
- ...maskOptions,
211
- ...maskClassOptions,
212
- ...editOptions,
213
- ...customizationOptions,
214
- ...outputOptions,
215
- ]
216
- };
217
- }
218
- }
219
- else if (model.includes("gemini")) {
220
- const max_tokens_limit = getGeminiMaxTokensLimit(model);
221
- const excludeOptions = ["max_tokens", "presence_penalty"];
222
- let commonOptions = textOptionsFallback.options.filter((option) => !excludeOptions.includes(option.name));
223
- if (model.includes("1.5")) {
224
- commonOptions = commonOptions.filter((option) => option.name !== "frequency_penalty");
225
- }
226
- const max_tokens: ModelOptionInfoItem[] = [{
227
- name: SharedOptions.max_tokens, type: OptionType.numeric, min: 1, max: max_tokens_limit,
228
- integer: true, step: 200, description: "The maximum number of tokens to generate"
229
- }];
230
- return {
231
- _option_id: "vertexai-gemini",
232
- options: [
233
- ...max_tokens,
234
- ...commonOptions,
235
- ]
236
- };
237
- }
238
- else if (model.includes("claude")) {
239
- const max_tokens_limit = getClaudeMaxTokensLimit(model, option as VertexAIClaudeOptions);
240
- const excludeOptions = ["max_tokens", "presence_penalty", "frequency_penalty"];
241
- let commonOptions = textOptionsFallback.options.filter((option) => !excludeOptions.includes(option.name));
242
- const max_tokens: ModelOptionInfoItem[] = [{
243
- name: SharedOptions.max_tokens, type: OptionType.numeric, min: 1, max: max_tokens_limit,
244
- integer: true, step: 200, description: "The maximum number of tokens to generate"
245
- }];
246
-
247
- if (model.includes("3-7")) {
248
- const claudeModeOptions: ModelOptionInfoItem[] = [
249
- {
250
- name: "thinking_mode",
251
- type: OptionType.boolean,
252
- default: false,
253
- description: "If true, use the extended reasoning mode"
254
- },
255
- ];
256
- const claudeThinkingOptions: ModelOptionInfoItem[] = (option as VertexAIClaudeOptions)?.thinking_mode ? [
257
- {
258
- name: "thinking_budget_tokens",
259
- type: OptionType.numeric,
260
- min: 1024,
261
- default: 4000,
262
- integer: true,
263
- step: 100,
264
- description: "The target number of tokens to use for reasoning, not a hard limit."
265
- },
266
- ] : [];
267
-
268
- return {
269
- _option_id: "vertexai-claude",
270
- options: [
271
- ...max_tokens,
272
- ...commonOptions,
273
- ...claudeModeOptions,
274
- ...claudeThinkingOptions,
275
- ]
276
- };
277
- }
278
- return {
279
- _option_id: "vertexai-claude",
280
- options: [
281
- ...max_tokens,
282
- ...commonOptions,
283
- ]
284
- };
285
- }
286
- return textOptionsFallback;
287
- }
288
- function getGeminiMaxTokensLimit(model: string): number {
289
- if (model.includes("thinking")) {
290
- return 65536;
291
- }
292
- if (model.includes("ultra") || model.includes("vision")) {
293
- return 2048;
294
- }
295
- return 8192;
296
- }
297
- function getClaudeMaxTokensLimit(model: string, option?: VertexAIClaudeOptions): number {
298
- if (model.includes("3-7")) {
299
- if (option && option?.thinking_mode) {
300
- return 128000;
301
- } else {
302
- return 8192;
303
- }
304
- }
305
- else if (model.includes("3-5")) {
306
- return 8192;
307
- }
308
- else {
309
- return 4096;
310
- }
311
- }
312
-
package/src/types.ts DELETED
@@ -1,381 +0,0 @@
1
- import { JSONSchema4 } from 'json-schema';
2
-
3
- import { PromptFormatter } from './formatters/index.js';
4
- import { JSONObject } from './json.js';
5
- import { TextFallbackOptions } from './options.js';
6
- import { VertexAIOptions } from './options/vertexai.js';
7
- import { BedrockOptions } from './options/bedrock.js';
8
- import { OpenAiOptions } from './options/openai.js';
9
-
10
- export interface EmbeddingsOptions {
11
- /**
12
- * The text to generate the embeddings for. One of text or image is required.
13
- */
14
- text?: string;
15
- /**
16
- * The image to generate embeddings for
17
- */
18
- image?: string
19
- /**
20
- * The model to use to generate the embeddings. Optional.
21
- */
22
- model?: string;
23
-
24
- }
25
-
26
- export interface EmbeddingsResult {
27
- /**
28
- * The embedding vectors corresponding to the words in the input text.
29
- */
30
- values: number[];
31
- /**
32
- * The model used to hgenerate the embeddings.
33
- */
34
- model: string;
35
- /**
36
- * Number of tokens of the input text.
37
- */
38
- token_count?: number;
39
-
40
- }
41
-
42
- export interface ResultValidationError {
43
- code: 'validation_error' | 'json_error' | 'content_policy_violation';
44
- message: string;
45
- data?: string;
46
- }
47
-
48
- //ResultT should be either JSONObject or string
49
- //Internal structure used in driver implementation.
50
- export interface CompletionChunkObject<ResultT = any> {
51
- result: ResultT;
52
- token_usage?: ExecutionTokenUsage;
53
- finish_reason?: "stop" | "length" | string;
54
- }
55
-
56
- //Internal structure used in driver implementation.
57
- export type CompletionChunk = CompletionChunkObject | string;
58
-
59
- export interface ToolDefinition {
60
- name: string,
61
- description?: string,
62
- input_schema: {
63
- type: 'object';
64
- properties?: unknown | null | undefined;
65
- [k: string]: unknown;
66
- },
67
- }
68
-
69
- export interface ToolUse {
70
- id: string,
71
- name: string,
72
- input: JSONObject | null
73
- }
74
-
75
- //ResultT should be either JSONObject or string
76
- export interface Completion<ResultT = any> {
77
- // the driver impl must return the result and optionally the token_usage. the execution time is computed by the extended abstract driver
78
- result: ResultT;
79
- token_usage?: ExecutionTokenUsage;
80
- /**
81
- * Contains the tools from which the model awaits information.
82
- */
83
- tool_use?: ToolUse[];
84
- /**
85
- * The finish reason as reported by the model: stop | length or other model specific values
86
- */
87
- finish_reason?: "stop" | "length" | "tool_use" | string;
88
-
89
- /**
90
- * Set only if a result validation error occured, otherwise if the result is valid the error field is undefined
91
- * This can only be set if the result_schema is set and the reuslt could not be parsed as a json or if the result does not match the schema
92
- */
93
- error?: ResultValidationError;
94
-
95
- /**
96
- * The original response. Only included if the option include_original_response is set to true and the request is made using execute. Not supported when streaming.
97
- */
98
- original_response?: Record<string, any>;
99
-
100
- /**
101
- * The conversation context. This is an opaque structure that can be passed to the next request to restore the context.
102
- */
103
- conversation?: unknown;
104
- }
105
-
106
- export interface ImageGeneration {
107
-
108
- images?: string[];
109
-
110
- }
111
-
112
- export interface ExecutionResponse<PromptT = any> extends Completion {
113
- prompt: PromptT;
114
- /**
115
- * The time it took to execute the request in seconds
116
- */
117
- execution_time?: number;
118
- /**
119
- * The number of chunks for streamed executions
120
- */
121
- chunks?: number;
122
- }
123
-
124
-
125
- export interface CompletionStream<PromptT = any> extends AsyncIterable<string> {
126
- completion: ExecutionResponse<PromptT> | undefined;
127
- }
128
-
129
- export interface Logger {
130
- debug: (...obj: any[]) => void;
131
- info: (...obj: any[]) => void;
132
- warn: (...obj: any[]) => void;
133
- error: (...obj: any[]) => void;
134
- }
135
-
136
- export interface DriverOptions {
137
- logger?: Logger | "console";
138
- }
139
-
140
- //Options are split into PromptOptions, ModelOptions and ExecutionOptions.
141
- //ExecutionOptions are most often used within llumiverse as they are the most complete.
142
- //The base types are useful for external code that needs to interact with llumiverse.
143
- export interface PromptOptions {
144
- model: string;
145
- /**
146
- * A custom formatter to use for format the final model prompt from the input prompt segments.
147
- * If no one is specified the driver will choose a formatter compatible with the target model
148
- */
149
- format?: PromptFormatter;
150
- result_schema?: JSONSchema4;
151
- }
152
-
153
- export interface ExecutionOptions extends PromptOptions {
154
- /**
155
- * If set to true the original response from the target LLM will be included in the response under the original_response field.
156
- * This is useful for debugging and for some advanced use cases.
157
- * It is ignored on streaming requests
158
- */
159
- include_original_response?: boolean;
160
- model_options?: ModelOptions;
161
- output_modality: Modalities;
162
- /**
163
- * Available tools for the request
164
- */
165
- tools?: ToolDefinition[];
166
- /**
167
- * This is an opaque structure that provides a conversation context
168
- * Each driver implementation will return a conversation property in the execution response
169
- * that can be passed here to restore the context when a new prompt is sent to the model.
170
- */
171
- conversation?: unknown | null;
172
- }
173
-
174
- //Common names to share between different models
175
- export enum SharedOptions {
176
- //Text
177
- max_tokens = "max_tokens",
178
- temperature = "temperature",
179
- top_p = "top_p",
180
- top_k = "top_k",
181
- presence_penalty = "presence_penalty",
182
- frequency_penalty = "frequency_penalty",
183
- stop_sequence = "stop_sequence",
184
-
185
- //Image
186
- seed = "seed",
187
- number_of_images = "number_of_images",
188
- }
189
-
190
- export enum OptionType {
191
- numeric = "numeric",
192
- enum = "enum",
193
- boolean = "boolean",
194
- string_list = "string_list"
195
- }
196
-
197
- // ============== Model Options ===============
198
-
199
- export type ModelOptions = TextFallbackOptions | VertexAIOptions | BedrockOptions | OpenAiOptions;
200
-
201
- // ============== Option Info ===============
202
-
203
- export interface ModelOptionsInfo {
204
- options: ModelOptionInfoItem[];
205
- _option_id: string; //Should follow same ids as ModelOptions
206
- }
207
-
208
- export type ModelOptionInfoItem = NumericOptionInfo | EnumOptionInfo | BooleanOptionInfo | StringListOptionInfo;
209
- interface OptionInfoPrototype {
210
- type: OptionType;
211
- name: string;
212
- description?: string;
213
-
214
- //If this is true, whether other options apply is dependent on this option
215
- //Therefore, if this option is changed, the set of available options should be refreshed.
216
- refresh?: boolean;
217
- }
218
-
219
- export interface NumericOptionInfo extends OptionInfoPrototype {
220
- type: OptionType.numeric;
221
- value?: number;
222
- min?: number;
223
- max?: number;
224
- step?: number;
225
- integer?: boolean;
226
- default?: number;
227
- }
228
-
229
- export interface EnumOptionInfo extends OptionInfoPrototype {
230
- type: OptionType.enum;
231
- value?: string;
232
- enum: Record<string, string>;
233
- default?: string;
234
- }
235
-
236
- export interface BooleanOptionInfo extends OptionInfoPrototype {
237
- type: OptionType.boolean;
238
- value?: boolean;
239
- default?: boolean;
240
- }
241
-
242
- export interface StringListOptionInfo extends OptionInfoPrototype {
243
- type: OptionType.string_list;
244
- value?: string[];
245
- default?: string[];
246
- }
247
-
248
- // ============== Prompts ===============
249
- export enum PromptRole {
250
- safety = "safety",
251
- system = "system",
252
- user = "user",
253
- assistant = "assistant",
254
- negative = "negative",
255
- mask = "mask",
256
- /**
257
- * Used to send the response of a tool
258
- */
259
- tool = "tool"
260
- }
261
-
262
- export interface PromptSegment {
263
- role: PromptRole;
264
- content: string;
265
- /**
266
- * The tool use id if the segment is a tool response
267
- */
268
- tool_use_id?: string;
269
- files?: DataSource[]
270
- }
271
-
272
- export interface ExecutionTokenUsage {
273
- prompt?: number;
274
- result?: number;
275
- total?: number;
276
- }
277
-
278
- export enum Modalities {
279
- text = "text",
280
- image = "image"
281
- }
282
-
283
-
284
- // ============== AI MODEL ==============
285
-
286
- export interface AIModel<ProviderKeys = string> {
287
- id: string; //id of the model known by the provider
288
- name: string; //human readable name
289
- provider: ProviderKeys; //provider name
290
- description?: string;
291
- version?: string; //if any version is specified
292
- type?: ModelType; //type of the model
293
- tags?: string[]; //tags for searching
294
- owner?: string; //owner of the model
295
- status?: AIModelStatus; //status of the model
296
- can_stream?: boolean; //if the model's reponse can be streamed
297
- is_custom?: boolean; //if the model is a custom model (a trained model)
298
- is_multimodal?: boolean //if the model support files and images
299
- }
300
-
301
- export enum AIModelStatus {
302
- Available = "available",
303
- Pending = "pending",
304
- Stopped = "stopped",
305
- Unavailable = "unavailable",
306
- Unknown = "unknown"
307
- }
308
-
309
- /**
310
- * payload to list available models for an enviroment
311
- * @param environmentId id of the environment
312
- * @param query text to search for in model name/description
313
- * @param type type of the model
314
- * @param tags tags for searching
315
- */
316
- export interface ModelSearchPayload {
317
- text: string;
318
- type?: ModelType;
319
- tags?: string[];
320
- owner?: string;
321
- }
322
-
323
-
324
- export enum ModelType {
325
- Classifier = "classifier",
326
- Regressor = "regressor",
327
- Clustering = "clustering",
328
- AnomalyDetection = "anomaly-detection",
329
- TimeSeries = "time-series",
330
- Text = "text",
331
- Image = "image",
332
- Audio = "audio",
333
- Video = "video",
334
- Embedding = "embedding",
335
- Chat = "chat",
336
- Code = "code",
337
- NLP = "nlp",
338
- MultiModal = "multi-modal",
339
- Test = "test",
340
- Other = "other",
341
- Unknown = "unknown"
342
- }
343
-
344
-
345
- // ============== training =====================
346
-
347
-
348
-
349
- export interface DataSource {
350
- name: string;
351
- mime_type?: string;
352
- getStream(): Promise<ReadableStream<Uint8Array | string>>;
353
- getURL(): Promise<string>;
354
- }
355
-
356
- export interface TrainingOptions {
357
- name: string; // the new model name
358
- model: string; // the model to train
359
- params?: JSONObject; // the training parameters
360
- }
361
-
362
- export interface TrainingPromptOptions {
363
- segments: PromptSegment[];
364
- completion: string | JSONObject;
365
- model: string; // the model to train
366
- schema?: JSONSchema4; // the resuilt schema f any
367
- }
368
-
369
- export enum TrainingJobStatus {
370
- running = "running",
371
- succeeded = "succeeded",
372
- failed = "failed",
373
- cancelled = "cancelled",
374
- }
375
-
376
- export interface TrainingJob {
377
- id: string; // id of the training job
378
- status: TrainingJobStatus; // status of the training job - depends on the implementation
379
- details?: string;
380
- model?: string; // the name of the fine tuned model which is created
381
- }