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
BaseLLMInterface
ABCAbstract 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
Dictionary of inference parameters (temperature, top_p, etc.) passed to the llm on each request.
Methods
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
List of Message objects representing the conversation history.
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
List of Message objects representing the conversation history.
A pydantic model class defining the output structure. The provider will transform this into the format required by its respective API.
Provider-specific keyword arguments to customise llm behaviour.
BaseLLMInterface.start
start() → NoneInitialise 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() → NoneShut 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.