feat(core): add seed to fal (#6712)

This commit is contained in:
fundon
2024-04-26 11:40:09 +00:00
parent b639e52dca
commit 7584ab4b91
2 changed files with 15 additions and 5 deletions

View File

@@ -158,9 +158,14 @@ export class CopilotClient {
}
// Text or image to images
imagesStream(messageId: string, sessionId: string) {
return new EventSource(
`${this.backendUrl}/api/copilot/chat/${sessionId}/images?messageId=${messageId}`
imagesStream(messageId: string, sessionId: string, seed?: string) {
const url = new URL(
`${this.backendUrl}/api/copilot/chat/${sessionId}/images`
);
url.searchParams.set('messageId', messageId);
if (seed) {
url.searchParams.set('seed', seed);
}
return new EventSource(url);
}
}

View File

@@ -31,6 +31,10 @@ export type TextToTextOptions = {
signal?: AbortSignal;
};
export type ToImageOptions = TextToTextOptions & {
seed?: string;
};
export function createChatSession({
workspaceId,
docId,
@@ -175,8 +179,9 @@ export function toImage({
content,
attachments,
params,
seed,
timeout = TIMEOUT,
}: TextToTextOptions) {
}: ToImageOptions) {
return {
[Symbol.asyncIterator]: async function* () {
const { messageId, sessionId } = await createSessionMessage({
@@ -188,7 +193,7 @@ export function toImage({
params,
});
const eventSource = client.imagesStream(messageId, sessionId);
const eventSource = client.imagesStream(messageId, sessionId, seed);
for await (const event of toTextStream(eventSource, { timeout })) {
if (event.type === 'attachment') {
yield event.data;