|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +export interface LanguageModel extends EventTarget { |
| 19 | + create(options?: LanguageModelCreateOptions): Promise<LanguageModel>; |
| 20 | + availability(options?: LanguageModelCreateCoreOptions): Promise<Availability>; |
| 21 | + prompt( |
| 22 | + input: LanguageModelPrompt, |
| 23 | + options?: LanguageModelPromptOptions |
| 24 | + ): Promise<string>; |
| 25 | + promptStreaming( |
| 26 | + input: LanguageModelPrompt, |
| 27 | + options?: LanguageModelPromptOptions |
| 28 | + ): ReadableStream; |
| 29 | + measureInputUsage( |
| 30 | + input: LanguageModelPrompt, |
| 31 | + options?: LanguageModelPromptOptions |
| 32 | + ): Promise<number>; |
| 33 | + destroy(): undefined; |
| 34 | +} |
| 35 | +enum Availability { |
| 36 | + 'unavailable', |
| 37 | + 'downloadable', |
| 38 | + 'downloading', |
| 39 | + 'available' |
| 40 | +} |
| 41 | +interface LanguageModelCreateCoreOptions { |
| 42 | + topK?: number; |
| 43 | + temperature?: number; |
| 44 | + expectedInputs?: LanguageModelExpectedInput[]; |
| 45 | +} |
| 46 | +interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions { |
| 47 | + signal?: AbortSignal; |
| 48 | + systemPrompt?: string; |
| 49 | + initialPrompts?: LanguageModelInitialPrompts; |
| 50 | +} |
| 51 | +interface LanguageModelPromptOptions { |
| 52 | + signal?: AbortSignal; |
| 53 | +} |
| 54 | +interface LanguageModelExpectedInput { |
| 55 | + type: LanguageModelMessageType; |
| 56 | + languages?: string[]; |
| 57 | +} |
| 58 | +type LanguageModelPrompt = |
| 59 | + | LanguageModelMessage[] |
| 60 | + | LanguageModelMessageShorthand[] |
| 61 | + | string; |
| 62 | +type LanguageModelInitialPrompts = |
| 63 | + | LanguageModelMessage[] |
| 64 | + | LanguageModelMessageShorthand[]; |
| 65 | +interface LanguageModelMessage { |
| 66 | + role: LanguageModelMessageRole; |
| 67 | + content: LanguageModelMessageContent[]; |
| 68 | +} |
| 69 | +interface LanguageModelMessageShorthand { |
| 70 | + role: LanguageModelMessageRole; |
| 71 | + content: string; |
| 72 | +} |
| 73 | +interface LanguageModelMessageContent { |
| 74 | + type: LanguageModelMessageType; |
| 75 | + content: LanguageModelMessageContentValue; |
| 76 | +} |
| 77 | +type LanguageModelMessageRole = 'system' | 'user' | 'assistant'; |
| 78 | +type LanguageModelMessageType = 'text' | 'image' | 'audio'; |
| 79 | +type LanguageModelMessageContentValue = |
| 80 | + | ImageBitmapSource |
| 81 | + | AudioBuffer |
| 82 | + | BufferSource |
| 83 | + | string; |
0 commit comments