Classes
CLASS WatsonxAIBackend
A generic backend class for watsonx SDK.
Args:
model_id: WatsonX model identifier. Defaults tomodel_ids.IBM_GRANITE_4_HYBRID_SMALL.formatter: Formatter for rendering components. Defaults to[TemplateFormatter](../formatters/template_formatter#class-templateformatter).base_url: URL for the WatsonX ML deployment endpoint; defaults to theWATSONX_URLenvironment variable.model_options: Default model options for generation requests.api_key: WatsonX API key; defaults to theWATSONX_API_KEYenvironment variable.project_id: WatsonX project ID; defaults to theWATSONX_PROJECT_IDenvironment variable.
to_mellea_model_opts_map_chats: Mapping from chat-endpoint option names to Mellea[ModelOption](model_options#class-modeloption)sentinel keys.from_mellea_model_opts_map_chats: Mapping from Mellea sentinel keys to chat-endpoint option names.to_mellea_model_opts_map_completions: Mapping from completions-endpoint option names to Mellea[ModelOption](model_options#class-modeloption)sentinel keys.from_mellea_model_opts_map_completions: Mapping from Mellea sentinel keys to completions-endpoint option names.
FUNC filter_chat_completions_kwargs
model_options: Model options dict that may contain non-chat keys.
- A dict containing only keys accepted by the WatsonX chat endpoint.
FUNC generate_from_chat_context
action: The component or content block to generate a completion for.ctx: The current generation context._format: Optional Pydantic model class for structured output decoding.model_options: Per-call model options.tool_calls: IfTrue, expose available tools and parse responses.
- ModelOutputThunk[C]: A thunk holding the (lazy) model output.
Exception: Ifactionis anALoraRequirement, which is not supported by this backend.RuntimeError: If not called from a thread with a running event loop.
FUNC processing
"message" key) or
streaming delta dict (with a "delta" key). Tool call parsing is
handled in the post-processing step.
Args:
mot: The output thunk being populated.chunk: A single response dict or streaming delta from the WatsonX API.
FUNC post_processing
mot: The output thunk to finalize.conversation: The chat conversation sent to the model, used for logging.tools: Available tools, keyed by name.seed: The random seed used during generation, orNone._format: The structured output format class used during generation, if any.
FUNC generate_from_raw
FUNC generate_from_raw
FUNC generate_from_raw
format parameter is not supported and will be ignored with a warning.
Args:
actions: Actions to generate completions for.ctx: The current generation context.format: Not supported; ignored with a warning.model_options: Per-call model options.tool_calls: Ignored; tool calling is not supported on this endpoint.
- list[ModelOutputThunk]: A list of model output thunks, one per action.