Better division of labor between frontend and backend model providers

A bit better thinking on which types go where.
This commit is contained in:
Kyle Corbitt
2023-07-21 11:49:35 -07:00
parent 7e1fbb3767
commit 741128e0f4
7 changed files with 58 additions and 48 deletions

View File

@@ -3,11 +3,18 @@ import { type JsonValue } from "type-fest";
export type SupportedProvider = "openai/ChatCompletion" | "replicate/llama2";
type ModelProviderModel = {
type ModelInfo = {
name?: string;
learnMore?: string;
};
export type FrontendModelProvider<SupportedModels extends string, OutputSchema> = {
name: string;
models: Record<SupportedModels, ModelInfo>;
normalizeOutput: (output: OutputSchema) => NormalizedOutput;
};
export type CompletionResponse<T> =
| { type: "error"; message: string; autoRetry: boolean; statusCode?: number }
| {
@@ -21,8 +28,6 @@ export type CompletionResponse<T> =
};
export type ModelProvider<SupportedModels extends string, InputSchema, OutputSchema> = {
name: string;
models: Record<SupportedModels, ModelProviderModel>;
getModel: (input: InputSchema) => SupportedModels | null;
shouldStream: (input: InputSchema) => boolean;
inputSchema: JSONSchema4;
@@ -33,7 +38,7 @@ export type ModelProvider<SupportedModels extends string, InputSchema, OutputSch
// This is just a convenience for type inference, don't use it at runtime
_outputSchema?: OutputSchema | null;
};
} & FrontendModelProvider<SupportedModels, OutputSchema>;
export type NormalizedOutput =
| {
@@ -44,7 +49,3 @@ export type NormalizedOutput =
type: "json";
value: JsonValue;
};
export type ModelProviderFrontend<ModelProviderT extends ModelProvider<any, any, any>> = {
normalizeOutput: (output: NonNullable<ModelProviderT["_outputSchema"]>) => NormalizedOutput;
};