Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

refacto: Centralize seed and temperature configurations

Clémence Lesnécea8d0e5e1a9
diff --git a/helpers/config_models/llm.py b/helpers/config_models/llm.py
index 1e5bbe7..598c37e 100644
--- a/helpers/config_models/llm.py
+++ b/helpers/config_models/llm.py
@@ -21,7 +21,9 @@ class AbstractPlatformModel(BaseModel):
}
context: int
model: str
+ seed: int = 42 # Reproducible results
streaming: bool
+ temperature: float = 0.0 # Most focused and deterministic
@abstractmethod
async def instance(
@@ -32,6 +34,7 @@ class AbstractPlatformModel(BaseModel):
class AzureOpenaiPlatformModel(AbstractPlatformModel):
_client: AsyncAzureOpenAI | None = None
+ api_version: str = "2024-06-01"
deployment: str
endpoint: str
@@ -40,7 +43,7 @@ class AzureOpenaiPlatformModel(AbstractPlatformModel):
self._client = AsyncAzureOpenAI(
**self._client_kwargs,
# Deployment
- api_version="2024-06-01",
+ api_version=self.api_version,
azure_deployment=self.deployment,
azure_endpoint=self.endpoint,
# Authentication
diff --git a/helpers/llm_worker.py b/helpers/llm_worker.py
index 6dfa2fe..bb594bc 100644
--- a/helpers/llm_worker.py
+++ b/helpers/llm_worker.py
@@ -166,8 +166,8 @@ async def _completion_stream_worker( # noqa: PLR0912
"max_tokens": max_tokens,
"messages": prompt,
"model": platform.model,
- "seed": 42, # Reproducible results
- "temperature": 0, # Most focused and deterministic
+ "seed": platform.seed,
+ "temperature": platform.temperature,
**extra,
} # Shared kwargs for both streaming and non-streaming
maximum_tokens_reached = False
@@ -345,8 +345,8 @@ async def _completion_sync_worker(
max_tokens=max_tokens,
messages=prompt,
model=platform.model,
- seed=42, # Reproducible results
- temperature=0, # Most focused and deterministic
+ seed=platform.seed,
+ temperature=platform.temperature,
**extra,
)
except BadRequestError as e:
diff --git a/tests/conftest.py b/tests/conftest.py
index 7e5cd7a..bd7955e 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -139,11 +139,11 @@ class DeepEvalAzureOpenAI(GPTModel):
_langchain_kwargs = {
# Repeatability
"model_kwargs": {
- "seed": 42,
+ "seed": platform.seed,
},
- "temperature": 0,
+ "temperature": platform.temperature,
# Deployment
- "api_version": "2023-12-01-preview",
+ "api_version": platform.api_version,
"azure_deployment": platform.deployment,
"azure_endpoint": platform.endpoint,
"model": platform.model,