diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/docs/src/content/docs/reference/scripts/inline-prompts.mdx b/docs/src/content/docs/reference/scripts/inline-prompts.mdx index 4545d64c27..3c0ce8df3f 100644 --- a/docs/src/content/docs/reference/scripts/inline-prompts.mdx +++ b/docs/src/content/docs/reference/scripts/inline-prompts.mdx @@ -72,7 +72,7 @@ defTool( await Promise.all(env.files => prompt`Summarize the ${file}`) ``` -Internally, GenAIScript applies a concurrent limit of 5 per model by default. You can change this limit using the `modelConcurrency` option. +Internally, GenAIScript applies a concurrent limit of 8 per model by default. You can change this limit using the `modelConcurrency` option. ```js "modelConcurrency" script({ diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/core/src/concurrency.ts b/packages/core/src/concurrency.ts index 8a296a7b59..8837a49fb7 100644 --- a/packages/core/src/concurrency.ts +++ b/packages/core/src/concurrency.ts @@ -1,6 +1,7 @@ import pLimit, { LimitFunction } from "p-limit" import { runtimeHost } from "./host" import { normalizeInt } from "./util" +import { PROMISE_QUEUE_CONCURRENCY_DEFAULT } from "./constants" export type ConcurrentLimitFunction = LimitFunction @@ -20,7 +21,23 @@ export function concurrentLimit( export class PLimitPromiseQueue implements PromiseQueue { private queue: LimitFunction constructor(private readonly options: PromiseQueueOptions) { - this.queue = pLimit(options?.concurrency ?? 5) + this.queue = pLimit( + options?.concurrency ?? PROMISE_QUEUE_CONCURRENCY_DEFAULT + ) + } + + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise { + return await Promise.all( + values.map((value) => this.queue(fn, value, ...arguments_)) + ) + } + + async all(fns: (() => Awaitable)[]): Promise { + return await Promise.all(fns.map((fn) => this.queue(fn))) } add( diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 3c0920c62c..a02bc812eb 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -242,4 +242,5 @@ export const OPENAI_RETRY_DEFAULT_DEFAULT = 1000 export const TEMPLATE_ARG_FILE_MAX_TOKENS = 4000 export const TEMPLATE_ARG_DATA_SLICE_SAMPLE = 2000 -export const CHAT_REQUEST_PER_MODEL_CONCURRENT_LIMIT = 5 +export const CHAT_REQUEST_PER_MODEL_CONCURRENT_LIMIT = 8 +export const PROMISE_QUEUE_CONCURRENCY_DEFAULT = 16 diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/core/src/promptcontext.ts b/packages/core/src/promptcontext.ts index ad5f736819..43dc36a645 100644 --- a/packages/core/src/promptcontext.ts +++ b/packages/core/src/promptcontext.ts @@ -225,7 +225,7 @@ export async function createPromptContext( await runtimeHost.select(message, options), input: async (message) => await runtimeHost.input(message), confirm: async (message) => await runtimeHost.confirm(message), - pQueue: (options) => new PLimitPromiseQueue(options), + promiseQueue: (options) => new PLimitPromiseQueue(options), }) const ctx: PromptContext & RunPromptContextNode = { diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index dc1ccb75c1..85b712ecf3 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -2284,11 +2284,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2303,9 +2318,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/genaisrc/summarize-concurrent.genai.mjs b/packages/sample/genaisrc/summarize-concurrent.genai.mjs index 454cd574b7..67c4832bc3 100644 --- a/packages/sample/genaisrc/summarize-concurrent.genai.mjs +++ b/packages/sample/genaisrc/summarize-concurrent.genai.mjs @@ -1,23 +1,18 @@ -import pAll from "p-all" - script({ title: "summarize concurrently", model: "openai:gpt-3.5-turbo", files: "src/rag/*", }) -const summaries = await pAll( - env.files.map( - (file) => () => - runPrompt( - (_) => { - _.def("FILE", file) - _.$`Summarize FILE with one paragraph.` - }, - { label: file.filename } - ) - ), - { concurrency: 2 } +const queue = host.promiseQueue({ concurrency: 2 }) +const summaries = await queue.mapAll(env.files, (file) => + runPrompt( + (_) => { + _.def("FILE", file) + _.$`Summarize FILE with one paragraph.` + }, + { label: file.filename } + ) ) summaries.forEach((s) => def("FILE", s.text)) diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost { diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index 13f0061d34..814e085455 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -2317,11 +2317,26 @@ interface PromiseQueue { * @param fn */ add( - function_: ( - ...arguments_: Arguments - ) => PromiseLike | ReturnType, + function_: (...arguments_: Arguments) => Awaitable, ...arguments_: Arguments ): Promise + + /** + * Runs all the functions in the queue with limited concurrency + * @param fns + */ + all(fns: (() => Awaitable)[]): Promise + + /** + * Applies a function to all the values in the queue with limited concurrency + * @param values + * @param fn + */ + async mapAll( + values: T[], + fn: (value: T, ...arguments_: Arguments) => Awaitable, + ...arguments_: Arguments + ): Promise } interface PromiseQueueOptions { @@ -2336,9 +2351,9 @@ interface PromptHost extends ShellHost { container(options?: ContainerOptions): Promise /** - * Create a new job promise queue + * Create a new promise queue to run async functions with limited concurrency */ - pQueue(options?: PromiseQueueOptions): PromiseQueue + promiseQueue(options?: PromiseQueueOptions): PromiseQueue } interface ContainerHost extends ShellHost {