haive.core.models.llm.providers.ai21¶

AI21 Labs Provider Module.

This module implements the AI21 Labs language model provider for the Haive framework, supporting Jurassic models known for their strong performance on various NLP tasks.

The provider handles API key management, model configuration, and safe imports of the langchain-ai21 package dependencies.

Examples

Basic usage:

from haive.core.models.llm.providers.ai21 import AI21Provider

provider = AI21Provider(
    model="j2-ultra",
    temperature=0.7,
    max_tokens=1000
)
llm = provider.instantiate()

With custom parameters:

provider = AI21Provider(
    model="j2-grande-instruct",
    temperature=0.1,
    top_p=0.9,
    frequency_penalty=0.2
)

Classes¶

AI21Provider

AI21 Labs language model provider configuration.

Module Contents¶

class haive.core.models.llm.providers.ai21.AI21Provider(/, **data)¶

Bases: haive.core.models.llm.providers.base.BaseLLMProvider

AI21 Labs language model provider configuration.

This provider supports AI21’s Jurassic family of models including J2-Ultra, J2-Mid, and instruction-tuned variants optimized for various tasks.

Parameters:

data (Any)

provider¶

Always LLMProvider.AI21

Type:

LLMProvider

model¶

The AI21 model to use

Type:

str

temperature¶

Sampling temperature (0.0-2.0)

Type:

float

max_tokens¶

Maximum tokens in response

Type:

int

top_p¶

Nucleus sampling parameter

Type:

float

top_k_return¶

Number of top tokens to consider

Type:

int

frequency_penalty¶

Frequency penalty settings

Type:

dict

presence_penalty¶

Presence penalty settings

Type:

dict

count_penalty¶

Count penalty settings

Type:

dict

Examples

Ultra model for complex tasks:

provider = AI21Provider(
    model="j2-ultra",
    temperature=0.7,
    max_tokens=2000
)

Instruct model with penalties:

provider = AI21Provider(
    model="j2-grande-instruct",
    temperature=0.1,
    frequency_penalty={"scale": 0.2, "apply_to_whitespaces": False}
)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod get_models()¶

Get available AI21 models.

Return type:

list[str]

max_tokens: int | None = None¶

Get maximum total tokens for this model.