mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 09:21:24 +08:00
feat(core): add seed to fal (#6712)
This commit is contained in:
+8
-3
@@ -158,9 +158,14 @@ export class CopilotClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Text or image to images
|
// Text or image to images
|
||||||
imagesStream(messageId: string, sessionId: string) {
|
imagesStream(messageId: string, sessionId: string, seed?: string) {
|
||||||
return new EventSource(
|
const url = new URL(
|
||||||
`${this.backendUrl}/api/copilot/chat/${sessionId}/images?messageId=${messageId}`
|
`${this.backendUrl}/api/copilot/chat/${sessionId}/images`
|
||||||
);
|
);
|
||||||
|
url.searchParams.set('messageId', messageId);
|
||||||
|
if (seed) {
|
||||||
|
url.searchParams.set('seed', seed);
|
||||||
|
}
|
||||||
|
return new EventSource(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ export type TextToTextOptions = {
|
|||||||
signal?: AbortSignal;
|
signal?: AbortSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ToImageOptions = TextToTextOptions & {
|
||||||
|
seed?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export function createChatSession({
|
export function createChatSession({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
docId,
|
docId,
|
||||||
@@ -175,8 +179,9 @@ export function toImage({
|
|||||||
content,
|
content,
|
||||||
attachments,
|
attachments,
|
||||||
params,
|
params,
|
||||||
|
seed,
|
||||||
timeout = TIMEOUT,
|
timeout = TIMEOUT,
|
||||||
}: TextToTextOptions) {
|
}: ToImageOptions) {
|
||||||
return {
|
return {
|
||||||
[Symbol.asyncIterator]: async function* () {
|
[Symbol.asyncIterator]: async function* () {
|
||||||
const { messageId, sessionId } = await createSessionMessage({
|
const { messageId, sessionId } = await createSessionMessage({
|
||||||
@@ -188,7 +193,7 @@ export function toImage({
|
|||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
|
|
||||||
const eventSource = client.imagesStream(messageId, sessionId);
|
const eventSource = client.imagesStream(messageId, sessionId, seed);
|
||||||
for await (const event of toTextStream(eventSource, { timeout })) {
|
for await (const event of toTextStream(eventSource, { timeout })) {
|
||||||
if (event.type === 'attachment') {
|
if (event.type === 'attachment') {
|
||||||
yield event.data;
|
yield event.data;
|
||||||
|
|||||||
Reference in New Issue
Block a user