Skip to content

Instantly share code, notes, and snippets.

@swissspidy
Last active June 6, 2024 13:44
Show Gist options
  • Save swissspidy/477df0a812ba68fada7ab54695eb7a78 to your computer and use it in GitHub Desktop.
Save swissspidy/477df0a812ba68fada7ab54695eb7a78 to your computer and use it in GitHub Desktop.
TypeScript type definitions for Chrome's new built-in AI prompt API
declare global {
interface AI {
canCreateTextSession(
opts?: AITextSessionOptions
): Promise< 'no' | 'readily' >;
createTextSession(): Promise< AITextSession >;
defaultTextSessionOptions(): Promise<AITextSessionOptions>
}
interface AITextSession {
promptStreaming( prompt: string ): IterableIterator< string >;
prompt( prompt: string ): Promise< string >;
}
interface AITextSessionOptions {
temperature: 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1.0;
topK: number;
}
interface Window {
ai: AI;
}
}
export type {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment