foundry-local-sdk / ChatClient
Client for performing chat completions with a loaded model. Follows the OpenAI Chat Completion API structure.
settings: ChatClientSettings;Configuration settings for chat completions.
completeChat(messages): Promise<any>;Performs a synchronous chat completion.
| Parameter | Type | Description |
|---|---|---|
messages |
any[] |
An array of message objects (e.g., { role: 'user', content: 'Hello' }). |
Promise<any>
The chat completion response object.
Error - If messages or tools are invalid or completion fails.
completeChat(messages, tools): Promise<any>;Performs a synchronous chat completion.
| Parameter | Type | Description |
|---|---|---|
messages |
any[] |
An array of message objects (e.g., { role: 'user', content: 'Hello' }). |
tools |
any[] |
An array of tool objects (e.g. { type: 'function', function: { name: 'get_apps', description: 'Returns a list of apps available on the system' } }). |
Promise<any>
The chat completion response object.
Error - If messages or tools are invalid or completion fails.
completeStreamingChat(messages): AsyncIterable<any>;Performs a streaming chat completion, returning an async iterable of chunks.
| Parameter | Type | Description |
|---|---|---|
messages |
any[] |
An array of message objects. |
AsyncIterable<any>
An async iterable that yields parsed streaming response chunks.
Error - If messages or tools are invalid, or streaming fails.
// Without tools:
for await (const chunk of chatClient.completeStreamingChat(messages)) {
const content = chunk.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
}
// With tools:
for await (const chunk of chatClient.completeStreamingChat(messages, tools)) {
const content = chunk.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
}completeStreamingChat(messages, tools): AsyncIterable<any>;Performs a streaming chat completion, returning an async iterable of chunks.
| Parameter | Type | Description |
|---|---|---|
messages |
any[] |
An array of message objects. |
tools |
any[] |
An optional array of tool objects. |
AsyncIterable<any>
An async iterable that yields parsed streaming response chunks.
Error - If messages or tools are invalid, or streaming fails.
// Without tools:
for await (const chunk of chatClient.completeStreamingChat(messages)) {
const content = chunk.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
}
// With tools:
for await (const chunk of chatClient.completeStreamingChat(messages, tools)) {
const content = chunk.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
}