Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
import type { paths } from 'services/api/schema';
import { api, buildV1Url } from '..';
export type UserFontFace = {
path: string;
url: string;
weight: number;
style: 'normal' | 'italic';
};
export type UserFont = {
id: string;
family: string;
label: string;
path: string;
url: string;
faces: UserFontFace[];
};
type UserFontsResponse = {
fonts: UserFont[];
};
/**
* Builds an endpoint URL for the utilities router
* @example
* buildUtilitiesUrl('some-path')
* // '/api/v1/utilities/some-path'
*/
const buildUtilitiesUrl = (path: string = '') => buildV1Url(`utilities/${path}`);
// Types for expand-prompt and image-to-prompt endpoints.
// These will use generated schema types once schema.ts is regenerated.
type ExpandPromptRequest = {
prompt: string;
model_key: string;
max_tokens?: number;
system_prompt?: string | null;
seed?: number | null;
task_id?: string | null;
};
type ExpandPromptResponse = {
expanded_prompt: string;
seed: number;
error?: string | null;
};
type ImageToPromptRequest = {
image_name: string;
model_key: string;
instruction?: string;
task_id?: string | null;
};
type ImageToPromptResponse = {
prompt: string;
error?: string | null;
};
export const utilitiesApi = api.injectEndpoints({
endpoints: (build) => ({
dynamicPrompts: build.query<
paths['/api/v1/utilities/dynamicprompts']['post']['responses']['200']['content']['application/json'],
paths['/api/v1/utilities/dynamicprompts']['post']['requestBody']['content']['application/json']
>({
query: (arg) => ({
url: buildUtilitiesUrl('dynamicprompts'),
body: arg,
method: 'POST',
}),
// We need to fetch this on reconnect bc the user may have changed the text field while
// disconnected.
providesTags: ['FetchOnReconnect'],
}),
listUserFonts: build.query<UserFont[], void>({
query: () => ({
url: buildUtilitiesUrl('fonts'),
}),
transformResponse: (response: UserFontsResponse) => response.fonts,
providesTags: ['FetchOnReconnect'],
}),
expandPrompt: build.mutation<ExpandPromptResponse, ExpandPromptRequest>({
query: (arg) => ({
url: buildUtilitiesUrl('expand-prompt'),
body: arg,
method: 'POST',
}),
}),
imageToPrompt: build.mutation<ImageToPromptResponse, ImageToPromptRequest>({
query: (arg) => ({
url: buildUtilitiesUrl('image-to-prompt'),
body: arg,
method: 'POST',
}),
}),
}),
});
export const { useListUserFontsQuery, useExpandPromptMutation, useImageToPromptMutation } = utilitiesApi;