Skip to content

watsonx.ai

WatsonxLLM #

Bases: BaseLLM

A wrapper class for interacting with a IBM watsonx.ai large language models (LLMs). For more information, see here.

Attributes:

Name Type Description
model str

The identifier of the LLM model to use (e.g., "openai/gpt-oss-120b", "meta-llama/llama-3-3-70b-instruct").

api_key str

API key used for authenticating with the LLM provider.

region Region

The region where watsonx.ai is hosted when using IBM Cloud. Defaults to us-south.

project_id str

The project ID in watsonx.ai.

space_id str

The space ID in watsonx.ai.

additional_kwargs dict[str, Any]

A dictionary of additional parameters passed to the LLM during completion. This allows customization of the request beyond the standard parameters.

callback_manager BaseObservability | None

(PromptMonitor, optional): The callback manager is used for observability.

completion #

completion(prompt: str, guardrails: bool = False, params: dict[str, Any] = {}, **kwargs: Any) -> CompletionResponse

Creates a completion for the provided prompt and parameters. Using OpenAI's standard endpoint (/completions).

Parameters:

Name Type Description Default
prompt str

The input prompt to generate a completion for.

required
guardrails bool

The detection filter for potentially hateful, abusive, and/or profane language (HAP).

False
params dict

MetaProps for text generation. Method-provided params override class-level params.

{}
**kwargs Any

Additional keyword arguments to customize the LLM completion request.

{}

chat_completion #

chat_completion(messages: list[ChatMessage | dict], params: dict[str, Any] = {}, **kwargs: Any) -> ChatResponse

Creates a chat completion for LLM. Using OpenAI's standard endpoint (/chat/completions).

Parameters:

Name Type Description Default
messages list[ChatMessage]

A list of chat messages as input for the LLM.

required
params dict

MetaProps for text generation. Method-provided params override class-level params.

{}
**kwargs Any

Additional keyword arguments to customize the LLM completion request.

{}