ai_sentinel.llm.OpenAIClient

class ai_sentinel.llm.OpenAIClient(base_url: str, model: str, api_key: str | None = 'EMPTY', timeout: float | None = 30.0, **kwargs)

Client implementation for Open Source LLM using a local server that offers compatibility with the OpenAI SDK

__init__(base_url: str, model: str, api_key: str | None = 'EMPTY', timeout: float | None = 30.0, **kwargs)

Methods

__init__(base_url, model[, api_key, timeout])

generate_text(prompt[, system_prompt, ...])

Generate a response from LLM based on the prompt and optional inputs (sync wrapper).

generate_text_async(prompt[, system_prompt, ...])

Generate a response from LLM based on the prompt and optional inputs (async).

validate()

Validate the provided API key by making a call to the provider (sync wrapper).

validate_async()

Validate the provided API key by making a call to the provider (async).

Attributes

info

Return clean information about the LLM Client configuration.

provider_name

Get the provider name

generate_text(prompt: str, system_prompt: str | None = None, context: list[dict[str, str]] | None = None, temperature: float | None = 0.7, **kwargs) LLMResponse

Generate a response from LLM based on the prompt and optional inputs (sync wrapper).

This is a synchronous wrapper around the async method that is safe to run in any environment, including Jupyter notebooks.

async generate_text_async(prompt: str, system_prompt: str | None = None, context: list[dict[str, str]] | None = None, temperature: float | None = 0.0, **kwargs) LLMResponse

Generate a response from LLM based on the prompt and optional inputs (async).

Warning: Implementations uses deprecated function “datetime.utcnow()”

Parameters: prompt (str): User input system_prompt (Optional[str]): System prompt to give the LLM as it’s role | default = None context (Optional[list[dict[str,str]]]): Conversation history | default = None temperature (Optional[float]): What sampling temperature to use | default = 0.7 **kwargs: Handles structured output ( ex. {‘response_format’: [Some Structure]} )

property info

Return clean information about the LLM Client configuration.

property provider_name: str

Get the provider name

validate() bool

Validate the provided API key by making a call to the provider (sync wrapper).

async validate_async() bool

Validate the provided API key by making a call to the provider (async). Return True if the API key is valid, False if not.