From d7e9dd151531cb3b6119c9ae6a31f16e19cf1ed3 Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Tue, 24 Oct 2023 11:18:21 -0400 Subject: [PATCH 1/5] chore: send logs query param to status request as true by default --- libs/client/src/function.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index 01f5ae0..a59b109 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -131,7 +131,7 @@ export async function subscribe( const pollInterval = options.pollInterval ?? 1000; const poll = async () => { try { - const requestStatus = await queue.status(id, requestId); + const requestStatus = await queue.status(id, requestId, true); if (options.onQueueUpdate) { options.onQueueUpdate(requestStatus); } @@ -197,9 +197,10 @@ interface Queue { * * @param id - The ID or URL of the function web endpoint. * @param requestId - The unique identifier for the enqueued request. + * @param logs - If `true`, the response will include the logs for the request. * @returns A promise that resolves to the status of the request. */ - status(id: string, requestId: string): Promise; + status(id: string, requestId: string, logs: boolean): Promise; /** * Retrieves the result of a specific request from the queue. @@ -231,10 +232,10 @@ export const queue: Queue = { ): Promise { return run(id, { ...options, method: 'post', path: '/fal/queue/submit/' }); }, - async status(id: string, requestId: string): Promise { + async status(id: string, requestId: string, logs: boolean = true): Promise { return run(id, { method: 'get', - path: `/fal/queue/requests/${requestId}/status`, + path: `/fal/queue/requests/${requestId}/status?logs=${logs ? '1' : '0'}`, }); }, async result(id: string, requestId: string): Promise { From 48829672cbecbedd388c7e896f7cb9c5948b56fe Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Wed, 25 Oct 2023 12:43:33 -0400 Subject: [PATCH 2/5] Update libs/client/src/function.ts Co-authored-by: Daniel Rochetti --- libs/client/src/function.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index a59b109..e74d660 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -235,7 +235,10 @@ export const queue: Queue = { async status(id: string, requestId: string, logs: boolean = true): Promise { return run(id, { method: 'get', - path: `/fal/queue/requests/${requestId}/status?logs=${logs ? '1' : '0'}`, + path: `/fal/queue/requests/${requestId}/status`, + input: { + logs: logs ? '1' : '0', + }, }); }, async result(id: string, requestId: string): Promise { From 1ee2832e2bbec3acb0ed611930e82033faf9e99f Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Wed, 25 Oct 2023 12:53:13 -0400 Subject: [PATCH 3/5] comments --- apps/demo-nextjs-app/pages/index.tsx | 3 ++- libs/client/src/function.ts | 7 ++++++- libs/client/src/types.ts | 7 +------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/demo-nextjs-app/pages/index.tsx b/apps/demo-nextjs-app/pages/index.tsx index c56dbfd..55a50f9 100644 --- a/apps/demo-nextjs-app/pages/index.tsx +++ b/apps/demo-nextjs-app/pages/index.tsx @@ -71,13 +71,14 @@ export function Index() { setLoading(true); const start = Date.now(); try { - const result: Result = await fal.queue.subscribe('110602490-lora', { + const result: Result = await fal.subscribe('110602490-lora', { input: { prompt, model_name: 'stabilityai/stable-diffusion-xl-base-1.0', image_size: 'square_hd', }, pollInterval: 5000, // Default is 1000 (every 1s) + logs: true, onQueueUpdate(update) { setElapsedTime(Date.now() - start); if ( diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index e74d660..b74440d 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -131,7 +131,7 @@ export async function subscribe( const pollInterval = options.pollInterval ?? 1000; const poll = async () => { try { - const requestStatus = await queue.status(id, requestId, true); + const requestStatus = await queue.status(id, requestId, options.logs ?? true); if (options.onQueueUpdate) { options.onQueueUpdate(requestStatus); } @@ -176,6 +176,11 @@ type QueueSubscribeOptions = { * @param status - The current status of the queue. */ onQueueUpdate?: (status: QueueStatus) => void; + + /** + * If `true`, the response will include the logs for the request. + */ + logs?: boolean; }; /** diff --git a/libs/client/src/types.ts b/libs/client/src/types.ts index 74ad756..4faf9f6 100644 --- a/libs/client/src/types.ts +++ b/libs/client/src/types.ts @@ -6,11 +6,6 @@ export type EnqueueResult = { request_id: string; }; -// export type QueueStatus = { -// status: "IN_PROGRESS" | "COMPLETED"; -// queue: number; -// }; - export type RequestLog = { message: string; level: 'STDERR' | 'STDOUT' | 'ERROR' | 'INFO' | 'WARN' | 'DEBUG'; @@ -22,7 +17,7 @@ export type QueueStatus = | { status: 'IN_PROGRESS' | 'COMPLETED'; response_url: string; - logs: RequestLog[]; + logs: null | RequestLog[]; } | { status: 'IN_QUEUE'; From 347a6d118a02fbbc8011434fdfd07ea4cbf3b838 Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Thu, 26 Oct 2023 13:18:15 -0400 Subject: [PATCH 4/5] default to false --- libs/client/src/function.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index b74440d..18c5169 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -131,7 +131,7 @@ export async function subscribe( const pollInterval = options.pollInterval ?? 1000; const poll = async () => { try { - const requestStatus = await queue.status(id, requestId, options.logs ?? true); + const requestStatus = await queue.status(id, requestId, options.logs ?? false); if (options.onQueueUpdate) { options.onQueueUpdate(requestStatus); } @@ -237,7 +237,7 @@ export const queue: Queue = { ): Promise { return run(id, { ...options, method: 'post', path: '/fal/queue/submit/' }); }, - async status(id: string, requestId: string, logs: boolean = true): Promise { + async status(id: string, requestId: string, logs: boolean = false): Promise { return run(id, { method: 'get', path: `/fal/queue/requests/${requestId}/status`, From c0d2c94f3c1790f3924ef4a6b41c91db2143197b Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Thu, 26 Oct 2023 13:48:16 -0400 Subject: [PATCH 5/5] lint --- libs/client/src/function.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index 18c5169..dca7c25 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -237,7 +237,7 @@ export const queue: Queue = { ): Promise { return run(id, { ...options, method: 'post', path: '/fal/queue/submit/' }); }, - async status(id: string, requestId: string, logs: boolean = false): Promise { + async status(id: string, requestId: string, logs = false): Promise { return run(id, { method: 'get', path: `/fal/queue/requests/${requestId}/status`,