@convo-lang/convo-lang
Version:
The language of AI
136 lines (135 loc) • 4.22 kB
TypeScript
import { VfsItem } from "@iyio/vfs";
/**
* An inclusive range selection of page indexes
*/
export interface ConvoDocRange {
from: number;
to: number;
}
export type ConvoDocRangeOptions = number | number | ConvoDocRange | null | undefined | 'all' | (number | number | ConvoDocRange | null | undefined | 'all')[];
export type ConvoDocOutputTarget = 'firstPage' | 'lastPage' | 'all';
export interface ConvoDocSelectStatement {
/**
* Controls the range of pages selected. A value of undefined is equivalent to "all"
*/
range?: ConvoDocRangeOptions;
/**
* If true the select statement is applied per page and if false the select statement is
* applied once for all pages selected by the range.
*/
perPage?: boolean;
/**
* Controls which pass the select statement is included. Each pass will have access to the
* previous pass outputs.
*/
pass?: number;
/**
* A natural language statement that must be true for the selected range in order for output
* to be produced
*/
requirement?: string;
/**
* A convo script that when evaluated should set the `__return` to true.
*/
requirementConvo?: string;
/**
* Natural language instructions about what to generate as output
*/
generate?: string;
/**
* A convo script that is used to generate the output of the select. The value of the last
* function call will be used as the output.
*/
generateConvo?: string;
/**
* text/plain or application/json will be used by default based on the generated output.
*/
outputContentType?: string;
/**
* A prefix to be added before the output of the select when used in a prompt
*/
outputPrefix?: string;
/**
* A suffix to be added after the output of the select when used in a prompt
*/
outputSuffix?: string;
/**
* @default "firstPage"
*/
outputTarget?: ConvoDocOutputTarget;
/**
* Will set the type of the output generated by the select
*/
outputType?: string;
}
/**
* Used to define queries against a document or collection of document using natural language.
*/
export interface ConvoDocQuery {
src: VfsItem | string;
/**
* If true each page will be converted to markdown using a vision model as the first pass of
* selection.
*/
visionPass?: boolean;
/**
* If true each page will be converted to text using a document reader.
*/
textPass?: boolean;
select?: ConvoDocSelectStatement[];
/**
* Used to break cached results
*/
salt?: string;
}
export declare const convoDocResultFormatVersion = 2;
export interface ConvoDocQueryResult {
outputs: ConvoDocOutput[];
pages: ConvoDocPageResult[];
}
export interface ConvoDocPageResult {
index: number;
}
export interface ConvoDocOutput {
id: number;
/**
* A prefix to be added before the output when used in a prompt
*/
prefix?: string;
/**
* A suffix to be added after the output when used in a prompt
*/
suffix?: string;
/**
* If empty the output is an output of the entire document
*/
pageIndexes: number[];
/**
* Can be a reference to library specific page handlers
*/
pageSrc?: any;
/**
* Output of the select statement that created the output.
*/
output: any;
/**
* Use text/plain if not sure what to use
*/
contentType: string;
/**
* A generic type that can be used to categorize the output
* @default "content"
*/
type: string;
/**
* The pass the output was generated in. Pass -1 is the default vision pass
*/
pass: number;
}
export interface ConvoDocReader {
pageToImageAsync?: (pageIndex: number, format?: string) => Blob | undefined | Promise<Blob | undefined>;
pageToTextAsync?: (pageIndex: number) => string | undefined | Promise<string | undefined>;
dispose?: () => void;
getPageCountAsync: () => number | Promise<number>;
}
export type ConvoDocReaderFactory = (contentType: string, url: string, src: VfsItem | string) => ConvoDocReader | undefined | Promise<ConvoDocReader | undefined>;