panelini.panels.ai.utils.ai_interface

AI interface for interacting with various LLM providers.

Module Contents

Classes

AiInterface

Interface for interacting with AI models.

Functions

create_interface

Create an AI interface for any configured provider.

Data

API

panelini.panels.ai.utils.ai_interface.PROVIDER_CLASS_REGISTRY: dict[str, panelini.panels.ai.utils.ai_interface._ClientFactory]

None

class panelini.panels.ai.utils.ai_interface.AiInterface(provider: panelini.panels.ai.utils.config.ProviderConfig, model_name: str | panelini.panels.ai.utils.config.ModelConfig, temperature: float = 0.7, max_tokens: int = 4096, tools: list[langchain_core.tools.BaseTool] | None = None, system_message: str | None = None)[source]

Interface for interacting with AI models.

This class provides a unified interface for working with different LLM providers, supporting streaming responses, tool usage, and conversation history management.

Attributes: model: The underlying chat model instance provider: The model provider being used tools: List of tools available to the model conversation_history: List of messages in the conversation system_message: Optional system message for the conversation

Initialization

Initialize the AI interface.

Args: provider: The provider configuration model_name: The specific model to use (string or ModelConfig) temperature: Sampling temperature (0-1) max_tokens: Maximum tokens in response tools: Optional list of LangChain tools system_message: Optional system message for the conversation

add_tool(tool: langchain_core.tools.BaseTool) None[source]

Add a tool to the interface.

Args: tool: LangChain tool to add

clear_history() None[source]

Clear the conversation history.

async get_response(user_message: str, stream: bool = True) str | collections.abc.AsyncGenerator[str, None][source]

Get a response from the AI model.

Args: user_message: The user’s input message stream: Whether to stream the response

Returns: Either a complete response string or an async generator for streaming

Raises: Exception: If the model invocation fails

async get_response_with_tools(user_message: str) dict[str, Any][source]

Get a response that may include tool calls.

Args: user_message: The user’s input message

Returns: Dictionary containing response text and any tool calls

Raises: Exception: If the model invocation fails

panelini.panels.ai.utils.ai_interface.create_interface(provider: panelini.panels.ai.utils.config.ProviderConfig, model: str | panelini.panels.ai.utils.config.ModelConfig, temperature: float = 0.7, max_tokens: int = 4096, system_message: str | None = None, tools: list[langchain_core.tools.BaseTool] | None = None) panelini.panels.ai.utils.ai_interface.AiInterface[source]

Create an AI interface for any configured provider.

Args: provider: The provider configuration model: The model to use (string or ModelConfig) temperature: Sampling temperature max_tokens: Maximum tokens in response system_message: Optional system message tools: Optional list of tools

Returns: Configured AiInterface instance