-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move providers to adapters and models
- Loading branch information
1 parent
14a671e
commit 5eb25bd
Showing
9 changed files
with
312 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* A symbol used internally to define the types for a model whilst keeping | ||
* generics clean. Must not be exported outside of this module. | ||
*/ | ||
export declare const types: unique symbol; | ||
export type types = typeof types; | ||
|
||
/** | ||
* An AI model, defining the I/O format and typing, and how to call the model. | ||
* | ||
* Models should extend this interface to define their own input and output | ||
* types. | ||
*/ | ||
export interface AiAdapter { | ||
/** | ||
* The I/O format for the adapter. | ||
*/ | ||
format: AiAdapter.Format; | ||
|
||
/** | ||
* The input and output types for this AI I/O format. | ||
* | ||
* This is not accessible externally, and is only used internally to define | ||
* the user-facing types for each model in a way that avoids using generics. | ||
*/ | ||
[types]: { | ||
/** | ||
* The input typing for the format. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
input: any; | ||
/** | ||
* The output typing for the format. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
output: any; | ||
}; | ||
|
||
/** | ||
* The URL to use for the format. | ||
*/ | ||
url?: string; | ||
|
||
/** | ||
* Headers to pass to the format. | ||
*/ | ||
headers?: Record<string, string>; | ||
|
||
/** | ||
* The authentication key to use for the format. | ||
*/ | ||
authKey: string; | ||
|
||
/** | ||
* Given the model and a body, mutate them as needed. This is useful for | ||
* addressing any dynamic changes to the model options or body based on each | ||
* other, such as the target URL changing based on a model. | ||
*/ | ||
onCall?: ( | ||
/** | ||
* The model to use for the inference. | ||
*/ | ||
model: this, | ||
|
||
/** | ||
* The input to pass to the model. | ||
*/ | ||
body: this[types]["input"] | ||
) => void; | ||
} | ||
|
||
/** | ||
* An AI model, defining the I/O format and typing, and how to call the model. | ||
* | ||
* Models should extend this interface to define their own input and output | ||
* types. | ||
*/ | ||
export namespace AiAdapter { | ||
/** | ||
* A helper used to infer the input type of an adapter. | ||
*/ | ||
export type Input<TAdapter extends AiAdapter> = TAdapter[types]["input"]; | ||
|
||
/** | ||
* A helper used to infer the output type of an adapter. | ||
*/ | ||
export type Output<TAdapter extends AiAdapter> = TAdapter[types]["output"]; | ||
|
||
/** | ||
* Supported I/O formats for AI models. | ||
*/ | ||
export type Format = "openai-chat"; // | "anthropic" | "gemini" | "bedrock"; | ||
|
||
/** | ||
* A function that creates a model that adheres to an existng AI adapter | ||
* interface. | ||
*/ | ||
export type ModelCreator< | ||
TInput extends unknown[], | ||
TOutput extends AiAdapter, | ||
> = (...args: TInput) => TOutput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.