@llumiverse/drivers 0.22.0 → 0.23.0-dev-20251118

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 (295) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/adobe/firefly.js +8 -7
  3. package/lib/cjs/adobe/firefly.js.map +1 -1
  4. package/lib/cjs/azure/azure_foundry.js +12 -12
  5. package/lib/cjs/azure/azure_foundry.js.map +1 -1
  6. package/lib/cjs/bedrock/index.js +172 -22
  7. package/lib/cjs/bedrock/index.js.map +1 -1
  8. package/lib/cjs/bedrock/twelvelabs.js +87 -0
  9. package/lib/cjs/bedrock/twelvelabs.js.map +1 -0
  10. package/lib/cjs/groq/index.js +91 -16
  11. package/lib/cjs/groq/index.js.map +1 -1
  12. package/lib/cjs/huggingface_ie.js +7 -6
  13. package/lib/cjs/huggingface_ie.js.map +1 -1
  14. package/lib/cjs/index.js +2 -2
  15. package/lib/cjs/index.js.map +1 -1
  16. package/lib/cjs/mistral/index.js +5 -4
  17. package/lib/cjs/mistral/index.js.map +1 -1
  18. package/lib/cjs/openai/azure_openai.js +1 -1
  19. package/lib/cjs/openai/azure_openai.js.map +1 -1
  20. package/lib/cjs/openai/index.js +16 -12
  21. package/lib/cjs/openai/index.js.map +1 -1
  22. package/lib/cjs/replicate.js +6 -6
  23. package/lib/cjs/replicate.js.map +1 -1
  24. package/lib/cjs/test/utils.js +1 -1
  25. package/lib/cjs/test/utils.js.map +1 -1
  26. package/lib/cjs/test-driver/TestErrorCompletionStream.js +20 -0
  27. package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +1 -0
  28. package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +24 -0
  29. package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
  30. package/lib/cjs/test-driver/index.js +109 -0
  31. package/lib/cjs/test-driver/index.js.map +1 -0
  32. package/lib/cjs/test-driver/utils.js +30 -0
  33. package/lib/cjs/test-driver/utils.js.map +1 -0
  34. package/lib/cjs/togetherai/index.js +4 -4
  35. package/lib/cjs/togetherai/index.js.map +1 -1
  36. package/lib/cjs/vertexai/embeddings/embeddings-text.js +1 -1
  37. package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +1 -1
  38. package/lib/cjs/vertexai/index.js +136 -31
  39. package/lib/cjs/vertexai/index.js.map +1 -1
  40. package/lib/cjs/vertexai/models/claude.js +38 -16
  41. package/lib/cjs/vertexai/models/claude.js.map +1 -1
  42. package/lib/cjs/vertexai/models/gemini.js +131 -41
  43. package/lib/cjs/vertexai/models/gemini.js.map +1 -1
  44. package/lib/cjs/vertexai/models/imagen.js +12 -23
  45. package/lib/cjs/vertexai/models/imagen.js.map +1 -1
  46. package/lib/cjs/vertexai/models/llama.js +4 -3
  47. package/lib/cjs/vertexai/models/llama.js.map +1 -1
  48. package/lib/cjs/vertexai/models.js +13 -2
  49. package/lib/cjs/vertexai/models.js.map +1 -1
  50. package/lib/cjs/watsonx/index.js +5 -5
  51. package/lib/cjs/watsonx/index.js.map +1 -1
  52. package/lib/cjs/xai/index.js +1 -1
  53. package/lib/cjs/xai/index.js.map +1 -1
  54. package/lib/esm/adobe/firefly.js +8 -7
  55. package/lib/esm/adobe/firefly.js.map +1 -1
  56. package/lib/esm/azure/azure_foundry.js +12 -12
  57. package/lib/esm/azure/azure_foundry.js.map +1 -1
  58. package/lib/esm/bedrock/index.js +172 -22
  59. package/lib/esm/bedrock/index.js.map +1 -1
  60. package/lib/esm/bedrock/twelvelabs.js +84 -0
  61. package/lib/esm/bedrock/twelvelabs.js.map +1 -0
  62. package/lib/esm/groq/index.js +91 -16
  63. package/lib/esm/groq/index.js.map +1 -1
  64. package/lib/esm/huggingface_ie.js +8 -7
  65. package/lib/esm/huggingface_ie.js.map +1 -1
  66. package/lib/esm/index.js +2 -2
  67. package/lib/esm/index.js.map +1 -1
  68. package/lib/esm/mistral/index.js +5 -4
  69. package/lib/esm/mistral/index.js.map +1 -1
  70. package/lib/esm/openai/azure_openai.js +1 -1
  71. package/lib/esm/openai/azure_openai.js.map +1 -1
  72. package/lib/esm/openai/index.js +16 -12
  73. package/lib/esm/openai/index.js.map +1 -1
  74. package/lib/esm/replicate.js +6 -6
  75. package/lib/esm/replicate.js.map +1 -1
  76. package/lib/esm/src/adobe/firefly.js +116 -0
  77. package/lib/esm/src/adobe/firefly.js.map +1 -0
  78. package/lib/esm/src/azure/azure_foundry.js +382 -0
  79. package/lib/esm/src/azure/azure_foundry.js.map +1 -0
  80. package/lib/esm/src/bedrock/converse.js +278 -0
  81. package/lib/esm/src/bedrock/converse.js.map +1 -0
  82. package/lib/esm/src/bedrock/index.js +962 -0
  83. package/lib/esm/src/bedrock/index.js.map +1 -0
  84. package/lib/esm/src/bedrock/nova-image-payload.js +203 -0
  85. package/lib/esm/src/bedrock/nova-image-payload.js.map +1 -0
  86. package/lib/esm/src/bedrock/payloads.js +2 -0
  87. package/lib/esm/src/bedrock/payloads.js.map +1 -0
  88. package/lib/esm/src/bedrock/s3.js +99 -0
  89. package/lib/esm/src/bedrock/s3.js.map +1 -0
  90. package/lib/esm/src/bedrock/twelvelabs.js +84 -0
  91. package/lib/esm/src/bedrock/twelvelabs.js.map +1 -0
  92. package/lib/esm/src/groq/index.js +286 -0
  93. package/lib/esm/src/groq/index.js.map +1 -0
  94. package/lib/esm/src/huggingface_ie.js +197 -0
  95. package/lib/esm/src/huggingface_ie.js.map +1 -0
  96. package/lib/esm/src/index.js +14 -0
  97. package/lib/esm/src/index.js.map +1 -0
  98. package/lib/esm/src/mistral/index.js +169 -0
  99. package/lib/esm/src/mistral/index.js.map +1 -0
  100. package/lib/esm/src/mistral/types.js +80 -0
  101. package/lib/esm/src/mistral/types.js.map +1 -0
  102. package/lib/esm/src/openai/azure_openai.js +68 -0
  103. package/lib/esm/src/openai/azure_openai.js.map +1 -0
  104. package/lib/esm/src/openai/index.js +464 -0
  105. package/lib/esm/src/openai/index.js.map +1 -0
  106. package/lib/esm/src/openai/openai.js +14 -0
  107. package/lib/esm/src/openai/openai.js.map +1 -0
  108. package/lib/esm/src/openai/openai_format.js +134 -0
  109. package/lib/esm/src/openai/openai_format.js.map +1 -0
  110. package/lib/esm/src/replicate.js +268 -0
  111. package/lib/esm/src/replicate.js.map +1 -0
  112. package/lib/esm/src/test/TestErrorCompletionStream.js +16 -0
  113. package/lib/esm/src/test/TestErrorCompletionStream.js.map +1 -0
  114. package/lib/esm/src/test/TestValidationErrorCompletionStream.js +20 -0
  115. package/lib/esm/src/test/TestValidationErrorCompletionStream.js.map +1 -0
  116. package/lib/esm/src/test/index.js +91 -0
  117. package/lib/esm/src/test/index.js.map +1 -0
  118. package/lib/esm/src/test/utils.js +25 -0
  119. package/lib/esm/src/test/utils.js.map +1 -0
  120. package/lib/esm/src/test-driver/TestErrorCompletionStream.js +16 -0
  121. package/lib/esm/src/test-driver/TestErrorCompletionStream.js.map +1 -0
  122. package/lib/esm/src/test-driver/TestValidationErrorCompletionStream.js +20 -0
  123. package/lib/esm/src/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
  124. package/lib/esm/src/test-driver/index.js +91 -0
  125. package/lib/esm/src/test-driver/index.js.map +1 -0
  126. package/lib/esm/src/test-driver/utils.js +25 -0
  127. package/lib/esm/src/test-driver/utils.js.map +1 -0
  128. package/lib/esm/src/togetherai/index.js +122 -0
  129. package/lib/esm/src/togetherai/index.js.map +1 -0
  130. package/lib/esm/src/togetherai/interfaces.js +2 -0
  131. package/lib/esm/src/togetherai/interfaces.js.map +1 -0
  132. package/lib/esm/src/vertexai/debug.js +6 -0
  133. package/lib/esm/src/vertexai/debug.js.map +1 -0
  134. package/lib/esm/src/vertexai/embeddings/embeddings-image.js +24 -0
  135. package/lib/esm/src/vertexai/embeddings/embeddings-image.js.map +1 -0
  136. package/lib/esm/src/vertexai/embeddings/embeddings-text.js +20 -0
  137. package/lib/esm/src/vertexai/embeddings/embeddings-text.js.map +1 -0
  138. package/lib/esm/src/vertexai/index.js +383 -0
  139. package/lib/esm/src/vertexai/index.js.map +1 -0
  140. package/lib/esm/src/vertexai/models/claude.js +394 -0
  141. package/lib/esm/src/vertexai/models/claude.js.map +1 -0
  142. package/lib/esm/src/vertexai/models/gemini.js +817 -0
  143. package/lib/esm/src/vertexai/models/gemini.js.map +1 -0
  144. package/lib/esm/src/vertexai/models/imagen.js +302 -0
  145. package/lib/esm/src/vertexai/models/imagen.js.map +1 -0
  146. package/lib/esm/src/vertexai/models/llama.js +179 -0
  147. package/lib/esm/src/vertexai/models/llama.js.map +1 -0
  148. package/lib/esm/src/vertexai/models.js +32 -0
  149. package/lib/esm/src/vertexai/models.js.map +1 -0
  150. package/lib/esm/src/watsonx/index.js +157 -0
  151. package/lib/esm/src/watsonx/index.js.map +1 -0
  152. package/lib/esm/src/watsonx/interfaces.js +2 -0
  153. package/lib/esm/src/watsonx/interfaces.js.map +1 -0
  154. package/lib/esm/src/xai/index.js +64 -0
  155. package/lib/esm/src/xai/index.js.map +1 -0
  156. package/lib/esm/test/utils.js +1 -1
  157. package/lib/esm/test/utils.js.map +1 -1
  158. package/lib/esm/test-driver/TestErrorCompletionStream.js +16 -0
  159. package/lib/esm/test-driver/TestErrorCompletionStream.js.map +1 -0
  160. package/lib/esm/test-driver/TestValidationErrorCompletionStream.js +20 -0
  161. package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
  162. package/lib/esm/test-driver/index.js +91 -0
  163. package/lib/esm/test-driver/index.js.map +1 -0
  164. package/lib/esm/test-driver/utils.js +25 -0
  165. package/lib/esm/test-driver/utils.js.map +1 -0
  166. package/lib/esm/togetherai/index.js +4 -4
  167. package/lib/esm/togetherai/index.js.map +1 -1
  168. package/lib/esm/tsconfig.tsbuildinfo +1 -0
  169. package/lib/esm/vertexai/embeddings/embeddings-text.js +1 -1
  170. package/lib/esm/vertexai/embeddings/embeddings-text.js.map +1 -1
  171. package/lib/esm/vertexai/index.js +136 -31
  172. package/lib/esm/vertexai/index.js.map +1 -1
  173. package/lib/esm/vertexai/models/claude.js +37 -15
  174. package/lib/esm/vertexai/models/claude.js.map +1 -1
  175. package/lib/esm/vertexai/models/gemini.js +133 -43
  176. package/lib/esm/vertexai/models/gemini.js.map +1 -1
  177. package/lib/esm/vertexai/models/imagen.js +9 -17
  178. package/lib/esm/vertexai/models/imagen.js.map +1 -1
  179. package/lib/esm/vertexai/models/llama.js +4 -3
  180. package/lib/esm/vertexai/models/llama.js.map +1 -1
  181. package/lib/esm/vertexai/models.js +13 -2
  182. package/lib/esm/vertexai/models.js.map +1 -1
  183. package/lib/esm/watsonx/index.js +5 -5
  184. package/lib/esm/watsonx/index.js.map +1 -1
  185. package/lib/esm/xai/index.js +1 -1
  186. package/lib/esm/xai/index.js.map +1 -1
  187. package/lib/types/adobe/firefly.d.ts +3 -3
  188. package/lib/types/adobe/firefly.d.ts.map +1 -1
  189. package/lib/types/azure/azure_foundry.d.ts +2 -2
  190. package/lib/types/azure/azure_foundry.d.ts.map +1 -1
  191. package/lib/types/bedrock/index.d.ts +9 -5
  192. package/lib/types/bedrock/index.d.ts.map +1 -1
  193. package/lib/types/bedrock/twelvelabs.d.ts +50 -0
  194. package/lib/types/bedrock/twelvelabs.d.ts.map +1 -0
  195. package/lib/types/groq/index.d.ts +3 -0
  196. package/lib/types/groq/index.d.ts.map +1 -1
  197. package/lib/types/huggingface_ie.d.ts +8 -5
  198. package/lib/types/huggingface_ie.d.ts.map +1 -1
  199. package/lib/types/index.d.ts +2 -2
  200. package/lib/types/index.d.ts.map +1 -1
  201. package/lib/types/mistral/index.d.ts +2 -2
  202. package/lib/types/mistral/index.d.ts.map +1 -1
  203. package/lib/types/openai/index.d.ts +2 -2
  204. package/lib/types/openai/index.d.ts.map +1 -1
  205. package/lib/types/replicate.d.ts +6 -3
  206. package/lib/types/replicate.d.ts.map +1 -1
  207. package/lib/types/src/adobe/firefly.d.ts +29 -0
  208. package/lib/types/src/azure/azure_foundry.d.ts +49 -0
  209. package/lib/types/src/bedrock/converse.d.ts +8 -0
  210. package/lib/types/src/bedrock/index.d.ts +61 -0
  211. package/lib/types/src/bedrock/nova-image-payload.d.ts +73 -0
  212. package/lib/types/src/bedrock/payloads.d.ts +11 -0
  213. package/lib/types/src/bedrock/s3.d.ts +22 -0
  214. package/lib/types/src/bedrock/twelvelabs.d.ts +49 -0
  215. package/lib/types/src/groq/index.d.ts +26 -0
  216. package/lib/types/src/huggingface_ie.d.ts +34 -0
  217. package/lib/types/src/index.d.ts +13 -0
  218. package/lib/types/src/mistral/index.d.ts +24 -0
  219. package/lib/types/src/mistral/types.d.ts +131 -0
  220. package/lib/types/src/openai/azure_openai.d.ts +24 -0
  221. package/lib/types/src/openai/index.d.ts +24 -0
  222. package/lib/types/src/openai/openai.d.ts +14 -0
  223. package/lib/types/src/openai/openai_format.d.ts +18 -0
  224. package/lib/types/src/replicate.d.ts +47 -0
  225. package/lib/types/src/test/TestErrorCompletionStream.d.ts +8 -0
  226. package/lib/types/src/test/TestValidationErrorCompletionStream.d.ts +8 -0
  227. package/lib/types/src/test/index.d.ts +23 -0
  228. package/lib/types/src/test/utils.d.ts +4 -0
  229. package/lib/types/src/test-driver/TestErrorCompletionStream.d.ts +8 -0
  230. package/lib/types/src/test-driver/TestValidationErrorCompletionStream.d.ts +8 -0
  231. package/lib/types/src/test-driver/index.d.ts +23 -0
  232. package/lib/types/src/test-driver/utils.d.ts +4 -0
  233. package/lib/types/src/togetherai/index.d.ts +22 -0
  234. package/lib/types/src/togetherai/interfaces.d.ts +95 -0
  235. package/lib/types/src/vertexai/debug.d.ts +1 -0
  236. package/lib/types/src/vertexai/embeddings/embeddings-image.d.ts +10 -0
  237. package/lib/types/src/vertexai/embeddings/embeddings-text.d.ts +9 -0
  238. package/lib/types/src/vertexai/index.d.ts +52 -0
  239. package/lib/types/src/vertexai/models/claude.d.ts +19 -0
  240. package/lib/types/src/vertexai/models/gemini.d.ts +17 -0
  241. package/lib/types/src/vertexai/models/imagen.d.ts +74 -0
  242. package/lib/types/src/vertexai/models/llama.d.ts +19 -0
  243. package/lib/types/src/vertexai/models.d.ts +14 -0
  244. package/lib/types/src/watsonx/index.d.ts +26 -0
  245. package/lib/types/src/watsonx/interfaces.d.ts +64 -0
  246. package/lib/types/src/xai/index.d.ts +18 -0
  247. package/lib/types/test-driver/TestErrorCompletionStream.d.ts +9 -0
  248. package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +1 -0
  249. package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts +9 -0
  250. package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +1 -0
  251. package/lib/types/test-driver/index.d.ts +24 -0
  252. package/lib/types/test-driver/index.d.ts.map +1 -0
  253. package/lib/types/test-driver/utils.d.ts +5 -0
  254. package/lib/types/test-driver/utils.d.ts.map +1 -0
  255. package/lib/types/togetherai/index.d.ts +3 -3
  256. package/lib/types/togetherai/index.d.ts.map +1 -1
  257. package/lib/types/vertexai/index.d.ts +17 -14
  258. package/lib/types/vertexai/index.d.ts.map +1 -1
  259. package/lib/types/vertexai/models/claude.d.ts +2 -0
  260. package/lib/types/vertexai/models/claude.d.ts.map +1 -1
  261. package/lib/types/vertexai/models/gemini.d.ts.map +1 -1
  262. package/lib/types/vertexai/models/imagen.d.ts +2 -2
  263. package/lib/types/vertexai/models/imagen.d.ts.map +1 -1
  264. package/lib/types/vertexai/models/llama.d.ts +2 -2
  265. package/lib/types/vertexai/models/llama.d.ts.map +1 -1
  266. package/lib/types/vertexai/models.d.ts +2 -2
  267. package/lib/types/vertexai/models.d.ts.map +1 -1
  268. package/lib/types/watsonx/index.d.ts +3 -3
  269. package/lib/types/watsonx/index.d.ts.map +1 -1
  270. package/package.json +90 -85
  271. package/src/adobe/firefly.ts +14 -22
  272. package/src/azure/azure_foundry.ts +16 -16
  273. package/src/bedrock/index.ts +207 -28
  274. package/src/bedrock/twelvelabs.ts +150 -0
  275. package/src/groq/index.ts +134 -37
  276. package/src/huggingface_ie.ts +13 -14
  277. package/src/index.ts +2 -2
  278. package/src/mistral/index.ts +8 -7
  279. package/src/openai/azure_openai.ts +5 -5
  280. package/src/openai/index.ts +19 -13
  281. package/src/replicate.ts +14 -14
  282. package/src/{test → test-driver}/utils.ts +1 -1
  283. package/src/togetherai/index.ts +7 -7
  284. package/src/vertexai/embeddings/embeddings-text.ts +2 -2
  285. package/src/vertexai/index.ts +156 -40
  286. package/src/vertexai/models/claude.ts +45 -19
  287. package/src/vertexai/models/gemini.ts +161 -60
  288. package/src/vertexai/models/imagen.ts +15 -26
  289. package/src/vertexai/models/llama.ts +6 -5
  290. package/src/vertexai/models.ts +18 -6
  291. package/src/watsonx/index.ts +8 -8
  292. package/src/xai/index.ts +11 -12
  293. /package/src/{test → test-driver}/TestErrorCompletionStream.ts +0 -0
  294. /package/src/{test → test-driver}/TestValidationErrorCompletionStream.ts +0 -0
  295. /package/src/{test → test-driver}/index.ts +0 -0
package/src/replicate.ts CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  AIModel,
3
3
  AbstractDriver,
4
4
  Completion,
5
- CompletionChunk,
5
+ CompletionChunkObject,
6
6
  DataSource,
7
7
  DriverOptions,
8
8
  EmbeddingsResult,
@@ -15,7 +15,7 @@ import {
15
15
  } from "@llumiverse/core";
16
16
  import { EventStream } from "@llumiverse/core/async";
17
17
  import { EventSource } from "eventsource";
18
- import Replicate, { Prediction } from "replicate";
18
+ import Replicate, { Prediction, Training } from "replicate";
19
19
 
20
20
  let cachedTrainableModels: AIModel[] | undefined;
21
21
  let cachedTrainableModelsTimestamp: number = 0;
@@ -64,12 +64,12 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
64
64
  };
65
65
  }
66
66
 
67
- async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunk>> {
67
+ async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
68
68
  if (options.model_options?._option_id !== "text-fallback") {
69
- this.logger.warn("Invalid model options", {options: options.model_options });
69
+ this.logger.warn({ options: options.model_options }, "Invalid model options");
70
70
  }
71
71
  options.model_options = options.model_options as TextFallbackOptions;
72
-
72
+
73
73
  const model = ReplicateDriver.parseModelId(options.model);
74
74
  const predictionData = {
75
75
  input: {
@@ -84,11 +84,11 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
84
84
  const prediction =
85
85
  await this.service.predictions.create(predictionData);
86
86
 
87
- const stream = new EventStream<CompletionChunk>();
87
+ const stream = new EventStream<CompletionChunkObject>();
88
88
 
89
89
  const source = new EventSource(prediction.urls.stream!);
90
90
  source.addEventListener("output", (e: any) => {
91
- stream.push(e.data);
91
+ stream.push({ result: [{ type: "text", value: e.data }] });
92
92
  });
93
93
  source.addEventListener("error", (e: any) => {
94
94
  let error: any;
@@ -97,7 +97,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
97
97
  } catch (error) {
98
98
  error = JSON.stringify(e);
99
99
  }
100
- this.logger?.error("Error in SSE stream", {e, error});
100
+ this.logger.error({ e, error }, "Error in SSE stream");
101
101
  });
102
102
  source.addEventListener("done", () => {
103
103
  try {
@@ -111,7 +111,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
111
111
 
112
112
  async requestTextCompletion(prompt: string, options: ExecutionOptions) {
113
113
  if (options.model_options?._option_id !== "text-fallback") {
114
- this.logger.warn("Invalid model options", {options: options.model_options });
114
+ this.logger.warn({ options: options.model_options }, "Invalid model options");
115
115
  }
116
116
  options.model_options = options.model_options as TextFallbackOptions;
117
117
  const model = ReplicateDriver.parseModelId(options.model);
@@ -136,9 +136,9 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
136
136
  //not streaming, wait for the result
137
137
  const res = await this.service.wait(prediction, {});
138
138
 
139
- const text = res.output.join("");
139
+ const text: string = res.output.join("");
140
140
  return {
141
- result: text,
141
+ result: [{ type: "text" as const, value: text }],
142
142
  original_response: options.include_original_response ? res : undefined,
143
143
  };
144
144
  }
@@ -236,7 +236,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
236
236
  this.service.models.versions.list(owner, model),
237
237
  ]);
238
238
 
239
- if (!rModel || !versions || versions.length === 0) {
239
+ if (!rModel || !versions || (versions as any).results?.length === 0) {
240
240
  throw new Error("Model not found or no versions available");
241
241
  }
242
242
 
@@ -289,7 +289,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
289
289
 
290
290
  }
291
291
 
292
- function jobInfo(job: Prediction, modelName?: string): TrainingJob {
292
+ function jobInfo(job: Prediction | Training, modelName?: string): TrainingJob {
293
293
  // 'starting' | 'processing' | 'succeeded' | 'failed' | 'canceled'
294
294
  const jobStatus = job.status;
295
295
  let details: string | undefined;
@@ -298,7 +298,7 @@ function jobInfo(job: Prediction, modelName?: string): TrainingJob {
298
298
  status = TrainingJobStatus.succeeded;
299
299
  } else if (jobStatus === 'failed') {
300
300
  status = TrainingJobStatus.failed;
301
- const error = job.error as any;
301
+ const error = job.error as any;
302
302
  if (typeof error === 'string') {
303
303
  details = error;
304
304
  } else {
@@ -8,7 +8,7 @@ export function throwError(message: string, prompt: PromptSegment[]): never {
8
8
 
9
9
  export function createValidationErrorCompletion(segments: PromptSegment[]) {
10
10
  return {
11
- result: "An invalid result",
11
+ result: [{ type: "text", value: "An invalid result" }],
12
12
  prompt: segments,
13
13
  execution_time: 3000,
14
14
  error: {
@@ -1,4 +1,4 @@
1
- import { AIModel, AbstractDriver, Completion, CompletionChunk, DriverOptions, EmbeddingsResult, ExecutionOptions, TextFallbackOptions } from "@llumiverse/core";
1
+ import { AIModel, AbstractDriver, Completion, CompletionChunkObject, DriverOptions, EmbeddingsResult, ExecutionOptions, TextFallbackOptions } from "@llumiverse/core";
2
2
  import { transformSSEStream } from "@llumiverse/core/async";
3
3
  import { FetchClient } from "@vertesia/api-fetch-client";
4
4
  import { TextCompletion, TogetherModelInfo } from "./interfaces.js";
@@ -29,9 +29,9 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
29
29
  } : undefined;
30
30
  }
31
31
 
32
- async requestTextCompletion(prompt: string, options: ExecutionOptions): Promise<Completion<any>> {
32
+ async requestTextCompletion(prompt: string, options: ExecutionOptions): Promise<Completion> {
33
33
  if (options.model_options?._option_id !== "text-fallback") {
34
- this.logger.warn("Invalid model options", {options: options.model_options });
34
+ this.logger.warn({ options: options.model_options }, "Invalid model options");
35
35
  }
36
36
  options.model_options = options.model_options as TextFallbackOptions;
37
37
 
@@ -60,7 +60,7 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
60
60
  const text = choice.text ?? '';
61
61
  const usage = res.usage || {};
62
62
  return {
63
- result: text,
63
+ result: [{ type: "text", value: text }],
64
64
  token_usage: {
65
65
  prompt: usage.prompt_tokens,
66
66
  result: usage.completion_tokens,
@@ -71,9 +71,9 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
71
71
  }
72
72
  }
73
73
 
74
- async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunk>> {
74
+ async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
75
75
  if (options.model_options?._option_id !== "text-fallback") {
76
- this.logger.warn("Invalid model options", {options: options.model_options });
76
+ this.logger.warn({ options: options.model_options }, "Invalid model options");
77
77
  }
78
78
  options.model_options = options.model_options as TextFallbackOptions;
79
79
 
@@ -103,7 +103,7 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
103
103
  return transformSSEStream(stream, (data: string) => {
104
104
  const json = JSON.parse(data);
105
105
  return {
106
- result: json.choices[0]?.text ?? '',
106
+ result: [{ type: "text", value: json.choices[0]?.text ?? '' }],
107
107
  finish_reason: json.choices[0]?.finish_reason, //Uses expected "stop" , "length" format
108
108
  token_usage: {
109
109
  prompt: json.usage?.prompt_tokens,
@@ -36,9 +36,9 @@ export async function getEmbeddingsForText(driver: VertexAIDriver, options: Text
36
36
  title: options.title,
37
37
  content: options.content
38
38
  }]
39
- } as EmbeddingsForTextPrompt;
39
+ } satisfies EmbeddingsForTextPrompt;
40
40
 
41
- const model = options.model || "text-embedding-004";
41
+ const model = options.model || "gemini-embedding-001";
42
42
 
43
43
  const client = driver.getFetchClient();
44
44
 
@@ -1,12 +1,15 @@
1
+ import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
2
+ import { PredictionServiceClient, v1beta1 } from "@google-cloud/aiplatform";
3
+ import { Content, GoogleGenAI, Model } from "@google/genai";
1
4
  import {
2
5
  AIModel,
3
6
  AbstractDriver,
4
7
  Completion,
5
- CompletionChunk,
8
+ CompletionChunkObject,
6
9
  DriverOptions,
10
+ EmbeddingsOptions,
7
11
  EmbeddingsResult,
8
12
  ExecutionOptions,
9
- ImageGeneration,
10
13
  Modalities,
11
14
  ModelSearchPayload,
12
15
  PromptSegment,
@@ -14,16 +17,12 @@ import {
14
17
  modelModalitiesToArray,
15
18
  } from "@llumiverse/core";
16
19
  import { FetchClient } from "@vertesia/api-fetch-client";
17
- import { GoogleAuth, GoogleAuthOptions } from "google-auth-library";
18
- import { JSONClient } from "google-auth-library/build/src/auth/googleauth.js";
20
+ import { GoogleAuth, GoogleAuthOptions, AuthClient } from "google-auth-library";
21
+ import { getEmbeddingsForImages } from "./embeddings/embeddings-image.js";
19
22
  import { TextEmbeddingsOptions, getEmbeddingsForText } from "./embeddings/embeddings-text.js";
20
23
  import { getModelDefinition } from "./models.js";
21
- import { EmbeddingsOptions } from "@llumiverse/core";
22
- import { getEmbeddingsForImages } from "./embeddings/embeddings-image.js";
23
- import { v1beta1 } from "@google-cloud/aiplatform";
24
- import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
24
+ import { ANTHROPIC_REGIONS, NON_GLOBAL_ANTHROPIC_MODELS } from "./models/claude.js";
25
25
  import { ImagenModelDefinition, ImagenPrompt } from "./models/imagen.js";
26
- import { GoogleGenAI, Content } from "@google/genai";
27
26
 
28
27
  export interface VertexAIDriverOptions extends DriverOptions {
29
28
  project: string;
@@ -54,8 +53,10 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
54
53
  googleGenAI: GoogleGenAI | undefined;
55
54
  llamaClient: FetchClient & { region?: string } | undefined;
56
55
  modelGarden: v1beta1.ModelGardenServiceClient | undefined;
56
+ imagenClient: PredictionServiceClient | undefined;
57
57
 
58
- authClient: JSONClient | GoogleAuth<JSONClient>;
58
+ googleAuth: GoogleAuth<any>;
59
+ private authClientPromise: Promise<AuthClient> | undefined;
59
60
 
60
61
  constructor(options: VertexAIDriverOptions) {
61
62
  super(options);
@@ -66,19 +67,39 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
66
67
  this.googleGenAI = undefined;
67
68
  this.modelGarden = undefined;
68
69
  this.llamaClient = undefined;
70
+ this.imagenClient = undefined;
69
71
 
70
- this.authClient = options.googleAuthOptions?.authClient ?? new GoogleAuth(options.googleAuthOptions);
72
+ this.googleAuth = new GoogleAuth(options.googleAuthOptions) as GoogleAuth<any>;
73
+ this.authClientPromise = undefined;
71
74
  }
72
75
 
73
- public getGoogleGenAIClient(): GoogleGenAI {
74
- //Lazy initialisation
76
+ private async getAuthClient(): Promise<AuthClient> {
77
+ if (!this.authClientPromise) {
78
+ this.authClientPromise = this.googleAuth.getClient();
79
+ }
80
+ return this.authClientPromise;
81
+ }
82
+
83
+ public getGoogleGenAIClient(region: string = this.options.region): GoogleGenAI {
84
+ //Lazy initialization
85
+ if (region !== this.options.region) {
86
+ //Get one off client for different region
87
+ return new GoogleGenAI({
88
+ project: this.options.project,
89
+ location: region,
90
+ vertexai: true,
91
+ googleAuthOptions: this.options.googleAuthOptions || {
92
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"],
93
+ }
94
+ });
95
+ }
75
96
  if (!this.googleGenAI) {
76
97
  this.googleGenAI = new GoogleGenAI({
77
98
  project: this.options.project,
78
- location: this.options.region,
99
+ location: region,
79
100
  vertexai: true,
80
- googleAuthOptions: {
81
- authClient: this.authClient as JSONClient,
101
+ googleAuthOptions: this.options.googleAuthOptions || {
102
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"],
82
103
  }
83
104
  });
84
105
  }
@@ -86,14 +107,13 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
86
107
  }
87
108
 
88
109
  public getFetchClient(): FetchClient {
89
- //Lazy initialisation
110
+ //Lazy initialization
90
111
  if (!this.fetchClient) {
91
112
  this.fetchClient = createFetchClient({
92
113
  region: this.options.region,
93
114
  project: this.options.project,
94
115
  }).withAuthCallback(async () => {
95
- const accessTokenResponse = await this.authClient.getAccessToken();
96
- const token = typeof accessTokenResponse === 'string' ? accessTokenResponse : accessTokenResponse?.token;
116
+ const token = await this.googleAuth.getAccessToken();
97
117
  return `Bearer ${token}`;
98
118
  });
99
119
  }
@@ -101,15 +121,14 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
101
121
  }
102
122
 
103
123
  public getLLamaClient(region: string = "us-central1"): FetchClient {
104
- //Lazy initialisation
124
+ //Lazy initialization
105
125
  if (!this.llamaClient || this.llamaClient["region"] !== region) {
106
126
  this.llamaClient = createFetchClient({
107
127
  region: region,
108
128
  project: this.options.project,
109
129
  apiVersion: "v1beta1",
110
130
  }).withAuthCallback(async () => {
111
- const accessTokenResponse = await this.authClient.getAccessToken();
112
- const token = typeof accessTokenResponse === 'string' ? accessTokenResponse : accessTokenResponse?.token;
131
+ const token = await this.googleAuth.getAccessToken();
113
132
  return `Bearer ${token}`;
114
133
  });
115
134
  // Store the region for potential client reuse
@@ -118,42 +137,80 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
118
137
  return this.llamaClient;
119
138
  }
120
139
 
121
- public getAnthropicClient(): AnthropicVertex {
122
- //Lazy initialisation
140
+ public async getAnthropicClient(region: string = this.options.region): Promise<AnthropicVertex> {
141
+ // Extract region prefix and map if it exists in ANTHROPIC_REGIONS, otherwise use as-is
142
+ const getRegionPrefix = (r: string) => r.split('-')[0];
143
+ const regionPrefix = getRegionPrefix(region);
144
+ const mappedRegion = ANTHROPIC_REGIONS[regionPrefix] || region;
145
+
146
+ const defaultRegionPrefix = getRegionPrefix(this.options.region);
147
+ const defaultMappedRegion = ANTHROPIC_REGIONS[defaultRegionPrefix] || this.options.region;
148
+
149
+ // Get auth client to avoid version mismatch with GoogleAuth generic types
150
+ const authClient = await this.getAuthClient();
151
+
152
+ // If mapped region is different from default mapped region, create one-off client
153
+ if (mappedRegion !== defaultMappedRegion) {
154
+ return new AnthropicVertex({
155
+ timeout: 20 * 60 * 10000, // Set to 20 minutes, 10 minute default, setting this disables long request error: https://github.com/anthropics/anthropic-sdk-typescript?#long-requests
156
+ region: mappedRegion,
157
+ projectId: this.options.project,
158
+ authClient,
159
+ });
160
+ }
161
+
162
+ //Lazy initialization for default region
123
163
  if (!this.anthropicClient) {
124
164
  this.anthropicClient = new AnthropicVertex({
125
165
  timeout: 20 * 60 * 10000, // Set to 20 minutes, 10 minute default, setting this disables long request error: https://github.com/anthropics/anthropic-sdk-typescript?#long-requests
126
- region: "us-east5",
127
- projectId: process.env.GOOGLE_PROJECT_ID,
166
+ region: mappedRegion,
167
+ projectId: this.options.project,
168
+ authClient,
128
169
  });
129
170
  }
130
171
  return this.anthropicClient;
131
172
  }
132
173
 
133
- public getAIPlatformClient(): v1beta1.ModelServiceClient {
134
- //Lazy initialisation
174
+ public async getAIPlatformClient(): Promise<v1beta1.ModelServiceClient> {
175
+ //Lazy initialization
135
176
  if (!this.aiplatform) {
177
+ const authClient = await this.getAuthClient();
136
178
  this.aiplatform = new v1beta1.ModelServiceClient({
137
179
  projectId: this.options.project,
138
180
  apiEndpoint: `${this.options.region}-${API_BASE_PATH}`,
139
- authClient: this.authClient as JSONClient,
181
+ authClient,
140
182
  });
141
183
  }
142
184
  return this.aiplatform;
143
185
  }
144
186
 
145
- public getModelGardenClient(): v1beta1.ModelGardenServiceClient {
146
- //Lazy initialisation
187
+ public async getModelGardenClient(): Promise<v1beta1.ModelGardenServiceClient> {
188
+ //Lazy initialization
147
189
  if (!this.modelGarden) {
190
+ const authClient = await this.getAuthClient();
148
191
  this.modelGarden = new v1beta1.ModelGardenServiceClient({
149
192
  projectId: this.options.project,
150
193
  apiEndpoint: `${this.options.region}-${API_BASE_PATH}`,
151
- authClient: this.authClient as JSONClient,
194
+ authClient,
152
195
  });
153
196
  }
154
197
  return this.modelGarden;
155
198
  }
156
199
 
200
+ public async getImagenClient(): Promise<PredictionServiceClient> {
201
+ //Lazy initialization
202
+ if (!this.imagenClient) {
203
+ // TODO: make location configurable, fixed to us-central1 for now
204
+ const authClient = await this.getAuthClient();
205
+ this.imagenClient = new PredictionServiceClient({
206
+ projectId: this.options.project,
207
+ apiEndpoint: `us-central1-${API_BASE_PATH}`,
208
+ authClient,
209
+ });
210
+ }
211
+ return this.imagenClient;
212
+ }
213
+
157
214
  validateResult(result: Completion, options: ExecutionOptions) {
158
215
  // Optionally preprocess the result before validation
159
216
  const modelDef = getModelDefinition(options.model);
@@ -180,29 +237,39 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
180
237
  return getModelDefinition(options.model).createPrompt(this, segments, options);
181
238
  }
182
239
 
183
- async requestTextCompletion(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<Completion<any>> {
240
+ async requestTextCompletion(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<Completion> {
184
241
  return getModelDefinition(options.model).requestTextCompletion(this, prompt, options);
185
242
  }
186
243
  async requestTextCompletionStream(
187
244
  prompt: VertexAIPrompt,
188
245
  options: ExecutionOptions,
189
- ): Promise<AsyncIterable<CompletionChunk>> {
246
+ ): Promise<AsyncIterable<CompletionChunkObject>> {
190
247
  return getModelDefinition(options.model).requestTextCompletionStream(this, prompt, options);
191
248
  }
192
249
 
193
250
  async requestImageGeneration(
194
251
  _prompt: ImagenPrompt,
195
252
  _options: ExecutionOptions,
196
- ): Promise<Completion<ImageGeneration>> {
253
+ ): Promise<Completion> {
197
254
  const splits = _options.model.split("/");
198
255
  const modelName = trimModelName(splits[splits.length - 1]);
199
256
  return new ImagenModelDefinition(modelName).requestImageGeneration(this, _prompt, _options);
200
257
  }
201
258
 
259
+ async getGenAIModelsArray(client: GoogleGenAI): Promise<Model[]> {
260
+ const models: Model[] = [];
261
+ const pager = await client.models.list();
262
+ for await (const item of pager) {
263
+ models.push(item);
264
+ }
265
+ return models;
266
+ }
267
+
202
268
  async listModels(_params?: ModelSearchPayload): Promise<AIModel<string>[]> {
203
269
  // Get clients
204
- const modelGarden = this.getModelGardenClient();
205
- const aiplatform = this.getAIPlatformClient();
270
+ const modelGarden = await this.getModelGardenClient();
271
+ const aiplatform = await this.getAIPlatformClient();
272
+ const globalGenAiClient = this.getGoogleGenAIClient("global");
206
273
 
207
274
  let models: AIModel<string>[] = [];
208
275
 
@@ -241,16 +308,19 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
241
308
  parent: `projects/${this.options.project}/locations/${this.options.region}`,
242
309
  });
243
310
  const publisherPromises = publishers.map(async (publisher) => {
244
- let [response] = await modelGarden.listPublisherModels({
311
+ const [response] = await modelGarden.listPublisherModels({
245
312
  parent: `publishers/${publisher}`,
246
313
  orderBy: "name",
247
314
  listAllVersions: true,
248
315
  });
249
316
  return { publisher, response };
250
317
  });
318
+
319
+ const globalGooglePromise = this.getGenAIModelsArray(globalGenAiClient);
251
320
  // Await all network requests
252
- const [aiplatformResult, ...publisherResults] = await Promise.all([
321
+ const [aiplatformResult, globalGoogleResult, ...publisherResults] = await Promise.all([
253
322
  aiplatformPromise,
323
+ globalGooglePromise,
254
324
  ...publisherPromises,
255
325
  ]);
256
326
 
@@ -261,7 +331,23 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
261
331
  id: model.name?.split("/").pop() ?? "",
262
332
  name: model.displayName ?? "",
263
333
  provider: "vertexai"
264
- })),
334
+ }))
335
+ );
336
+
337
+ // Process global google models from GenAI
338
+ models = models.concat(
339
+ globalGoogleResult.map((model) => {
340
+ const modelCapability = getModelCapabilities(model.name ?? '', "vertexai");
341
+ return {
342
+ id: "locations/global/" + model.name,
343
+ name: "Global " + model.name?.split('/').pop(),
344
+ provider: "vertexai",
345
+ owner: "google",
346
+ input_modalities: modelModalitiesToArray(modelCapability.input),
347
+ output_modalities: modelModalitiesToArray(modelCapability.output),
348
+ tool_support: modelCapability.tool_support,
349
+ };
350
+ })
265
351
  );
266
352
 
267
353
  // Process publisher models
@@ -294,6 +380,36 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
294
380
  } satisfies AIModel<string>;
295
381
  }));
296
382
 
383
+ // Create global anthropic models for those not in NON_GLOBAL_ANTHROPIC_MODELS
384
+ if (publisher === 'anthropic') {
385
+ const globalAnthropicModels = response.filter((model) => {
386
+ const modelName = model.name ?? "";
387
+ if (retiredModels.some(retiredModel => modelName.includes(retiredModel))) {
388
+ return false;
389
+ }
390
+ if (modelFamily.some(family => modelName.includes(family))) {
391
+ if (modelName.includes("claude-3-7")) {
392
+ return true;
393
+ }
394
+ return !NON_GLOBAL_ANTHROPIC_MODELS.some(nonGlobalModel => modelName.includes(nonGlobalModel));
395
+ }
396
+ return false;
397
+ }).map(model => {
398
+ const modelCapability = getModelCapabilities(model.name ?? '', "vertexai");
399
+ return {
400
+ id: "locations/global/" + model.name,
401
+ name: "Global " + model.name?.split('/').pop(),
402
+ provider: 'vertexai',
403
+ owner: publisher,
404
+ input_modalities: modelModalitiesToArray(modelCapability.input),
405
+ output_modalities: modelModalitiesToArray(modelCapability.output),
406
+ tool_support: modelCapability.tool_support,
407
+ } satisfies AIModel<string>;
408
+ });
409
+
410
+ models = models.concat(globalAnthropicModels);
411
+ }
412
+
297
413
  // Add additional models that are not in the listing
298
414
  for (const additionalModel of additionalModels[publisher as keyof typeof additionalModels]) {
299
415
  const publisherModelName = `publishers/${publisher}/models/${additionalModel}`;