UNPKG

@promptbook/azure-openai

Version:

Promptbook: Run AI apps in plain human language across multiple models and platforms

73 lines (72 loc) 3.18 kB
import type { string_mime_type } from '../../types/typeAliases'; import type { string_name } from '../../types/typeAliases'; import type { string_SCREAMING_CASE } from '../../utils/normalization/normalizeTo_SCREAMING_CASE'; import type { empty_object } from '../../utils/organization/empty_object'; import type { FormatSubvalueParser } from './FormatSubvalueParser'; /** * A format definition is a set of functions that define how to validate, heal and convert response from LLM. * * @remarks * - "settings" are runtime options that affect parsing (e.g., delimiter for CSV). * - "schema" is a structural definition or contract for the data (e.g., expected fields in JSON). * * @see https://github.com/webgptorg/promptbook/discussions/36 * @private still in development [🏢] */ export type FormatParser<TValue extends TPartialValue, TPartialValue extends string, TSettings extends empty_object, TSchema extends empty_object> = { /** * The name of the format used in .book.md files * * @example "JSON" */ readonly formatName: string_name & string_SCREAMING_CASE; /** * Aliases for the `formatName` */ readonly aliases?: ReadonlyArray<string_name & string_SCREAMING_CASE>; /** * The mime type of the format (if any) * * @example "application/json" */ readonly mimeType?: string_mime_type; /** * Check if a value is fully valid * * @param value The value to check, for example "{\"foo\": true}" * @param schema Optional schema to do extra validation */ isValid(value: string, settings?: TSettings, schema?: TSchema): value is TValue; /** * Check if a first part of a value is valid * * @see https://github.com/webgptorg/promptbook/discussions/37 * * @param partialValue Partial value to check, for example "{\"foo\": t" * @param schema Optional schema to do extra validation */ canBeValid(partialValue: string, settings?: TSettings, schema?: TSchema): partialValue is TPartialValue; /** * Heal a value to make it valid if possible * * Note: This make sense in context of LLMs that often returns slightly invalid values * @see https://github.com/webgptorg/promptbook/discussions/31 * * @param value The value to heal, for example "{foo: true}" * @param scheme * @throws {Error} If the value cannot be healed */ heal(value: string, settings?: TSettings, scheme?: TSchema): TValue; /** * Parsers for extracting or mapping subvalues from the main value (e.g., rows from CSV, items from JSON array). */ readonly subvalueParsers: ReadonlyArray<FormatSubvalueParser<TValue, TSettings>>; }; /** * TODO: [♏] Add some prepare hook to modify prompt according to the format * TODO: [🍓]`name` and `aliases` should be UPPERCASE only and interpreted as case-insensitive (via normalization) * TODO: [🍓][👨‍⚖️] Compute TPartialValue dynamically - PartialString<TValue> * TODO: [🍓][🧠] Should execution tools be available to heal, canBeValid and isValid? * TODO: [🍓][🧠] llm Provider Bindings * TODO: [🍓][🔼] Export via some package */