yera.models.interfaces.llms.base

Base interface for LLM implementations.

This module defines the abstract BaseLLMInterface that all llm provider implementations must inherit from. It establishes the contract for:

  • Streaming chat completions (chat method)
  • Generating structured outputs conforming to a schema (make_struct method)
  • Managing llm client lifecycle (start/stop methods)

Concrete implementations (e.g., AnthropicLLM, OpenAILLM, AwsBedrockLLM) provide provider-specific implementations of these abstract methods whilst handling their respective API clients and configuration.

Symbols

class BaseLLMInterface — Abstract base interface for llm implementations.

BaseLLMInterface

Inherits: ABC

Abstract base interface for llm implementations.

Defines the contract that all concrete llm provider implementations must satisfy. Subclasses handle provider-specific client initialisation, authentication, and API interaction whilst conforming to the streaming chat and structured output methods defined here.

Attributes

kwargs
type: dict

Dictionary of inference parameters (temperature, top_p, etc.) passed to the llm on each request.

Methods

chat — Stream a chat completion response.
make_struct — Stream a structured output response conforming to a provided schema.
start — Initialise the llm client.
stop — Shut down and clear the llm client.

BaseLLMInterface.chat

chat(
    messages: list[Message],
    **kwargs,
) → Iterator[str]

Stream a chat completion response.

Abstract method that must be implemented by concrete llm providers. Sends a conversation to the llm and streams the response as text tokens.

Parameters

messages
type: list[Message]

List of Message objects representing the conversation history.

**kwargs
type: str | int | float | bool

Provider-specific keyword arguments to customise llm behaviour (e.g., temperature, top_p, max_tokens).

BaseLLMInterface.make_struct

make_struct(
    messages: list[Message],
    **kwargs,
) → Iterator[str]

Stream a structured output response conforming to a provided schema.

Abstract method that must be implemented by concrete llm providers. Generates a response that strictly conforms to the structure defined by the provided schema class.

Parameters

messages
type: list[Message]

List of Message objects representing the conversation history.

cls
type: type[TStruct]

A pydantic model class defining the output structure. The provider will transform this into the format required by its respective API.

**kwargs
type: str | float | int | bool

Provider-specific keyword arguments to customise llm behaviour.

BaseLLMInterface.start

start() → None

Initialise the llm client.

Lifecycle method called before making API requests. Concrete implementations override this to instantiate and configure their provider-specific client. Default implementation does nothing.

BaseLLMInterface.stop

stop() → None

Shut down and clear the llm client.

Lifecycle method called when finished with the llm. Concrete implementations override this to release resources and clean up the provider-specific client. Default implementation does nothing.