@llumiverse/common 0.20.0 → 0.22.0-dev.1

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 (74) hide show
  1. package/lib/cjs/capability/azure_foundry.js +159 -0
  2. package/lib/cjs/capability/azure_foundry.js.map +1 -0
  3. package/lib/cjs/capability/bedrock.js +5 -2
  4. package/lib/cjs/capability/bedrock.js.map +1 -1
  5. package/lib/cjs/capability/openai.js +2 -0
  6. package/lib/cjs/capability/openai.js.map +1 -1
  7. package/lib/cjs/capability/vertexai.js +1 -0
  8. package/lib/cjs/capability/vertexai.js.map +1 -1
  9. package/lib/cjs/capability.js +15 -3
  10. package/lib/cjs/capability.js.map +1 -1
  11. package/lib/cjs/options/azure_foundry.js +428 -0
  12. package/lib/cjs/options/azure_foundry.js.map +1 -0
  13. package/lib/cjs/options/bedrock.js +26 -0
  14. package/lib/cjs/options/bedrock.js.map +1 -1
  15. package/lib/cjs/options/openai.js +3 -0
  16. package/lib/cjs/options/openai.js.map +1 -1
  17. package/lib/cjs/options/vertexai.js +49 -2
  18. package/lib/cjs/options/vertexai.js.map +1 -1
  19. package/lib/cjs/options.js +16 -9
  20. package/lib/cjs/options.js.map +1 -1
  21. package/lib/cjs/types.js +146 -1
  22. package/lib/cjs/types.js.map +1 -1
  23. package/lib/esm/capability/azure_foundry.js +156 -0
  24. package/lib/esm/capability/azure_foundry.js.map +1 -0
  25. package/lib/esm/capability/bedrock.js +5 -2
  26. package/lib/esm/capability/bedrock.js.map +1 -1
  27. package/lib/esm/capability/openai.js +2 -0
  28. package/lib/esm/capability/openai.js.map +1 -1
  29. package/lib/esm/capability/vertexai.js +1 -0
  30. package/lib/esm/capability/vertexai.js.map +1 -1
  31. package/lib/esm/capability.js +15 -3
  32. package/lib/esm/capability.js.map +1 -1
  33. package/lib/esm/options/azure_foundry.js +424 -0
  34. package/lib/esm/options/azure_foundry.js.map +1 -0
  35. package/lib/esm/options/bedrock.js +26 -0
  36. package/lib/esm/options/bedrock.js.map +1 -1
  37. package/lib/esm/options/openai.js +3 -0
  38. package/lib/esm/options/openai.js.map +1 -1
  39. package/lib/esm/options/vertexai.js +49 -2
  40. package/lib/esm/options/vertexai.js.map +1 -1
  41. package/lib/esm/options.js +16 -9
  42. package/lib/esm/options.js.map +1 -1
  43. package/lib/esm/types.js +142 -0
  44. package/lib/esm/types.js.map +1 -1
  45. package/lib/tsconfig.tsbuildinfo +1 -0
  46. package/lib/types/capability/azure_foundry.d.ts +7 -0
  47. package/lib/types/capability/azure_foundry.d.ts.map +1 -0
  48. package/lib/types/capability/bedrock.d.ts.map +1 -1
  49. package/lib/types/capability/openai.d.ts.map +1 -1
  50. package/lib/types/capability/vertexai.d.ts.map +1 -1
  51. package/lib/types/capability.d.ts +3 -3
  52. package/lib/types/capability.d.ts.map +1 -1
  53. package/lib/types/options/azure_foundry.d.ts +52 -0
  54. package/lib/types/options/azure_foundry.d.ts.map +1 -0
  55. package/lib/types/options/bedrock.d.ts +8 -2
  56. package/lib/types/options/bedrock.d.ts.map +1 -1
  57. package/lib/types/options/openai.d.ts.map +1 -1
  58. package/lib/types/options/vertexai.d.ts.map +1 -1
  59. package/lib/types/options.d.ts +2 -2
  60. package/lib/types/options.d.ts.map +1 -1
  61. package/lib/types/types.d.ts +60 -10
  62. package/lib/types/types.d.ts.map +1 -1
  63. package/package.json +5 -5
  64. package/src/capability/azure_foundry.ts +180 -0
  65. package/src/capability/bedrock.ts +5 -2
  66. package/src/capability/openai.ts +2 -0
  67. package/src/capability/vertexai.ts +1 -0
  68. package/src/capability.ts +18 -7
  69. package/src/options/azure_foundry.ts +488 -0
  70. package/src/options/bedrock.ts +36 -2
  71. package/src/options/openai.ts +3 -0
  72. package/src/options/vertexai.ts +53 -6
  73. package/src/options.ts +17 -11
  74. package/src/types.ts +193 -17
package/src/options.ts CHANGED
@@ -3,18 +3,24 @@ import { getGroqOptions } from "./options/groq.js";
3
3
  import { getOpenAiOptions } from "./options/openai.js";
4
4
  import { getVertexAiOptions } from "./options/vertexai.js";
5
5
  import { textOptionsFallback } from "./options/fallback.js";
6
- import { ModelOptionsInfo, ModelOptions } from "./types.js";
6
+ import { ModelOptionsInfo, ModelOptions, Providers } from "./types.js";
7
+ import { getAzureFoundryOptions } from "./options/azure_foundry.js";
7
8
 
8
- export function getOptions(model: string, provider?: string, options?: ModelOptions): ModelOptionsInfo {
9
- switch (provider?.toLowerCase()) {
10
- case "bedrock":
11
- return getBedrockOptions(model ?? "", options);
12
- case "vertexai":
13
- return getVertexAiOptions(model ?? "", options);
14
- case "openai":
15
- return getOpenAiOptions(model ?? "", options);
16
- case "groq":
17
- return getGroqOptions(model ?? "", options);
9
+ export function getOptions(model: string, provider?: string | Providers, options?: ModelOptions): ModelOptionsInfo {
10
+ if(!provider) {
11
+ return textOptionsFallback;
12
+ }
13
+ switch (provider.toLowerCase()) {
14
+ case Providers.bedrock:
15
+ return getBedrockOptions(model, options);
16
+ case Providers.vertexai:
17
+ return getVertexAiOptions(model, options);
18
+ case Providers.openai:
19
+ return getOpenAiOptions(model, options);
20
+ case Providers.groq:
21
+ return getGroqOptions(model, options);
22
+ case Providers.azure_foundry:
23
+ return getAzureFoundryOptions(model, options);
18
24
  default:
19
25
  return textOptionsFallback;
20
26
  }
package/src/types.ts CHANGED
@@ -4,6 +4,119 @@ import { GroqOptions } from './options/groq.js';
4
4
  import { OpenAiOptions } from './options/openai.js';
5
5
  import { VertexAIOptions } from './options/vertexai.js';
6
6
 
7
+ // ============== Provider details ===============
8
+
9
+ export enum Providers {
10
+ openai = 'openai',
11
+ azure_openai = 'azure_openai',
12
+ azure_foundry = 'azure_foundry',
13
+ huggingface_ie = 'huggingface_ie',
14
+ replicate = 'replicate',
15
+ bedrock = 'bedrock',
16
+ vertexai = 'vertexai',
17
+ togetherai = 'togetherai',
18
+ mistralai = 'mistralai',
19
+ groq = 'groq',
20
+ watsonx = 'watsonx'
21
+ }
22
+
23
+ export interface ProviderParams {
24
+ id: Providers;
25
+ name: string;
26
+ requiresApiKey: boolean;
27
+ requiresEndpointUrl: boolean;
28
+ endpointPlaceholder?: string;
29
+ supportSearch?: boolean;
30
+ }
31
+
32
+ export const ProviderList: Record<Providers, ProviderParams> = {
33
+ openai:
34
+ {
35
+ id: Providers.openai,
36
+ name: "OpenAI",
37
+ requiresApiKey: true,
38
+ requiresEndpointUrl: false,
39
+ supportSearch: false,
40
+ },
41
+ azure_openai:
42
+ {
43
+ id: Providers.azure_openai,
44
+ name: "Azure OpenAI",
45
+ requiresApiKey: false,
46
+ requiresEndpointUrl: true,
47
+ supportSearch: false,
48
+ },
49
+ azure_foundry:
50
+ {
51
+ id: Providers.azure_foundry,
52
+ name: "Azure Foundry",
53
+ requiresApiKey: true,
54
+ requiresEndpointUrl: true,
55
+ supportSearch: false,
56
+ },
57
+ huggingface_ie:
58
+ {
59
+ id: Providers.huggingface_ie,
60
+ name: "HuggingFace Inference Endpoint",
61
+ requiresApiKey: true,
62
+ requiresEndpointUrl: true,
63
+ },
64
+ replicate:
65
+ {
66
+ id: Providers.replicate,
67
+ name: "Replicate",
68
+ requiresApiKey: true,
69
+ requiresEndpointUrl: false,
70
+ supportSearch: true,
71
+ },
72
+ bedrock:
73
+ {
74
+ id: Providers.bedrock,
75
+ name: "AWS Bedrock",
76
+ requiresApiKey: false,
77
+ requiresEndpointUrl: false,
78
+ endpointPlaceholder: "region name (eg. us-east-1)",
79
+ supportSearch: false,
80
+ },
81
+ vertexai: {
82
+ id: Providers.vertexai,
83
+ name: "Google Vertex AI",
84
+ requiresApiKey: false,
85
+ requiresEndpointUrl: false,
86
+ supportSearch: false,
87
+ },
88
+ togetherai: {
89
+ id: Providers.togetherai,
90
+ name: "Together AI",
91
+ requiresApiKey: false,
92
+ requiresEndpointUrl: false,
93
+ supportSearch: false,
94
+ },
95
+ mistralai: {
96
+ id: Providers.mistralai,
97
+ name: "Mistral AI",
98
+ requiresApiKey: false,
99
+ requiresEndpointUrl: false,
100
+ supportSearch: false,
101
+ },
102
+ groq: {
103
+ id: Providers.groq,
104
+ name: "Groq Cloud",
105
+ requiresApiKey: false,
106
+ requiresEndpointUrl: false,
107
+ supportSearch: false,
108
+ },
109
+ watsonx: {
110
+ id: Providers.watsonx,
111
+ name: "IBM WatsonX",
112
+ requiresApiKey: true,
113
+ requiresEndpointUrl: true,
114
+ supportSearch: false
115
+ },
116
+ }
117
+
118
+ // ============== Embeddings ===============
119
+
7
120
  export interface EmbeddingsOptions {
8
121
  /**
9
122
  * The text to generate the embeddings for. One of text or image is required.
@@ -39,20 +152,90 @@ export interface EmbeddingsResult {
39
152
  export interface ResultValidationError {
40
153
  code: 'validation_error' | 'json_error' | 'content_policy_violation';
41
154
  message: string;
42
- data?: string;
155
+ data?: CompletionResult[];
156
+ }
157
+
158
+ // ============== Result Types ===============
159
+
160
+ export interface BaseResult {
161
+ type: "text" | "json" | "image";
162
+ value: any;
163
+ }
164
+
165
+ export interface TextResult extends BaseResult {
166
+ type: "text";
167
+ value: string;
168
+ }
169
+
170
+ export interface JsonResult extends BaseResult {
171
+ type: "json";
172
+ }
173
+
174
+ export interface ImageResult extends BaseResult {
175
+ type: "image";
176
+ value: string; // base64 data url or real url
177
+ }
178
+
179
+ export type CompletionResult = TextResult | JsonResult | ImageResult;
180
+
181
+ /**
182
+ * Output as string
183
+ */
184
+ export function completionResultToString(result: CompletionResult): string {
185
+ switch (result.type) {
186
+ case "text":
187
+ return result.value;
188
+ case "json":
189
+ return JSON.stringify(result.value, null, 2);
190
+ case "image":
191
+ return result.value;
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Output as JSON, only handles the first JSON result or tries to parse text as JSON
197
+ * Expects the text to be pure JSON if no JSON result is found
198
+ * Throws if no JSON result is found or if parsing fails
199
+ */
200
+ export function parseCompletionResultsToJson(results: CompletionResult[]): any {
201
+ const jsonResults = results.filter(r => r.type === "json");
202
+ if (jsonResults.length >= 1) {
203
+ return jsonResults[0].value;
204
+ //TODO: Handle multiple json type results
205
+ }
206
+
207
+ const textResults = results.filter(r => r.type === "text").join();
208
+ if (textResults.length === 0) {
209
+ throw new Error("No JSON result found or failed to parse text");
210
+ }
211
+ try {
212
+ return JSON.parse(textResults);
213
+ }
214
+ catch {
215
+ throw new Error("No JSON result found or failed to parse text");
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Output as JSON if possible, otherwise as concatenated text
221
+ * Joins text results with the specified separator, default is empty string
222
+ * If multiple JSON results are found only the first one is returned
223
+ */
224
+ export function parseCompletionResults(result: CompletionResult[], separator: string = ""): any {
225
+ try {
226
+ return parseCompletionResultsToJson(result);
227
+ } catch {
228
+ return result.map(completionResultToString).join(separator);
229
+ }
43
230
  }
44
231
 
45
- //ResultT should be either JSONObject or string
46
232
  //Internal structure used in driver implementation.
47
- export interface CompletionChunkObject<ResultT = any> {
48
- result: ResultT;
233
+ export interface CompletionChunkObject {
234
+ result: CompletionResult[];
49
235
  token_usage?: ExecutionTokenUsage;
50
236
  finish_reason?: "stop" | "length" | string;
51
237
  }
52
238
 
53
- //Internal structure used in driver implementation.
54
- export type CompletionChunk = CompletionChunkObject | string;
55
-
56
239
  export interface ToolDefinition {
57
240
  name: string,
58
241
  description?: string,
@@ -72,10 +255,9 @@ export interface ToolUse<ParamsT = JSONObject> {
72
255
  tool_input: ParamsT | null
73
256
  }
74
257
 
75
- //ResultT should be either JSONObject or string
76
- export interface Completion<ResultT = any> {
258
+ export interface Completion {
77
259
  // 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;
260
+ result: CompletionResult[];
79
261
  token_usage?: ExecutionTokenUsage;
80
262
  /**
81
263
  * Contains the tools from which the model awaits information.
@@ -103,12 +285,6 @@ export interface Completion<ResultT = any> {
103
285
  conversation?: unknown;
104
286
  }
105
287
 
106
- export interface ImageGeneration {
107
-
108
- images?: string[];
109
-
110
- }
111
-
112
288
  export interface ExecutionResponse<PromptT = any> extends Completion {
113
289
  prompt: PromptT;
114
290
  /**
@@ -420,7 +596,7 @@ export interface TrainingOptions {
420
596
 
421
597
  export interface TrainingPromptOptions {
422
598
  segments: PromptSegment[];
423
- completion: string | JSONObject;
599
+ completion: CompletionResult[]
424
600
  model: string; // the model to train
425
601
  schema?: JSONSchema; // the result schema f any
426
602
  }