mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-24 18:02:47 +08:00
feat: migrate fal workflow to server (#7581)
This commit is contained in:
@@ -198,9 +198,14 @@ export class CopilotClient {
|
||||
}
|
||||
|
||||
// Text or image to images
|
||||
imagesStream(sessionId: string, messageId?: string, seed?: string) {
|
||||
imagesStream(
|
||||
sessionId: string,
|
||||
messageId?: string,
|
||||
seed?: string,
|
||||
endpoint = 'images'
|
||||
) {
|
||||
const url = new URL(
|
||||
`${this.backendUrl}/api/copilot/chat/${sessionId}/images`
|
||||
`${this.backendUrl}/api/copilot/chat/${sessionId}/${endpoint}`
|
||||
);
|
||||
if (messageId) {
|
||||
url.searchParams.set('messageId', messageId);
|
||||
|
||||
@@ -8,10 +8,6 @@ export const promptKeys = [
|
||||
'debug:action:fal-sd15',
|
||||
'debug:action:fal-upscaler',
|
||||
'debug:action:fal-remove-bg',
|
||||
'debug:action:fal-sdturbo-clay',
|
||||
'debug:action:fal-sdturbo-pixel',
|
||||
'debug:action:fal-sdturbo-sketch',
|
||||
'debug:action:fal-sdturbo-fantasy',
|
||||
'debug:action:fal-face-to-sticker',
|
||||
'debug:action:fal-summary-caption',
|
||||
'chat:gpt4',
|
||||
@@ -42,6 +38,10 @@ export const promptKeys = [
|
||||
'Continue writing',
|
||||
'workflow:presentation',
|
||||
'workflow:brainstorm',
|
||||
'workflow:image-sketch',
|
||||
'workflow:image-clay',
|
||||
'workflow:image-anime',
|
||||
'workflow:image-pixel',
|
||||
] as const;
|
||||
|
||||
export type PromptKey = (typeof promptKeys)[number];
|
||||
|
||||
@@ -276,6 +276,7 @@ export function toImage({
|
||||
signal,
|
||||
timeout = TIMEOUT,
|
||||
retry = false,
|
||||
workflow = false,
|
||||
}: ToImageOptions) {
|
||||
let _sessionId: string;
|
||||
let _messageId: string | undefined;
|
||||
@@ -300,7 +301,12 @@ export function toImage({
|
||||
_messageId = messageId;
|
||||
}
|
||||
|
||||
const eventSource = client.imagesStream(_sessionId, _messageId, seed);
|
||||
const eventSource = client.imagesStream(
|
||||
_sessionId,
|
||||
_messageId,
|
||||
seed,
|
||||
workflow ? 'workflow' : undefined
|
||||
);
|
||||
AIProvider.LAST_ACTION_SESSIONID = _sessionId;
|
||||
|
||||
for await (const event of toTextStream(eventSource, {
|
||||
|
||||
@@ -27,10 +27,10 @@ import { setupTracker } from './tracker';
|
||||
|
||||
const filterStyleToPromptName = new Map(
|
||||
Object.entries({
|
||||
'Clay style': 'debug:action:fal-sdturbo-clay',
|
||||
'Pixel style': 'debug:action:fal-sdturbo-pixel',
|
||||
'Sketch style': 'debug:action:fal-sdturbo-sketch',
|
||||
'Anime style': 'debug:action:fal-sdturbo-fantasy',
|
||||
'Clay style': 'workflow:image-clay',
|
||||
'Pixel style': 'workflow:image-pixel',
|
||||
'Sketch style': 'workflow:image-sketch',
|
||||
'Anime style': 'workflow:image-anime',
|
||||
})
|
||||
);
|
||||
|
||||
@@ -356,13 +356,12 @@ Could you make a new website based on these notes and send back just the html fi
|
||||
|
||||
AIProvider.provide('filterImage', options => {
|
||||
// test to image
|
||||
const promptName = filterStyleToPromptName.get(
|
||||
options.style as string
|
||||
) as PromptKey;
|
||||
const promptName = filterStyleToPromptName.get(options.style as string);
|
||||
return toImage({
|
||||
...options,
|
||||
timeout: 120000,
|
||||
promptName,
|
||||
promptName: promptName as PromptKey,
|
||||
workflow: !!promptName?.startsWith('workflow:'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user