@ibm-cloud/watsonx-ai
Version:
IBM watsonx.ai Node.js SDK
213 lines • 8.5 kB
text/typescript
/**
* (C) Copyright IBM Corp. 2025-2026.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
import type { FunctionCall, ChatsToolCall } from "./tools.mjs";
export interface ChatsMessagesInput {
/** Name of a function to call or a participant of conversation to establish difference */
name?: string;
/** Content of a user message. */
content?: string | Record<string, any>;
/** Role of the messages author. */
role: string;
}
/** A message of a supported type for a chat completion. */
export type ChatsMessage = ChatsUserMessage | ChatsDeveloperMessage | ChatsSystemMessage | ChatsAssistantMessage | ChatsToolMessage | ChatsFunctionMessage | ChatsMessagesInput;
/**
* An object specifying the format that the model must output.
*
* - Setting to `{ "type": "json_schema", "json_schema": {...} }` enables [Structured
* Outputs][Structured Outputs] which ensures the model will match your supplied JSON schema.
* - Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model
* generates is valid JSON.
*
* Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a
* system or user message. Without this, the model may generate an unending stream of whitespace
* until the generation reaches the token limit, resulting in a long-running and seemingly "stuck"
* request. Also note that the message content may be partially cut off if `"finish_reason"` is set
* to `"length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded
* the max context length.
*
* [Structured Outputs]: https://platform.openai.com/docs/guides/structured-outputs.
*/
/** A content part with type "input_audio" that represents input audio in a chat request message. */
export interface ChatsUserContentAudio {
/** Type of the content part, in this case should always be "input_audio". */
type: 'audio';
/** The input audio data. */
input_audio: string;
}
/** A content part with type "input_url" that represents inout url in a request message. */
export interface ChatsUserContentImage {
/** ImageURL is the URL of the image. */
type: 'image';
/** Type of the content part, in this case should always be "image_url". */
input_url: string;
}
/** A content part with type "text" that represents text content in a request or response message. */
export interface ChatsUserContentText {
/** Type of the content part, in this case should always be "text". */
type: 'text';
/** Text contents of this part of the message. */
text: string;
}
/**
* An array of content parts that makes up the content of an assistant message. Can be one or more
* of type "text", "image", or "audio".
*/
/** Part of content for a user chat message. */
export type ChatsUserContent = string | ChatsUserContentAudio[] | ChatsUserContentImage[] | ChatsUserContentText[];
/** An assistant message in a chat. */
export interface ChatsAssistantMessage {
/** Data about a previous audio response from the model. */
audio?: ChatsAssistantAudio;
/** Content of an assistant message. Required unless `tool_calls` or `function_call` are specified. */
content?: string | ChatsTextContentPart[];
/**
* The name and arguments of a function that should be called, as generated by the model.
*
* Deprecated: `function_call` has been deprecated by OpenAI and replaced by `tool_calls`.
*/
function_call?: FunctionCall;
/**
* Name for the participant. Provides the model information to differentiate between participants
* of the same role.
*/
name?: string;
/** Refusal message by the assistant. */
refusal?: string;
/** Role of the messages author, in this case should always be `"assistant"`. */
role: 'assistant';
/** Array of tool calls generated by the model, such as function calls. */
tool_calls?: ChatsToolCall[];
}
/** A developer message in a chat. */
export interface ChatsDeveloperMessage {
/** Content of a developer message. */
content: string | ChatsTextContentPart[];
/**
* Name for the participant. Provides the model information to differentiate between participants
* of the same role.
*/
name?: string;
/** Role of the messages author, in this case should always be `"developer"`. */
role: 'developer';
}
/**
* A function message in a chat.
*
* Deprecated: Function messages have been deprecated by OpenAI in favor of tool messages.
*/
export interface ChatsFunctionMessage {
/** Content of the function message. Required but nullable. */
content: string;
/** Name of the function to call. */
name: string;
/** Role of the messages author, in this case should always be "function". */
role: 'function';
}
/** A system message in a chat. */
export interface ChatsSystemMessage {
/** Content of a system message. */
content: string | ChatsTextContentPart[];
/**
* Name for the participant. Provides the model information to differentiate between participants
* of the same role.
*/
name?: string;
/** Role of the messages author, in this case should always be `"system"`. */
role: 'system';
}
/** A tool message in a chat. */
export interface ChatsToolMessage {
/** Content of a tool message. */
content: string | ChatsTextContentPart[];
/** Role of the messages author, in this case should always be `"tool"`. */
role: 'tool';
/** ToolCallID is the tool call that this message is responding to. */
tool_call_id: string;
}
/** A user message in a chat. */
export interface ChatsUserMessage {
/** Content of a user message. */
content: ChatsUserContent;
/**
* Name for the participant. Provides the model information to differentiate between participants
* of the same role.
*/
name?: string;
/** Role of the messages author, in this case should always be `"user"`. */
role: 'user';
}
export interface ChatsAssistantAudio {
/** Unique identifier for a previous audio response from the model. */
id: string;
}
/** The audio input for an audio content part. */
export interface ChatsAudioInput {
/** The base64 encoded audio data. */
data: string;
/** Format of the encoded audio data. Currently supports `"wav"` and `"mp3"`. */
format: ChatsAudioInput.Constants.Format;
}
export declare namespace ChatsAudioInput {
namespace Constants {
/** Format of the encoded audio data. Currently supports `"wav"` and `"mp3"`. */
enum Format {
WAV = "wav",
MP3 = "mp3"
}
}
}
/** The URL of an image. */
export interface ChatsImageURL {
/**
* Detail specifies the detail level of an image.
*
* See [OpenAI's Vision
* guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding)
* for more information.
*/
detail?: ChatsImageURL.Constants.Detail;
/** URL is either a URL of the image or the base64 encoded image data. */
url: string;
}
export declare namespace ChatsImageURL {
namespace Constants {
/**
* Detail specifies the detail level of an image. See [OpenAI's Vision
* guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding)
* for more information.
*/
enum Detail {
AUTO = "auto",
LOW = "low",
HIGH = "high"
}
}
}
/** Part of a message's content that contains text. */
export interface ChatsTextContentPart {
/** Text content of this part of the message. */
text: string;
/** The type of a content part. */
type: ChatsTextContentPart.Constants.Type;
}
export declare namespace ChatsTextContentPart {
namespace Constants {
/** The type of a content part. */
enum Type {
REFUSAL = "refusal"
}
}
}
//# sourceMappingURL=messages.d.mts.map