@coasys/ad4m / Exports / AIClient
Class: AIClient
Table of contents
Constructors
Properties
Methods
- addModel
- addTask
- closeTranscriptionStream
- discoverModels
- embed
- feedTranscriptionStream
- getDefaultModel
- getModels
- modelLoadingStatus
- openTranscriptionStream
- prompt
- removeModel
- removeTask
- serializeModelInput
- setDefaultModel
- tasks
- updateModel
- updateTask
Constructors
constructor
• new AIClient(baseUrl, token?, sharedApiClient?)
Parameters
| Name | Type |
|---|---|
baseUrl | string |
token? | string |
sharedApiClient? | ApiClient |
Defined in
core/src/ai/AIClient.ts:12 (opens in a new tab)
Properties
#apiClient
• Private #apiClient: ApiClient
Defined in
core/src/ai/AIClient.ts:9 (opens in a new tab)
#pendingStreamIds
• Private #pendingStreamIds: Set<string>
Defined in
core/src/ai/AIClient.ts:143 (opens in a new tab)
#transcriptionUnsubscribers
• Private #transcriptionUnsubscribers: Map<string, () => void>
Defined in
core/src/ai/AIClient.ts:10 (opens in a new tab)
Methods
addModel
▸ addModel(model, options?): Promise<string>
Parameters
| Name | Type |
|---|---|
model | ModelInput |
options? | CallOptions |
Returns
Promise<string>
Defined in
core/src/ai/AIClient.ts:41 (opens in a new tab)
addTask
▸ addTask(name, modelId, systemPrompt, promptExamples, metaData?): Promise<AITask>
Parameters
| Name | Type |
|---|---|
name | string |
modelId | string |
systemPrompt | string |
promptExamples | { input: string ; output: string }[] |
metaData? | string |
Returns
Promise<AITask>
Defined in
core/src/ai/AIClient.ts:65 (opens in a new tab)
closeTranscriptionStream
▸ closeTranscriptionStream(streamId): Promise<void>
Parameters
| Name | Type |
|---|---|
streamId | string |
Returns
Promise<void>
Defined in
core/src/ai/AIClient.ts:133 (opens in a new tab)
discoverModels
▸ discoverModels(baseUrl, apiKey?, apiType?): Promise<string[]>
Ask a remote endpoint which models it serves, before adding one.
Takes the credentials of a model that does not exist yet — a settings form is being filled in and wants the list to pick from. Rejects when the endpoint is unreachable or the key is refused, which makes this the credential check too: without it a bad key surfaces later as a failed completion carrying an error from a different layer.
apiType defaults to the OpenAI shape, which is what every endpoint
that is not Anthropic speaks.
Parameters
| Name | Type |
|---|---|
baseUrl | string |
apiKey? | string |
apiType? | string |
Returns
Promise<string[]>
Defined in
core/src/ai/AIClient.ts:37 (opens in a new tab)
embed
▸ embed(modelId, text, options?): Promise<number[]>
Parameters
| Name | Type |
|---|---|
modelId | string |
text | string |
options? | CallOptions |
Returns
Promise<number[]>
Defined in
core/src/ai/AIClient.ts:97 (opens in a new tab)
feedTranscriptionStream
▸ feedTranscriptionStream(streamIds, audio): Promise<void>
Feed an audio utterance to one or more transcription streams. Sends raw binary Float32Array as application/octet-stream. NOTE: This method still uses HTTP fetch because binary audio data cannot be efficiently sent over the JSON-based WebSocket RPC protocol. Transcription results are delivered via the WS event channel.
Rejects if any stream did not take the audio. When only some failed, the message names them and the others were fed, so retry only the failed ids.
Parameters
| Name | Type |
|---|---|
streamIds | string | string[] |
audio | number[] | Float32Array |
Returns
Promise<void>
Defined in
core/src/ai/AIClient.ts:155 (opens in a new tab)
getDefaultModel
▸ getDefaultModel(modelType): Promise<AIModel>
Parameters
| Name | Type |
|---|---|
modelType | ModelType |
Returns
Promise<AIModel>
Defined in
core/src/ai/AIClient.ts:57 (opens in a new tab)
getModels
▸ getModels(): Promise<AIModel[]>
Returns
Promise<AIModel[]>
Defined in
core/src/ai/AIClient.ts:21 (opens in a new tab)
modelLoadingStatus
▸ modelLoadingStatus(model): Promise<AIModelLoadingStatus>
Parameters
| Name | Type |
|---|---|
model | string |
Returns
Promise<AIModelLoadingStatus>
Defined in
core/src/ai/AIClient.ts:89 (opens in a new tab)
openTranscriptionStream
▸ openTranscriptionStream(modelId, streamCallback, params?): Promise<string>
Parameters
| Name | Type |
|---|---|
modelId | string |
streamCallback | (text: string) => void |
params? | Object |
params.endThreshold? | number |
params.endWindow? | number |
params.startThreshold? | number |
params.startWindow? | number |
params.timeBeforeSpeech? | number |
Returns
Promise<string>
Defined in
core/src/ai/AIClient.ts:111 (opens in a new tab)
prompt
▸ prompt(taskId, prompt, options?): Promise<string>
Parameters
| Name | Type |
|---|---|
taskId | string |
prompt | string |
options? | CallOptions |
Returns
Promise<string>
Defined in
core/src/ai/AIClient.ts:93 (opens in a new tab)
removeModel
▸ removeModel(modelId): Promise<boolean>
Parameters
| Name | Type |
|---|---|
modelId | string |
Returns
Promise<boolean>
Defined in
core/src/ai/AIClient.ts:49 (opens in a new tab)
removeTask
▸ removeTask(taskId): Promise<boolean>
Parameters
| Name | Type |
|---|---|
taskId | string |
Returns
Promise<boolean>
Defined in
core/src/ai/AIClient.ts:70 (opens in a new tab)
serializeModelInput
▸ Private serializeModelInput(«destructured»): ModelInput
The executor names the model type type.
Parameters
| Name | Type |
|---|---|
«destructured» | ModelInput |
Returns
ModelInput
Defined in
core/src/ai/AIClient.ts:17 (opens in a new tab)
setDefaultModel
▸ setDefaultModel(modelType, modelId): Promise<boolean>
Parameters
| Name | Type |
|---|---|
modelType | ModelType |
modelId | string |
Returns
Promise<boolean>
Defined in
core/src/ai/AIClient.ts:53 (opens in a new tab)
tasks
▸ tasks(): Promise<AITask[]>
Returns
Promise<AITask[]>
Defined in
core/src/ai/AIClient.ts:61 (opens in a new tab)
updateModel
▸ updateModel(modelId, model): Promise<boolean>
Parameters
| Name | Type |
|---|---|
modelId | string |
model | ModelInput |
Returns
Promise<boolean>
Defined in
core/src/ai/AIClient.ts:45 (opens in a new tab)
updateTask
▸ updateTask(taskId, task): Promise<AITask>
Parameters
| Name | Type |
|---|---|
taskId | string |
task | AITask |
Returns
Promise<AITask>