@ai-sdk/replicate 0.0.1 → 0.0.3
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -1
- package/.turbo/turbo-build.log +0 -21
- package/.turbo/turbo-clean.log +0 -4
- package/src/index.ts +0 -5
- package/src/replicate-error.ts +0 -13
- package/src/replicate-image-model.test.ts +0 -177
- package/src/replicate-image-model.ts +0 -104
- package/src/replicate-image-settings.ts +0 -36
- package/src/replicate-provider.test.ts +0 -24
- package/src/replicate-provider.ts +0 -74
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -10
- package/turbo.json +0 -12
- package/vitest.edge.config.js +0 -10
- package/vitest.node.config.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/replicate
|
|
2
2
|
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 218d001: feat (provider): Add maxImagesPerCall setting to all image providers.
|
|
8
|
+
|
|
9
|
+
## 0.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 33b28df: feat (provider/replicate): Fix api key name typo, add package metadata/files config.
|
|
14
|
+
|
|
3
15
|
## 0.0.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -16,10 +16,10 @@ interface ReplicateImageModelConfig {
|
|
|
16
16
|
fetch?: FetchFunction;
|
|
17
17
|
}
|
|
18
18
|
declare class ReplicateImageModel implements ImageModelV1 {
|
|
19
|
-
readonly specificationVersion = "v1";
|
|
20
19
|
readonly modelId: ReplicateImageModelId;
|
|
21
|
-
readonly settings
|
|
20
|
+
private readonly settings;
|
|
22
21
|
private readonly config;
|
|
22
|
+
readonly specificationVersion = "v1";
|
|
23
23
|
get provider(): string;
|
|
24
24
|
get maxImagesPerCall(): number;
|
|
25
25
|
constructor(modelId: ReplicateImageModelId, settings: ReplicateImageSettings, config: ReplicateImageModelConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -16,10 +16,10 @@ interface ReplicateImageModelConfig {
|
|
|
16
16
|
fetch?: FetchFunction;
|
|
17
17
|
}
|
|
18
18
|
declare class ReplicateImageModel implements ImageModelV1 {
|
|
19
|
-
readonly specificationVersion = "v1";
|
|
20
19
|
readonly modelId: ReplicateImageModelId;
|
|
21
|
-
readonly settings
|
|
20
|
+
private readonly settings;
|
|
22
21
|
private readonly config;
|
|
22
|
+
readonly specificationVersion = "v1";
|
|
23
23
|
get provider(): string;
|
|
24
24
|
get maxImagesPerCall(): number;
|
|
25
25
|
constructor(modelId: ReplicateImageModelId, settings: ReplicateImageSettings, config: ReplicateImageModelConfig);
|
package/dist/index.js
CHANGED
|
@@ -50,10 +50,10 @@ var replicateFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
50
50
|
// src/replicate-image-model.ts
|
|
51
51
|
var ReplicateImageModel = class {
|
|
52
52
|
constructor(modelId, settings, config) {
|
|
53
|
-
this.specificationVersion = "v1";
|
|
54
53
|
this.modelId = modelId;
|
|
55
54
|
this.settings = settings;
|
|
56
55
|
this.config = config;
|
|
56
|
+
this.specificationVersion = "v1";
|
|
57
57
|
}
|
|
58
58
|
get provider() {
|
|
59
59
|
return this.config.provider;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/replicate-provider.ts","../src/replicate-image-model.ts","../src/replicate-error.ts"],"sourcesContent":["export { createReplicate, replicate } from './replicate-provider';\nexport type {\n ReplicateProvider,\n ReplicateProviderSettings,\n} from './replicate-provider';\n","import type { FetchFunction } from '@ai-sdk/provider-utils';\nimport { loadApiKey } from '@ai-sdk/provider-utils';\nimport { ReplicateImageModel } from './replicate-image-model';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\nexport interface ReplicateProviderSettings {\n /**\nAPI token that is being send using the `Authorization` header.\nIt defaults to the `REPLICATE_API_TOKEN` environment variable.\n */\n apiToken?: string;\n\n /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.replicate.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface ReplicateProvider {\n /**\n * Creates a Replicate image generation model.\n */\n image(\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ): ReplicateImageModel;\n}\n\n/**\n * Create a Replicate provider instance.\n */\nexport function createReplicate(\n options: ReplicateProviderSettings = {},\n): ReplicateProvider {\n return {\n image: (\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ) =>\n new ReplicateImageModel(modelId, settings ?? {}, {\n provider: 'replicate',\n baseURL: options.baseURL ?? 'https://api.replicate.com/v1',\n headers: {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiToken,\n environmentVariableName: 'REPLICATE_API_TOKEN',\n description: 'Replicate',\n })}`,\n ...options.headers,\n },\n fetch: options.fetch,\n }),\n };\n}\n\n/**\n * Default Replicate provider instance.\n */\nexport const replicate = createReplicate();\n","import type { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';\nimport type { Resolvable } from '@ai-sdk/provider-utils';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonResponseHandler,\n postJsonToApi,\n resolve,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod';\nimport { replicateFailedResponseHandler } from './replicate-error';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\ninterface ReplicateImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n}\n\nexport class ReplicateImageModel implements ImageModelV1 {\n readonly specificationVersion = 'v1';\n\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/replicate-provider.ts","../src/replicate-image-model.ts","../src/replicate-error.ts"],"sourcesContent":["export { createReplicate, replicate } from './replicate-provider';\nexport type {\n ReplicateProvider,\n ReplicateProviderSettings,\n} from './replicate-provider';\n","import type { FetchFunction } from '@ai-sdk/provider-utils';\nimport { loadApiKey } from '@ai-sdk/provider-utils';\nimport { ReplicateImageModel } from './replicate-image-model';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\nexport interface ReplicateProviderSettings {\n /**\nAPI token that is being send using the `Authorization` header.\nIt defaults to the `REPLICATE_API_TOKEN` environment variable.\n */\n apiToken?: string;\n\n /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.replicate.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface ReplicateProvider {\n /**\n * Creates a Replicate image generation model.\n */\n image(\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ): ReplicateImageModel;\n}\n\n/**\n * Create a Replicate provider instance.\n */\nexport function createReplicate(\n options: ReplicateProviderSettings = {},\n): ReplicateProvider {\n return {\n image: (\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ) =>\n new ReplicateImageModel(modelId, settings ?? {}, {\n provider: 'replicate',\n baseURL: options.baseURL ?? 'https://api.replicate.com/v1',\n headers: {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiToken,\n environmentVariableName: 'REPLICATE_API_TOKEN',\n description: 'Replicate',\n })}`,\n ...options.headers,\n },\n fetch: options.fetch,\n }),\n };\n}\n\n/**\n * Default Replicate provider instance.\n */\nexport const replicate = createReplicate();\n","import type { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';\nimport type { Resolvable } from '@ai-sdk/provider-utils';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonResponseHandler,\n postJsonToApi,\n resolve,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod';\nimport { replicateFailedResponseHandler } from './replicate-error';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\ninterface ReplicateImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n}\n\nexport class ReplicateImageModel implements ImageModelV1 {\n readonly specificationVersion = 'v1';\n\n get provider(): string {\n return this.config.provider;\n }\n\n get maxImagesPerCall(): number {\n return this.settings.maxImagesPerCall ?? 1;\n }\n\n constructor(\n readonly modelId: ReplicateImageModelId,\n private readonly settings: ReplicateImageSettings,\n private readonly config: ReplicateImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n aspectRatio,\n size,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV1['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV1['doGenerate']>>\n > {\n const warnings: Array<ImageModelV1CallWarning> = [];\n\n const {\n value: { output },\n } = await postJsonToApi({\n url: `${this.config.baseURL}/models/${this.modelId}/predictions`,\n headers: combineHeaders(await resolve(this.config.headers), headers, {\n prefer: 'wait',\n }),\n body: {\n input: {\n prompt,\n aspect_ratio: aspectRatio,\n size,\n seed,\n num_outputs: n,\n ...(providerOptions.replicate ?? {}),\n },\n },\n failedResponseHandler: replicateFailedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n replicateImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n // download the images:\n const outputArray = Array.isArray(output) ? output : [output];\n const images = await Promise.all(\n outputArray.map(async url => {\n const response = await fetch(url);\n return new Uint8Array(await response.arrayBuffer());\n }),\n );\n\n return { images, warnings };\n }\n}\n\nconst replicateImageResponseSchema = z.object({\n output: z.union([z.array(z.string()), z.string()]),\n});\n","import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\nimport { z } from 'zod';\n\nconst replicateErrorSchema = z.object({\n detail: z.string().optional(),\n error: z.string().optional(),\n});\n\nexport const replicateFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: replicateErrorSchema,\n errorToMessage: error =>\n error.detail ?? error.error ?? 'Unknown Replicate error',\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,yBAA2B;;;ACC3B,IAAAC,yBAMO;AACP,IAAAC,cAAkB;;;ACTlB,4BAA+C;AAC/C,iBAAkB;AAElB,IAAM,uBAAuB,aAAE,OAAO;AAAA,EACpC,QAAQ,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,OAAO,aAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAEM,IAAM,qCAAiC,sDAA+B;AAAA,EAC3E,aAAa;AAAA,EACb,gBAAgB,WAAM;AAVxB;AAWI,6BAAM,WAAN,YAAgB,MAAM,UAAtB,YAA+B;AAAA;AACnC,CAAC;;;ADWM,IAAM,sBAAN,MAAkD;AAAA,EAWvD,YACW,SACQ,UACA,QACjB;AAHS;AACQ;AACA;AAbnB,SAAS,uBAAuB;AAAA,EAc7B;AAAA,EAZH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,mBAA2B;AA9BjC;AA+BI,YAAO,UAAK,SAAS,qBAAd,YAAkC;AAAA,EAC3C;AAAA,EAQA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AAnDJ;AAoDI,UAAM,WAA2C,CAAC;AAElD,UAAM;AAAA,MACJ,OAAO,EAAE,OAAO;AAAA,IAClB,IAAI,UAAM,sCAAc;AAAA,MACtB,KAAK,GAAG,KAAK,OAAO,OAAO,WAAW,KAAK,OAAO;AAAA,MAClD,aAAS,uCAAe,UAAM,gCAAQ,KAAK,OAAO,OAAO,GAAG,SAAS;AAAA,QACnE,QAAQ;AAAA,MACV,CAAC;AAAA,MACD,MAAM;AAAA,QACJ,OAAO;AAAA,UACL;AAAA,UACA,cAAc;AAAA,UACd;AAAA,UACA;AAAA,UACA,aAAa;AAAA,UACb,IAAI,qBAAgB,cAAhB,YAA6B,CAAC;AAAA,QACpC;AAAA,MACF;AAAA,MACA,uBAAuB;AAAA,MACvB,+BAA2B;AAAA,QACzB;AAAA,MACF;AAAA,MACA;AAAA,MACA,OAAO,KAAK,OAAO;AAAA,IACrB,CAAC;AAGD,UAAM,cAAc,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAC5D,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B,YAAY,IAAI,OAAM,QAAO;AAC3B,cAAM,WAAW,MAAM,MAAM,GAAG;AAChC,eAAO,IAAI,WAAW,MAAM,SAAS,YAAY,CAAC;AAAA,MACpD,CAAC;AAAA,IACH;AAEA,WAAO,EAAE,QAAQ,SAAS;AAAA,EAC5B;AACF;AAEA,IAAM,+BAA+B,cAAE,OAAO;AAAA,EAC5C,QAAQ,cAAE,MAAM,CAAC,cAAE,MAAM,cAAE,OAAO,CAAC,GAAG,cAAE,OAAO,CAAC,CAAC;AACnD,CAAC;;;ADhDM,SAAS,gBACd,UAAqC,CAAC,GACnB;AACnB,SAAO;AAAA,IACL,OAAO,CACL,SACA,aACA;AArDN;AAsDM,iBAAI,oBAAoB,SAAS,8BAAY,CAAC,GAAG;AAAA,QAC/C,UAAU;AAAA,QACV,UAAS,aAAQ,YAAR,YAAmB;AAAA,QAC5B,SAAS;AAAA,UACP,eAAe,cAAU,mCAAW;AAAA,YAClC,QAAQ,QAAQ;AAAA,YAChB,yBAAyB;AAAA,YACzB,aAAa;AAAA,UACf,CAAC,CAAC;AAAA,UACF,GAAG,QAAQ;AAAA,QACb;AAAA,QACA,OAAO,QAAQ;AAAA,MACjB,CAAC;AAAA;AAAA,EACL;AACF;AAKO,IAAM,YAAY,gBAAgB;","names":["import_provider_utils","import_provider_utils","import_zod"]}
|
package/dist/index.mjs
CHANGED
|
@@ -28,10 +28,10 @@ var replicateFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
28
28
|
// src/replicate-image-model.ts
|
|
29
29
|
var ReplicateImageModel = class {
|
|
30
30
|
constructor(modelId, settings, config) {
|
|
31
|
-
this.specificationVersion = "v1";
|
|
32
31
|
this.modelId = modelId;
|
|
33
32
|
this.settings = settings;
|
|
34
33
|
this.config = config;
|
|
34
|
+
this.specificationVersion = "v1";
|
|
35
35
|
}
|
|
36
36
|
get provider() {
|
|
37
37
|
return this.config.provider;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/replicate-provider.ts","../src/replicate-image-model.ts","../src/replicate-error.ts"],"sourcesContent":["import type { FetchFunction } from '@ai-sdk/provider-utils';\nimport { loadApiKey } from '@ai-sdk/provider-utils';\nimport { ReplicateImageModel } from './replicate-image-model';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\nexport interface ReplicateProviderSettings {\n /**\nAPI token that is being send using the `Authorization` header.\nIt defaults to the `REPLICATE_API_TOKEN` environment variable.\n */\n apiToken?: string;\n\n /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.replicate.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface ReplicateProvider {\n /**\n * Creates a Replicate image generation model.\n */\n image(\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ): ReplicateImageModel;\n}\n\n/**\n * Create a Replicate provider instance.\n */\nexport function createReplicate(\n options: ReplicateProviderSettings = {},\n): ReplicateProvider {\n return {\n image: (\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ) =>\n new ReplicateImageModel(modelId, settings ?? {}, {\n provider: 'replicate',\n baseURL: options.baseURL ?? 'https://api.replicate.com/v1',\n headers: {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiToken,\n environmentVariableName: 'REPLICATE_API_TOKEN',\n description: 'Replicate',\n })}`,\n ...options.headers,\n },\n fetch: options.fetch,\n }),\n };\n}\n\n/**\n * Default Replicate provider instance.\n */\nexport const replicate = createReplicate();\n","import type { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';\nimport type { Resolvable } from '@ai-sdk/provider-utils';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonResponseHandler,\n postJsonToApi,\n resolve,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod';\nimport { replicateFailedResponseHandler } from './replicate-error';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\ninterface ReplicateImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n}\n\nexport class ReplicateImageModel implements ImageModelV1 {\n readonly specificationVersion = 'v1';\n\n
|
|
1
|
+
{"version":3,"sources":["../src/replicate-provider.ts","../src/replicate-image-model.ts","../src/replicate-error.ts"],"sourcesContent":["import type { FetchFunction } from '@ai-sdk/provider-utils';\nimport { loadApiKey } from '@ai-sdk/provider-utils';\nimport { ReplicateImageModel } from './replicate-image-model';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\nexport interface ReplicateProviderSettings {\n /**\nAPI token that is being send using the `Authorization` header.\nIt defaults to the `REPLICATE_API_TOKEN` environment variable.\n */\n apiToken?: string;\n\n /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.replicate.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface ReplicateProvider {\n /**\n * Creates a Replicate image generation model.\n */\n image(\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ): ReplicateImageModel;\n}\n\n/**\n * Create a Replicate provider instance.\n */\nexport function createReplicate(\n options: ReplicateProviderSettings = {},\n): ReplicateProvider {\n return {\n image: (\n modelId: ReplicateImageModelId,\n settings?: ReplicateImageSettings,\n ) =>\n new ReplicateImageModel(modelId, settings ?? {}, {\n provider: 'replicate',\n baseURL: options.baseURL ?? 'https://api.replicate.com/v1',\n headers: {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiToken,\n environmentVariableName: 'REPLICATE_API_TOKEN',\n description: 'Replicate',\n })}`,\n ...options.headers,\n },\n fetch: options.fetch,\n }),\n };\n}\n\n/**\n * Default Replicate provider instance.\n */\nexport const replicate = createReplicate();\n","import type { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';\nimport type { Resolvable } from '@ai-sdk/provider-utils';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonResponseHandler,\n postJsonToApi,\n resolve,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod';\nimport { replicateFailedResponseHandler } from './replicate-error';\nimport {\n ReplicateImageModelId,\n ReplicateImageSettings,\n} from './replicate-image-settings';\n\ninterface ReplicateImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n}\n\nexport class ReplicateImageModel implements ImageModelV1 {\n readonly specificationVersion = 'v1';\n\n get provider(): string {\n return this.config.provider;\n }\n\n get maxImagesPerCall(): number {\n return this.settings.maxImagesPerCall ?? 1;\n }\n\n constructor(\n readonly modelId: ReplicateImageModelId,\n private readonly settings: ReplicateImageSettings,\n private readonly config: ReplicateImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n aspectRatio,\n size,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV1['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV1['doGenerate']>>\n > {\n const warnings: Array<ImageModelV1CallWarning> = [];\n\n const {\n value: { output },\n } = await postJsonToApi({\n url: `${this.config.baseURL}/models/${this.modelId}/predictions`,\n headers: combineHeaders(await resolve(this.config.headers), headers, {\n prefer: 'wait',\n }),\n body: {\n input: {\n prompt,\n aspect_ratio: aspectRatio,\n size,\n seed,\n num_outputs: n,\n ...(providerOptions.replicate ?? {}),\n },\n },\n failedResponseHandler: replicateFailedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n replicateImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n // download the images:\n const outputArray = Array.isArray(output) ? output : [output];\n const images = await Promise.all(\n outputArray.map(async url => {\n const response = await fetch(url);\n return new Uint8Array(await response.arrayBuffer());\n }),\n );\n\n return { images, warnings };\n }\n}\n\nconst replicateImageResponseSchema = z.object({\n output: z.union([z.array(z.string()), z.string()]),\n});\n","import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';\nimport { z } from 'zod';\n\nconst replicateErrorSchema = z.object({\n detail: z.string().optional(),\n error: z.string().optional(),\n});\n\nexport const replicateFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: replicateErrorSchema,\n errorToMessage: error =>\n error.detail ?? error.error ?? 'Unknown Replicate error',\n});\n"],"mappings":";AACA,SAAS,kBAAkB;;;ACC3B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,KAAAA,UAAS;;;ACTlB,SAAS,sCAAsC;AAC/C,SAAS,SAAS;AAElB,IAAM,uBAAuB,EAAE,OAAO;AAAA,EACpC,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,OAAO,EAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAEM,IAAM,iCAAiC,+BAA+B;AAAA,EAC3E,aAAa;AAAA,EACb,gBAAgB,WAAM;AAVxB;AAWI,6BAAM,WAAN,YAAgB,MAAM,UAAtB,YAA+B;AAAA;AACnC,CAAC;;;ADWM,IAAM,sBAAN,MAAkD;AAAA,EAWvD,YACW,SACQ,UACA,QACjB;AAHS;AACQ;AACA;AAbnB,SAAS,uBAAuB;AAAA,EAc7B;AAAA,EAZH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,mBAA2B;AA9BjC;AA+BI,YAAO,UAAK,SAAS,qBAAd,YAAkC;AAAA,EAC3C;AAAA,EAQA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AAnDJ;AAoDI,UAAM,WAA2C,CAAC;AAElD,UAAM;AAAA,MACJ,OAAO,EAAE,OAAO;AAAA,IAClB,IAAI,MAAM,cAAc;AAAA,MACtB,KAAK,GAAG,KAAK,OAAO,OAAO,WAAW,KAAK,OAAO;AAAA,MAClD,SAAS,eAAe,MAAM,QAAQ,KAAK,OAAO,OAAO,GAAG,SAAS;AAAA,QACnE,QAAQ;AAAA,MACV,CAAC;AAAA,MACD,MAAM;AAAA,QACJ,OAAO;AAAA,UACL;AAAA,UACA,cAAc;AAAA,UACd;AAAA,UACA;AAAA,UACA,aAAa;AAAA,UACb,IAAI,qBAAgB,cAAhB,YAA6B,CAAC;AAAA,QACpC;AAAA,MACF;AAAA,MACA,uBAAuB;AAAA,MACvB,2BAA2B;AAAA,QACzB;AAAA,MACF;AAAA,MACA;AAAA,MACA,OAAO,KAAK,OAAO;AAAA,IACrB,CAAC;AAGD,UAAM,cAAc,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAC5D,UAAM,SAAS,MAAM,QAAQ;AAAA,MAC3B,YAAY,IAAI,OAAM,QAAO;AAC3B,cAAM,WAAW,MAAM,MAAM,GAAG;AAChC,eAAO,IAAI,WAAW,MAAM,SAAS,YAAY,CAAC;AAAA,MACpD,CAAC;AAAA,IACH;AAEA,WAAO,EAAE,QAAQ,SAAS;AAAA,EAC5B;AACF;AAEA,IAAM,+BAA+BC,GAAE,OAAO;AAAA,EAC5C,QAAQA,GAAE,MAAM,CAACA,GAAE,MAAMA,GAAE,OAAO,CAAC,GAAGA,GAAE,OAAO,CAAC,CAAC;AACnD,CAAC;;;ADhDM,SAAS,gBACd,UAAqC,CAAC,GACnB;AACnB,SAAO;AAAA,IACL,OAAO,CACL,SACA,aACA;AArDN;AAsDM,iBAAI,oBAAoB,SAAS,8BAAY,CAAC,GAAG;AAAA,QAC/C,UAAU;AAAA,QACV,UAAS,aAAQ,YAAR,YAAmB;AAAA,QAC5B,SAAS;AAAA,UACP,eAAe,UAAU,WAAW;AAAA,YAClC,QAAQ,QAAQ;AAAA,YAChB,yBAAyB;AAAA,YACzB,aAAa;AAAA,UACf,CAAC,CAAC;AAAA,UACF,GAAG,QAAQ;AAAA,QACb;AAAA,QACA,OAAO,QAAQ;AAAA,MACjB,CAAC;AAAA;AAAA,EACL;AACF;AAKO,IAAM,YAAY,gBAAgB;","names":["z","z"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/replicate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*",
|
|
11
|
+
"CHANGELOG.md"
|
|
12
|
+
],
|
|
9
13
|
"exports": {
|
|
10
14
|
"./package.json": "./package.json",
|
|
11
15
|
".": {
|
|
@@ -34,6 +38,17 @@
|
|
|
34
38
|
"publishConfig": {
|
|
35
39
|
"access": "public"
|
|
36
40
|
},
|
|
41
|
+
"homepage": "https://sdk.vercel.ai/docs",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/vercel/ai.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/vercel/ai/issues"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"ai"
|
|
51
|
+
],
|
|
37
52
|
"scripts": {
|
|
38
53
|
"build": "tsup",
|
|
39
54
|
"build:watch": "tsup --watch",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @ai-sdk/replicate@0.0.1 build /home/runner/work/ai/ai/packages/replicate
|
|
3
|
-
> tsup
|
|
4
|
-
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.3.0
|
|
8
|
-
[34mCLI[39m Using tsup config: /home/runner/work/ai/ai/packages/replicate/tsup.config.ts
|
|
9
|
-
[34mCLI[39m Target: es2018
|
|
10
|
-
[34mCJS[39m Build start
|
|
11
|
-
[34mESM[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m3.13 KB[39m
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[32m7.22 KB[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in 74ms
|
|
15
|
-
[32mCJS[39m [1mdist/index.js [22m[32m4.37 KB[39m
|
|
16
|
-
[32mCJS[39m [1mdist/index.js.map [22m[32m7.46 KB[39m
|
|
17
|
-
[32mCJS[39m ⚡️ Build success in 88ms
|
|
18
|
-
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in 18826ms
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.08 KB[39m
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.08 KB[39m
|
package/.turbo/turbo-clean.log
DELETED
package/src/index.ts
DELETED
package/src/replicate-error.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
const replicateErrorSchema = z.object({
|
|
5
|
-
detail: z.string().optional(),
|
|
6
|
-
error: z.string().optional(),
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export const replicateFailedResponseHandler = createJsonErrorResponseHandler({
|
|
10
|
-
errorSchema: replicateErrorSchema,
|
|
11
|
-
errorToMessage: error =>
|
|
12
|
-
error.detail ?? error.error ?? 'Unknown Replicate error',
|
|
13
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { createTestServer } from '@ai-sdk/provider-utils/test';
|
|
2
|
-
import { createReplicate } from './replicate-provider';
|
|
3
|
-
|
|
4
|
-
const prompt = 'The Loch Ness monster getting a manicure';
|
|
5
|
-
|
|
6
|
-
const provider = createReplicate({ apiToken: 'test-api-token' });
|
|
7
|
-
const model = provider.image('black-forest-labs/flux-schnell');
|
|
8
|
-
|
|
9
|
-
describe('doGenerate', () => {
|
|
10
|
-
const server = createTestServer({
|
|
11
|
-
'https://api.replicate.com/*': {},
|
|
12
|
-
'https://replicate.delivery/*': {
|
|
13
|
-
response: {
|
|
14
|
-
type: 'binary',
|
|
15
|
-
body: Buffer.from('test-binary-content'),
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
function prepareResponse({
|
|
21
|
-
output = ['https://replicate.delivery/xezq/abc/out-0.webp'],
|
|
22
|
-
}: { output?: string | Array<string> } = {}) {
|
|
23
|
-
server.urls['https://api.replicate.com/*'].response = {
|
|
24
|
-
type: 'json-value',
|
|
25
|
-
body: {
|
|
26
|
-
id: 's7x1e3dcmhrmc0cm8rbatcneec',
|
|
27
|
-
model: 'black-forest-labs/flux-schnell',
|
|
28
|
-
version: 'dp-4d0bcc010b3049749a251855f12800be',
|
|
29
|
-
input: {
|
|
30
|
-
num_outputs: 1,
|
|
31
|
-
prompt: 'The Loch Ness Monster getting a manicure',
|
|
32
|
-
},
|
|
33
|
-
logs: '',
|
|
34
|
-
output,
|
|
35
|
-
data_removed: false,
|
|
36
|
-
error: null,
|
|
37
|
-
status: 'processing',
|
|
38
|
-
created_at: '2025-01-08T13:24:38.692Z',
|
|
39
|
-
urls: {
|
|
40
|
-
cancel:
|
|
41
|
-
'https://api.replicate.com/v1/predictions/s7x1e3dcmhrmc0cm8rbatcneec/cancel',
|
|
42
|
-
get: 'https://api.replicate.com/v1/predictions/s7x1e3dcmhrmc0cm8rbatcneec',
|
|
43
|
-
stream:
|
|
44
|
-
'https://stream.replicate.com/v1/files/bcwr-3okdfv3o2wehstv5f2okyftwxy57hhypqsi6osiim5iaq5k7u24a',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
it('should pass the model and the settings', async () => {
|
|
51
|
-
prepareResponse();
|
|
52
|
-
|
|
53
|
-
await model.doGenerate({
|
|
54
|
-
prompt,
|
|
55
|
-
n: 1,
|
|
56
|
-
size: '1024x768',
|
|
57
|
-
aspectRatio: '3:4',
|
|
58
|
-
seed: 123,
|
|
59
|
-
providerOptions: {
|
|
60
|
-
replicate: {
|
|
61
|
-
style: 'realistic_image',
|
|
62
|
-
},
|
|
63
|
-
other: {
|
|
64
|
-
something: 'else',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(await server.calls[0].requestBody).toStrictEqual({
|
|
70
|
-
input: {
|
|
71
|
-
prompt,
|
|
72
|
-
num_outputs: 1,
|
|
73
|
-
aspect_ratio: '3:4',
|
|
74
|
-
size: '1024x768',
|
|
75
|
-
seed: 123,
|
|
76
|
-
style: 'realistic_image',
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should call the correct url', async () => {
|
|
82
|
-
prepareResponse();
|
|
83
|
-
|
|
84
|
-
await model.doGenerate({
|
|
85
|
-
prompt,
|
|
86
|
-
n: 1,
|
|
87
|
-
size: undefined,
|
|
88
|
-
aspectRatio: undefined,
|
|
89
|
-
seed: undefined,
|
|
90
|
-
providerOptions: {},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(server.calls[0].requestMethod).toStrictEqual('POST');
|
|
94
|
-
expect(server.calls[0].requestUrl).toStrictEqual(
|
|
95
|
-
'https://api.replicate.com/v1/models/black-forest-labs/flux-schnell/predictions',
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should pass headers and set the prefer header', async () => {
|
|
100
|
-
prepareResponse();
|
|
101
|
-
|
|
102
|
-
const provider = createReplicate({
|
|
103
|
-
apiToken: 'test-api-token',
|
|
104
|
-
headers: {
|
|
105
|
-
'Custom-Provider-Header': 'provider-header-value',
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
await provider.image('black-forest-labs/flux-schnell').doGenerate({
|
|
110
|
-
prompt,
|
|
111
|
-
n: 1,
|
|
112
|
-
size: undefined,
|
|
113
|
-
aspectRatio: undefined,
|
|
114
|
-
seed: undefined,
|
|
115
|
-
providerOptions: {},
|
|
116
|
-
headers: {
|
|
117
|
-
'Custom-Request-Header': 'request-header-value',
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
expect(server.calls[0].requestHeaders).toStrictEqual({
|
|
122
|
-
authorization: 'Bearer test-api-token',
|
|
123
|
-
'content-type': 'application/json',
|
|
124
|
-
'custom-provider-header': 'provider-header-value',
|
|
125
|
-
'custom-request-header': 'request-header-value',
|
|
126
|
-
prefer: 'wait',
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should extract the generated image from array response', async () => {
|
|
131
|
-
prepareResponse({
|
|
132
|
-
output: ['https://replicate.delivery/xezq/abc/out-0.webp'],
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const result = await model.doGenerate({
|
|
136
|
-
prompt,
|
|
137
|
-
n: 1,
|
|
138
|
-
size: undefined,
|
|
139
|
-
aspectRatio: undefined,
|
|
140
|
-
seed: undefined,
|
|
141
|
-
providerOptions: {},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
expect(result.images).toStrictEqual([
|
|
145
|
-
new Uint8Array(Buffer.from('test-binary-content')),
|
|
146
|
-
]);
|
|
147
|
-
|
|
148
|
-
expect(server.calls[1].requestMethod).toStrictEqual('GET');
|
|
149
|
-
expect(server.calls[1].requestUrl).toStrictEqual(
|
|
150
|
-
'https://replicate.delivery/xezq/abc/out-0.webp',
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('should extract the generated image from string response', async () => {
|
|
155
|
-
prepareResponse({
|
|
156
|
-
output: 'https://replicate.delivery/xezq/abc/out-0.webp',
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const result = await model.doGenerate({
|
|
160
|
-
prompt,
|
|
161
|
-
n: 1,
|
|
162
|
-
size: undefined,
|
|
163
|
-
aspectRatio: undefined,
|
|
164
|
-
seed: undefined,
|
|
165
|
-
providerOptions: {},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
expect(result.images).toStrictEqual([
|
|
169
|
-
new Uint8Array(Buffer.from('test-binary-content')),
|
|
170
|
-
]);
|
|
171
|
-
|
|
172
|
-
expect(server.calls[1].requestMethod).toStrictEqual('GET');
|
|
173
|
-
expect(server.calls[1].requestUrl).toStrictEqual(
|
|
174
|
-
'https://replicate.delivery/xezq/abc/out-0.webp',
|
|
175
|
-
);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';
|
|
2
|
-
import type { Resolvable } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
4
|
-
FetchFunction,
|
|
5
|
-
combineHeaders,
|
|
6
|
-
createJsonResponseHandler,
|
|
7
|
-
postJsonToApi,
|
|
8
|
-
resolve,
|
|
9
|
-
} from '@ai-sdk/provider-utils';
|
|
10
|
-
import { z } from 'zod';
|
|
11
|
-
import { replicateFailedResponseHandler } from './replicate-error';
|
|
12
|
-
import {
|
|
13
|
-
ReplicateImageModelId,
|
|
14
|
-
ReplicateImageSettings,
|
|
15
|
-
} from './replicate-image-settings';
|
|
16
|
-
|
|
17
|
-
interface ReplicateImageModelConfig {
|
|
18
|
-
provider: string;
|
|
19
|
-
baseURL: string;
|
|
20
|
-
headers?: Resolvable<Record<string, string | undefined>>;
|
|
21
|
-
fetch?: FetchFunction;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class ReplicateImageModel implements ImageModelV1 {
|
|
25
|
-
readonly specificationVersion = 'v1';
|
|
26
|
-
|
|
27
|
-
readonly modelId: ReplicateImageModelId;
|
|
28
|
-
readonly settings: ReplicateImageSettings;
|
|
29
|
-
|
|
30
|
-
private readonly config: ReplicateImageModelConfig;
|
|
31
|
-
|
|
32
|
-
get provider(): string {
|
|
33
|
-
return this.config.provider;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get maxImagesPerCall(): number {
|
|
37
|
-
return this.settings.maxImagesPerCall ?? 1;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
constructor(
|
|
41
|
-
modelId: ReplicateImageModelId,
|
|
42
|
-
settings: ReplicateImageSettings,
|
|
43
|
-
config: ReplicateImageModelConfig,
|
|
44
|
-
) {
|
|
45
|
-
this.modelId = modelId;
|
|
46
|
-
this.settings = settings;
|
|
47
|
-
this.config = config;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async doGenerate({
|
|
51
|
-
prompt,
|
|
52
|
-
n,
|
|
53
|
-
aspectRatio,
|
|
54
|
-
size,
|
|
55
|
-
seed,
|
|
56
|
-
providerOptions,
|
|
57
|
-
headers,
|
|
58
|
-
abortSignal,
|
|
59
|
-
}: Parameters<ImageModelV1['doGenerate']>[0]): Promise<
|
|
60
|
-
Awaited<ReturnType<ImageModelV1['doGenerate']>>
|
|
61
|
-
> {
|
|
62
|
-
const warnings: Array<ImageModelV1CallWarning> = [];
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
value: { output },
|
|
66
|
-
} = await postJsonToApi({
|
|
67
|
-
url: `${this.config.baseURL}/models/${this.modelId}/predictions`,
|
|
68
|
-
headers: combineHeaders(await resolve(this.config.headers), headers, {
|
|
69
|
-
prefer: 'wait',
|
|
70
|
-
}),
|
|
71
|
-
body: {
|
|
72
|
-
input: {
|
|
73
|
-
prompt,
|
|
74
|
-
aspect_ratio: aspectRatio,
|
|
75
|
-
size,
|
|
76
|
-
seed,
|
|
77
|
-
num_outputs: n,
|
|
78
|
-
...(providerOptions.replicate ?? {}),
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
failedResponseHandler: replicateFailedResponseHandler,
|
|
82
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
83
|
-
replicateImageResponseSchema,
|
|
84
|
-
),
|
|
85
|
-
abortSignal,
|
|
86
|
-
fetch: this.config.fetch,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// download the images:
|
|
90
|
-
const outputArray = Array.isArray(output) ? output : [output];
|
|
91
|
-
const images = await Promise.all(
|
|
92
|
-
outputArray.map(async url => {
|
|
93
|
-
const response = await fetch(url);
|
|
94
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
95
|
-
}),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return { images, warnings };
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const replicateImageResponseSchema = z.object({
|
|
103
|
-
output: z.union([z.array(z.string()), z.string()]),
|
|
104
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export type ReplicateImageModelId =
|
|
2
|
-
| 'black-forest-labs/flux-1.1-pro'
|
|
3
|
-
| 'black-forest-labs/flux-1.1-pro-ultra'
|
|
4
|
-
| 'black-forest-labs/flux-dev'
|
|
5
|
-
| 'black-forest-labs/flux-pro'
|
|
6
|
-
| 'black-forest-labs/flux-schnell'
|
|
7
|
-
| 'bytedance/sdxl-lightning-4step'
|
|
8
|
-
| 'fofr/aura-flow'
|
|
9
|
-
| 'fofr/latent-consistency-model'
|
|
10
|
-
| 'fofr/realvisxl-v3-multi-controlnet-lora'
|
|
11
|
-
| 'fofr/sdxl-emoji'
|
|
12
|
-
| 'fofr/sdxl-multi-controlnet-lora'
|
|
13
|
-
| 'ideogram-ai/ideogram-v2'
|
|
14
|
-
| 'ideogram-ai/ideogram-v2-turbo'
|
|
15
|
-
| 'lucataco/dreamshaper-xl-turbo'
|
|
16
|
-
| 'lucataco/open-dalle-v1.1'
|
|
17
|
-
| 'lucataco/realvisxl-v2.0'
|
|
18
|
-
| 'lucataco/realvisxl2-lcm'
|
|
19
|
-
| 'luma/photon'
|
|
20
|
-
| 'luma/photon-flash'
|
|
21
|
-
| 'nvidia/sana'
|
|
22
|
-
| 'playgroundai/playground-v2.5-1024px-aesthetic'
|
|
23
|
-
| 'recraft-ai/recraft-v3'
|
|
24
|
-
| 'recraft-ai/recraft-v3-svg'
|
|
25
|
-
| 'stability-ai/stable-diffusion-3.5-large'
|
|
26
|
-
| 'stability-ai/stable-diffusion-3.5-large-turbo'
|
|
27
|
-
| 'stability-ai/stable-diffusion-3.5-medium'
|
|
28
|
-
| 'tstramer/material-diffusion'
|
|
29
|
-
| (string & {});
|
|
30
|
-
|
|
31
|
-
export interface ReplicateImageSettings {
|
|
32
|
-
/**
|
|
33
|
-
Override the maximum number of images per call (default 1)
|
|
34
|
-
*/
|
|
35
|
-
maxImagesPerCall?: number;
|
|
36
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { createReplicate } from './replicate-provider';
|
|
3
|
-
import { ReplicateImageModel } from './replicate-image-model';
|
|
4
|
-
|
|
5
|
-
describe('createReplicate', () => {
|
|
6
|
-
it('creates a provider with required settings', () => {
|
|
7
|
-
const provider = createReplicate({ apiToken: 'test-token' });
|
|
8
|
-
expect(provider.image).toBeDefined();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('creates a provider with custom settings', () => {
|
|
12
|
-
const provider = createReplicate({
|
|
13
|
-
apiToken: 'test-token',
|
|
14
|
-
baseURL: 'https://custom.replicate.com',
|
|
15
|
-
});
|
|
16
|
-
expect(provider.image).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('creates an image model instance', () => {
|
|
20
|
-
const provider = createReplicate({ apiToken: 'test-token' });
|
|
21
|
-
const model = provider.image('black-forest-labs/flux-schnell');
|
|
22
|
-
expect(model).toBeInstanceOf(ReplicateImageModel);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { loadApiKey } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { ReplicateImageModel } from './replicate-image-model';
|
|
4
|
-
import {
|
|
5
|
-
ReplicateImageModelId,
|
|
6
|
-
ReplicateImageSettings,
|
|
7
|
-
} from './replicate-image-settings';
|
|
8
|
-
|
|
9
|
-
export interface ReplicateProviderSettings {
|
|
10
|
-
/**
|
|
11
|
-
API token that is being send using the `Authorization` header.
|
|
12
|
-
It defaults to the `REPLICATE_API_TOKEN` environment variable.
|
|
13
|
-
*/
|
|
14
|
-
apiToken?: string;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
18
|
-
The default prefix is `https://api.replicate.com/v1`.
|
|
19
|
-
*/
|
|
20
|
-
baseURL?: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
Custom headers to include in the requests.
|
|
24
|
-
*/
|
|
25
|
-
headers?: Record<string, string>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
29
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
30
|
-
*/
|
|
31
|
-
fetch?: FetchFunction;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ReplicateProvider {
|
|
35
|
-
/**
|
|
36
|
-
* Creates a Replicate image generation model.
|
|
37
|
-
*/
|
|
38
|
-
image(
|
|
39
|
-
modelId: ReplicateImageModelId,
|
|
40
|
-
settings?: ReplicateImageSettings,
|
|
41
|
-
): ReplicateImageModel;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Create a Replicate provider instance.
|
|
46
|
-
*/
|
|
47
|
-
export function createReplicate(
|
|
48
|
-
options: ReplicateProviderSettings = {},
|
|
49
|
-
): ReplicateProvider {
|
|
50
|
-
return {
|
|
51
|
-
image: (
|
|
52
|
-
modelId: ReplicateImageModelId,
|
|
53
|
-
settings?: ReplicateImageSettings,
|
|
54
|
-
) =>
|
|
55
|
-
new ReplicateImageModel(modelId, settings ?? {}, {
|
|
56
|
-
provider: 'replicate',
|
|
57
|
-
baseURL: options.baseURL ?? 'https://api.replicate.com/v1',
|
|
58
|
-
headers: {
|
|
59
|
-
Authorization: `Bearer ${loadApiKey({
|
|
60
|
-
apiKey: options.apiToken,
|
|
61
|
-
environmentVariableName: 'REPLICATE_API_TOKEN',
|
|
62
|
-
description: 'Replicate',
|
|
63
|
-
})}`,
|
|
64
|
-
...options.headers,
|
|
65
|
-
},
|
|
66
|
-
fetch: options.fetch,
|
|
67
|
-
}),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Default Replicate provider instance.
|
|
73
|
-
*/
|
|
74
|
-
export const replicate = createReplicate();
|
package/tsconfig.json
DELETED
package/tsup.config.ts
DELETED
package/turbo.json
DELETED
package/vitest.edge.config.js
DELETED