Azure OpenAI
Backend LLM Implementation
This section details the Azure OpenAI implementation of the BaseBackendLLM
interface.
memora.llm_backends.AzureOpenAIBackendLLM
AzureOpenAIBackendLLM(
azure_openai_client: AsyncAzureOpenAI = None,
model: str = "gpt-4o",
temperature: float = 0.7,
top_p: float = 1,
max_tokens: int = 1024,
)
Bases: BaseBackendLLM
PARAMETER | DESCRIPTION |
---|---|
azure_openai_client
|
A pre-initialized Async Azure OpenAI client
TYPE:
|
model
|
The name of the Azure OpenAI model to use
TYPE:
|
temperature
|
The temperature to use for sampling
TYPE:
|
top_p
|
The top_p value to use for sampling
TYPE:
|
max_tokens
|
The maximum number of tokens to generate
TYPE:
|
Example
from openai import AsyncAzureOpenAI
from memora.llm_backends import AzureOpenAIBackendLLM
azure_openai_backend_llm = AzureOpenAIBackendLLM(
azure_openai_client=AsyncAzureOpenAI(
azure_endpoint="AZURE_OPENAI_ENDPOINT",
api_key="AZURE_OPENAI_API_KEY",
api_version="API_VERSION", # e.g "2024-08-01-preview" or later
max_retries=3
)
)
Source code in memora/llm_backends/azure_openai_backend_llm.py
Attributes
get_model_kwargs
property
Returns dictionary of model configuration parameters
Functions
__call__
async
__call__(
messages: List[Dict[str, str]],
output_schema_model: Type[BaseModel] | None = None,
) -> Union[str, BaseModel]
Process messages and generate response (📌 Streaming is not supported, as full response is required at once)
PARAMETER | DESCRIPTION |
---|---|
messages
|
List of message dicts with role and content e.g [{"role": "user", "content": "Hello!"}, ...]
TYPE:
|
output_schema_model
|
Optional Pydantic base model for structured output (📌 Ensure the api version and selected model supportes this.)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[str, BaseModel]
|
Union[str, BaseModel]: Generated text response as a string, or an instance of the output schema model if specified |