-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_constants.py
More file actions
104 lines (79 loc) · 3.11 KB
/
Copy path_constants.py
File metadata and controls
104 lines (79 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from __future__ import annotations
import logging
import os
from typing import TYPE_CHECKING
from pydantic import BaseModel, Field
if TYPE_CHECKING:
pass
log = logging.getLogger(__name__)
logging.getLogger("opentelemetry.attributes").setLevel(logging.ERROR)
# Provider Profile Models
class LLMProfile(BaseModel):
"""Configuration for a single LLM model slot (main or fast)."""
model: str
temperature: float = Field(default=0.3, ge=0.0, le=2.0)
max_tokens: int = Field(default=4096, ge=1, le=131072)
class ProviderProfile(BaseModel):
"""Configuration for a complete LLM provider."""
name: str
description: str = ""
base_url: str
main: LLMProfile
fast: LLMProfile
env_key: str = "API_KEY"
@property
def main_model(self) -> str:
"""Full model identifier in provider/model format."""
if "/" in self.main.model:
return self.main.model
return f"{self.name}/{self.main.model}"
@property
def fast_model(self) -> str:
"""Full model identifier in provider/model format."""
if "/" in self.fast.model:
return self.fast.model
return f"{self.name}/{self.fast.model}"
# Built-in Provider Profiles
PROVIDERS: dict[str, ProviderProfile] = {
"openrouter": ProviderProfile(
name="openrouter",
description="OpenRouter - multi-provider routing (supports OpenAI, Anthropic, Google, etc.)",
base_url="https://openrouter.ai/api/v1",
main=LLMProfile(model="anthropic/claude-sonnet-4-20250514", temperature=0.3, max_tokens=4096),
fast=LLMProfile(model="openai/gpt-4o-mini", temperature=0.3, max_tokens=4096),
env_key="OPENROUTER_API_KEY",
),
"anthropic": ProviderProfile(
name="anthropic",
description="Anthropic - direct API access",
base_url="https://api.anthropic.com/v1",
main=LLMProfile(model="claude-sonnet-4-20250514", temperature=0.3, max_tokens=4096),
fast=LLMProfile(model="claude-haiku-3-5-20241022", temperature=0.3, max_tokens=4096),
env_key="ANTHROPIC_API_KEY",
),
"openai": ProviderProfile(
name="openai",
description="OpenAI - direct API access",
base_url="https://api.openai.com/v1",
main=LLMProfile(model="gpt-4o", temperature=0.3, max_tokens=4096),
fast=LLMProfile(model="gpt-4o-mini", temperature=0.3, max_tokens=4096),
env_key="OPENAI_API_KEY",
),
"ollama": ProviderProfile(
name="ollama",
description="Ollama - local LLM server",
base_url="http://localhost:11434/v1",
main=LLMProfile(model="llama3", temperature=0.3, max_tokens=4096),
fast=LLMProfile(model="llama3", temperature=0.3, max_tokens=4096),
env_key="",
),
}
# Review Loop Limits
_MAX_REVIEW_ITERATIONS = int(os.getenv("MAX_REVIEW_ITERATIONS", "5"))
# Cache Management (testing)
def clear_caches() -> None:
"""Clear all LLM/embedder caches. Useful in tests."""
from bandai.config.llm import get_llm # noqa: E402
from bandai.config.embedder import get_embedder # noqa: E402
get_llm.cache_clear()
get_embedder.cache_clear()