add mj generation
This commit is contained in:
1 parent
ab976d3834
commit
8e49c21bcc
13 files changed
+725
-13
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { IMidjourneyChannel } from './models';
|
||||
|
||||
export const MIDJOURNEY_CHANNEL_NAME_FAST = 'Fast';
|
||||
export const MIDJOURNEY_CHANNEL_NAME_RELAX = 'Relax';
|
||||
export const MIDJOURNEY_CHANNEL_NAME_TURBO = 'Turbo';
|
||||
|
||||
export const API_ID_MIDJOURNEY_FAST = '9a628863-8879-462b-bbee-5dc46505b733';
|
||||
export const API_ID_MIDJOURNEY_RELAX = 'c58713f3-fef7-4c18-824c-9f76b5a07a7f';
|
||||
export const API_ID_MIDJOURNEY_TURBO = '62ec82bd-7de3-427f-b71a-ab3551ac7677';
|
||||
|
||||
export const MIDJOURNEY_CHANNEL_FAST: IMidjourneyChannel = {
|
||||
icon: 'fa-bolt fa-regular',
|
||||
apiId: API_ID_MIDJOURNEY_FAST,
|
||||
name: MIDJOURNEY_CHANNEL_NAME_FAST,
|
||||
displayName: 'Fast'
|
||||
};
|
||||
|
||||
export const MIDJOURNEY_CHANNEL_RELAX: IMidjourneyChannel = {
|
||||
icon: 'fa-bolt fa-regular',
|
||||
apiId: API_ID_MIDJOURNEY_RELAX,
|
||||
name: MIDJOURNEY_CHANNEL_NAME_RELAX,
|
||||
displayName: 'Relax'
|
||||
};
|
||||
|
||||
export const MIDJOURNEY_CHANNEL_TURBO: IMidjourneyChannel = {
|
||||
icon: 'fa-bolt fa-regular',
|
||||
apiId: API_ID_MIDJOURNEY_TURBO,
|
||||
name: MIDJOURNEY_CHANNEL_NAME_TURBO,
|
||||
displayName: 'Turbo'
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './constants';
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -0,0 +1,47 @@
|
||||
export interface IMidjourneyChannel {
|
||||
icon: string;
|
||||
apiId: string;
|
||||
name: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface IMidjourneyPreset {
|
||||
model?: string;
|
||||
ratio?: string;
|
||||
version?: string;
|
||||
stylize?: string;
|
||||
chaos?: string;
|
||||
}
|
||||
|
||||
export enum MidjourneyImagineAction {
|
||||
GENERATE = 'generate',
|
||||
UPSAMPLE1 = 'upsample1'
|
||||
}
|
||||
|
||||
export enum MidjourneyImagineState {
|
||||
PENDING = 'pending',
|
||||
GENERATING = 'generating',
|
||||
FINISHED = 'finished',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineRequest {
|
||||
action: MidjourneyImagineAction;
|
||||
prompt: string;
|
||||
image_id?: string;
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineResponse {
|
||||
task_id: string;
|
||||
progress: number;
|
||||
image_id: string;
|
||||
image_url: string;
|
||||
actions: MidjourneyImagineAction[];
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineOptions {
|
||||
stream?: (response: IMidjourneyImagineResponse) => void;
|
||||
token: string;
|
||||
endpoint: string;
|
||||
path: string;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import { IMidjourneyImagineOptions, IMidjourneyImagineRequest, IMidjourneyImagineResponse } from './models';
|
||||
|
||||
class MidjourneyOperator {
|
||||
async imagine(
|
||||
data: IMidjourneyImagineRequest,
|
||||
options: IMidjourneyImagineOptions
|
||||
): Promise<AxiosResponse<IMidjourneyImagineResponse>> {
|
||||
return await axios.post(options.path, data, {
|
||||
headers: {
|
||||
authorization: `Bearer ${options.token}`,
|
||||
accept: 'application/x-ndjson',
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
baseURL: options.endpoint,
|
||||
responseType: 'stream',
|
||||
onDownloadProgress: (event) => {
|
||||
const response = event.target.response;
|
||||
const lines = response.split('\r\n').filter((line: string) => !!line);
|
||||
const lastLine = lines[lines.length - 1];
|
||||
if (lastLine) {
|
||||
const jsonData = JSON.parse(lastLine);
|
||||
if (options?.stream) {
|
||||
options?.stream(jsonData as IMidjourneyImagineResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const midjourneyOperator = new MidjourneyOperator();
|
||||
Reference in new issue
Block a user