@ai-sdk/replicate 0.0.1 → 0.0.2
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 +6 -0
- 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
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/replicate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
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