Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | /**
* Configuration information for a language model.
* Contains the model identifier and optional configuration parameters.
*
* @template Options - The type of options supported by the model
*/
export type ModelInfo<Options = unknown> = {
model: string;
options?: Partial<Options>;
};
/**
* Interface for a language model that can be loaded, unloaded, and used for text generation.
* Provides a standardized interface for interacting with different language model implementations.
*
* @template Options - The type of options supported by the model
* @template Response - The type of response generated by the model
*/
export type LanguageModel<Options, Response> = {
/**
* Retrieves information about the model configuration.
*
* @returns A promise that resolves to the model information
*/
getInfo: () => Promise<ModelInfo<Options>>;
/**
* Loads the model into memory and keeps it alive indefinitely.
*
* @returns A promise that resolves when the model is loaded.
*/
load: () => Promise<void>;
/**
* Unloads the model from memory.
*
* @returns A promise that resolves when the model is unloaded.
*/
unload: () => Promise<void>;
/**
* Generates a response from the model based on the provided prompt.
*
* @param prompt - The prompt to complete.
* @param options - The options to pass to the model.
* @returns A promise that resolves to an async iterable of response chunks, or rejects if an error occurs.
*/
sample: (
prompt: string,
options?: Partial<Options>,
) => Promise<{
stream: AsyncIterable<Response>;
abort: () => Promise<void>;
}>;
};
/**
* Configuration for creating a language model instance.
* Specifies which model to use and any model-specific options.
*
* @template Options - The type of options supported by the model
*/
export type InstanceConfig<Options> = {
model: string;
options?: Partial<Options>;
};
/**
* Service interface for creating language model instances.
* Provides a factory pattern for instantiating language models with specific configurations.
*
* @template Config - The type of configuration accepted by the service
* @template Options - The type of options supported by created models
* @template Response - The type of response generated by created models
*/
export type LanguageModelService<Config, Options, Response> = {
/**
* Creates a new language model instance with the specified configuration.
*
* @param config - The configuration for the model instance
* @returns A promise that resolves to a language model instance
*/
makeInstance: (
config: InstanceConfig<Config>,
) => Promise<LanguageModel<Options, Response>>;
};
|