Skip to content

Commit 542f4d9

Browse files
oriolriusclaude
andauthored
✨ feat: Add Replicate image provider
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1c18706 commit 542f4d9

File tree

14 files changed

+628
-12
lines changed

14 files changed

+628
-12
lines changed

packages/fetch-sse/src/__tests__/headers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('headersToRecord', () => {
145145
it('should handle object with special characters in values', () => {
146146
// Arrange
147147
const headersObj = {
148-
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
148+
'authorization': 'Bearer test-token',
149149
'x-special': 'value with spaces and symbols: !@#$%',
150150
};
151151

@@ -154,7 +154,7 @@ describe('headersToRecord', () => {
154154

155155
// Assert
156156
expect(result).toEqual({
157-
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
157+
'authorization': 'Bearer test-token',
158158
'x-special': 'value with spaces and symbols: !@#$%',
159159
});
160160
});

packages/model-bank/src/aiModels/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { default as perplexity } from './perplexity';
4545
import { default as ppio } from './ppio';
4646
import { default as qiniu } from './qiniu';
4747
import { default as qwen } from './qwen';
48+
import { default as replicate } from './replicate';
4849
import { default as sambanova } from './sambanova';
4950
import { default as search1api } from './search1api';
5051
import { default as sensenova } from './sensenova';
@@ -133,6 +134,7 @@ export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({
133134
ppio,
134135
qiniu,
135136
qwen,
137+
replicate,
136138
sambanova,
137139
search1api,
138140
sensenova,
@@ -203,6 +205,7 @@ export { default as perplexity } from './perplexity';
203205
export { default as ppio } from './ppio';
204206
export { default as qiniu } from './qiniu';
205207
export { default as qwen } from './qwen';
208+
export { default as replicate } from './replicate';
206209
export { default as sambanova } from './sambanova';
207210
export { default as search1api } from './search1api';
208211
export { default as sensenova } from './sensenova';
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { AIImageModelCard } from '../types';
2+
3+
// Replicate image models
4+
// https://replicate.com/black-forest-labs
5+
const imageModels: AIImageModelCard[] = [
6+
{
7+
description:
8+
'FLUX 1.1 Pro - Faster, better FLUX Pro with excellent image quality and prompt adherence.',
9+
displayName: 'FLUX 1.1 Pro',
10+
enabled: true,
11+
id: 'black-forest-labs/flux-1.1-pro',
12+
parameters: {
13+
aspectRatio: {
14+
default: '1:1',
15+
enum: ['1:1', '16:9', '9:16', '4:3', '3:4', '21:9', '9:21'],
16+
},
17+
prompt: { default: '' },
18+
seed: { default: null },
19+
},
20+
pricing: {
21+
units: [{ name: 'imageGeneration', rate: 0.04, strategy: 'fixed', unit: 'image' }],
22+
},
23+
releasedAt: '2024-10-02',
24+
type: 'image',
25+
},
26+
{
27+
description: 'FLUX Schnell - Fast image generation model optimized for speed.',
28+
displayName: 'FLUX Schnell',
29+
enabled: true,
30+
id: 'black-forest-labs/flux-schnell',
31+
parameters: {
32+
aspectRatio: {
33+
default: '1:1',
34+
enum: ['1:1', '16:9', '9:16', '4:3', '3:4', '21:9', '9:21'],
35+
},
36+
prompt: { default: '' },
37+
seed: { default: null },
38+
},
39+
pricing: {
40+
units: [{ name: 'imageGeneration', rate: 0.003, strategy: 'fixed', unit: 'image' }],
41+
},
42+
releasedAt: '2024-08-01',
43+
type: 'image',
44+
},
45+
{
46+
description: 'FLUX Dev - Development version of FLUX for non-commercial use.',
47+
displayName: 'FLUX Dev',
48+
enabled: true,
49+
id: 'black-forest-labs/flux-dev',
50+
parameters: {
51+
aspectRatio: {
52+
default: '1:1',
53+
enum: ['1:1', '16:9', '9:16', '4:3', '3:4', '21:9', '9:21'],
54+
},
55+
cfg: { default: 3.5, max: 10, min: 1, step: 0.1 },
56+
prompt: { default: '' },
57+
seed: { default: null },
58+
steps: { default: 28, max: 50, min: 1 },
59+
},
60+
pricing: {
61+
units: [{ name: 'imageGeneration', rate: 0.025, strategy: 'fixed', unit: 'image' }],
62+
},
63+
releasedAt: '2024-08-01',
64+
type: 'image',
65+
},
66+
{
67+
description: 'FLUX Pro - Professional FLUX model with high quality output.',
68+
displayName: 'FLUX Pro',
69+
enabled: true,
70+
id: 'black-forest-labs/flux-pro',
71+
parameters: {
72+
aspectRatio: {
73+
default: '1:1',
74+
enum: ['1:1', '16:9', '9:16', '4:3', '3:4', '21:9', '9:21'],
75+
},
76+
cfg: { default: 3, max: 10, min: 1, step: 0.1 },
77+
prompt: { default: '' },
78+
seed: { default: null },
79+
steps: { default: 25, max: 50, min: 1 },
80+
},
81+
pricing: {
82+
units: [{ name: 'imageGeneration', rate: 0.05, strategy: 'fixed', unit: 'image' }],
83+
},
84+
releasedAt: '2024-08-01',
85+
type: 'image',
86+
},
87+
];
88+
89+
export const allModels = [...imageModels];
90+
91+
export default allModels;

packages/model-bank/src/const/modelProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export enum ModelProvider {
4646
Perplexity = 'perplexity',
4747
Qiniu = 'qiniu',
4848
Qwen = 'qwen',
49+
Replicate = 'replicate',
4950
SambaNova = 'sambanova',
5051
Search1API = 'search1api',
5152
SenseNova = 'sensenova',

packages/model-runtime/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"async-retry": "^1.3.3",
2121
"debug": "^4.4.3",
2222
"model-bank": "workspace:*",
23-
"openai": "^4.104.0"
23+
"openai": "^4.104.0",
24+
"replicate": "^1.4.0"
2425
}
2526
}

packages/model-runtime/src/core/ModelRuntime.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
TextToImagePayload,
1717
TextToSpeechPayload,
1818
} from '../types';
19+
import { AgentRuntimeErrorType } from '../types/error';
1920
import { AuthenticatedImageRuntime, CreateImagePayload } from '../types/image';
21+
import { AgentRuntimeError } from '../utils/createError';
2022
import { LobeRuntimeAI } from './BaseAI';
2123

2224
export interface AgentChatOptions {
@@ -62,7 +64,15 @@ export class ModelRuntime {
6264
* ```
6365
*/
6466
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
65-
return this._runtime.chat!(payload, options);
67+
if (typeof this._runtime.chat !== 'function') {
68+
throw AgentRuntimeError.chat({
69+
error: new Error('Chat is not supported by this provider'),
70+
errorType: AgentRuntimeErrorType.ProviderBizError,
71+
provider: payload.provider || 'unknown',
72+
});
73+
}
74+
75+
return this._runtime.chat(payload, options);
6676
}
6777

6878
async generateObject(payload: GenerateObjectPayload) {

0 commit comments

Comments
 (0)