Skip to content

watsonx

% pip install novastack-llms-watsonx

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 str

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.

Example
from novastack.llms.watsonx import WatsonxLLM

llm = WatsonxLLM(model="openai/gpt-oss-120b", api_key="your_api_key_here")

completion #

completion(prompt: str, **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
**kwargs Any

Additional keyword arguments to customize the LLM completion request.

{}

chat_completion #

chat_completion(messages: list[ChatMessage | dict], **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
**kwargs Any

Additional keyword arguments to customize the LLM completion request.

{}

text_completion #

text_completion(prompt: str, **kwargs: Any) -> str

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

Parameters:

Name Type Description Default
prompt str

The input prompt to generate a completion for.

required
**kwargs Any

Additional keyword arguments to customize the LLM completion request.

{}