Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable request limit & flag. #69

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function makeArgs(argv = process.argv) {
"template-view": { type: "string", default: process.env["AILLY_TEMPLATE_VIEW"] },
prompt: { type: "string", default: process.env["AILLY_PROMPT"], short: "p" },
system: { type: "string", default: process.env["AILLY_SYSTEM"], short: "s" },
"request-limit": { type: "string", default: process.env["AILLY_REQUEST_LIMIT"] },
temperature: { type: "string", default: "" },
"update-db": { type: "boolean", default: false },
"query-db": { type: "string", default: "" },
Expand Down Expand Up @@ -65,6 +66,7 @@ export function help() {

--plugin can load a custom RAG plugin. Specify a path to import with "file://./path/to/plugin.mjs". plugin.mjs must export a single default function that meets the PluginBuilder interface in core/src/plugin/index.ts
--template-view loads a YAML or JSON file to use as a view for the prompt templates. This view will be merged after global, engine, and plugin views but before system and template views.
--request-limit will limit to this many requests at once. Default is 5, unless the model is Opus, which has a default request limit of 1.
DavidSouther marked this conversation as resolved.
Show resolved Hide resolved

--no-overwrite will not run generation on Content with an existing Response.
--summary will show a pricing expectation before running and prompt for OK.
Expand Down
2 changes: 2 additions & 0 deletions cli/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function loadFs(fs, args) {
const root = resolve(args.values.root ?? '.');
fs.cd(root);


const settings = await ailly.Ailly.makePipelineSettings({
root,
out: resolve(args.values.out ?? root),
Expand All @@ -37,6 +38,7 @@ export async function loadFs(fs, args) {
plugin: args.values.plugin,
templateView: await loadTemplateView(fs, args.values['template-view']),
overwrite: !args.values["no-overwrite"],
requestLimit: args.values['request-limit'] ?? args.values.model?.includes("opus") ? 1 : undefined,
});

const positionals = args.positionals.slice(2).map(a => resolve(join(root, a)));
Expand Down
7 changes: 4 additions & 3 deletions core/src/actions/prompt_thread.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PipelineSettings } from "../ailly.js";
import { DEFAULT_SCHEDULER_LIMIT, PipelineSettings } from "../ailly.js";
import { View, type Content } from "../content/content.js";
import type { Engine } from "../engine/index.js";
import type { Plugin } from "../plugin/index.js";
Expand All @@ -22,7 +22,7 @@ export interface PromptThreadSummary extends PromptThreadsSummary {

export async function scheduler<T>(
taskQueue: Array<() => Promise<T>>,
limit: number = 5
limit: number = DEFAULT_SCHEDULER_LIMIT
): Promise<PromiseSettledResult<T>[]> {
taskQueue = [...taskQueue].reverse();
let finished: Array<Promise<T>> = [];
Expand Down Expand Up @@ -130,7 +130,8 @@ export class PromptThread {
private runIsolated(): Promise<PromiseSettledResult<Content>[]> {
LOGGER.debug(`Running thread for ${this.content.length} isolated prompts`);
return scheduler(
this.content.map((c, i) => () => this.runOne(c, i))
this.content.map((c, i) => () => this.runOne(c, i)),
this.settings.requestLimit
).finally(() => (this.done = true));
}

Expand Down
6 changes: 6 additions & 0 deletions core/src/ailly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export type Thread = Content[];

export { GenerateManager } from "./actions/generate_manager.js";

export const DEFAULT_SCHEDULER_LIMIT = 5;

export interface PipelineSettings {
root: string;
out: string;
engine: string;
model: string;
requestLimit: number;
context: NonNullable<ContentMeta["context"]>;
plugin: string;
isolated: boolean;
Expand All @@ -30,6 +33,7 @@ export async function makePipelineSettings({
out = root,
engine = DEFAULT_ENGINE,
model,
requestLimit = DEFAULT_SCHEDULER_LIMIT,
context = "conversation",
plugin = DEFAULT_PLUGIN,
overwrite = true,
Expand All @@ -46,6 +50,7 @@ export async function makePipelineSettings({
overwrite?: boolean;
isolated?: boolean;
combined?: boolean;
requestLimit?: number;
templateView?: View;
}): Promise<PipelineSettings> {
model = model ?? (await getEngine(engine)).DEFAULT_MODEL;
Expand All @@ -57,6 +62,7 @@ export async function makePipelineSettings({
out,
engine,
model,
requestLimit,
context: context as NonNullable<ContentMeta["context"]>,
plugin,
overwrite,
Expand Down