|
9 | 9 | from openai import AsyncOpenAI |
10 | 10 | from pydantic import BaseModel |
11 | 11 |
|
| 12 | +from agent_memory_server.config import settings |
| 13 | + |
12 | 14 |
|
13 | 15 | logger = logging.getLogger(__name__) |
14 | 16 |
|
@@ -203,14 +205,21 @@ def total_tokens(self) -> int: |
203 | 205 | class AnthropicClientWrapper: |
204 | 206 | """Wrapper for Anthropic client""" |
205 | 207 |
|
206 | | - def __init__(self, api_key: str | None = None): |
| 208 | + def __init__(self, api_key: str | None = None, base_url: str | None = None): |
207 | 209 | """Initialize the Anthropic client""" |
208 | 210 | anthropic_api_key = api_key or os.environ.get("ANTHROPIC_API_KEY") |
| 211 | + anthropic_api_base = base_url or os.environ.get("ANTHROPIC_API_BASE") |
209 | 212 |
|
210 | 213 | if not anthropic_api_key: |
211 | 214 | raise ValueError("Anthropic API key is required") |
212 | 215 |
|
213 | | - self.client = anthropic.AsyncAnthropic(api_key=anthropic_api_key) |
| 216 | + if anthropic_api_base: |
| 217 | + self.client = anthropic.AsyncAnthropic( |
| 218 | + api_key=anthropic_api_key, |
| 219 | + base_url=anthropic_api_base, |
| 220 | + ) |
| 221 | + else: |
| 222 | + self.client = anthropic.AsyncAnthropic(api_key=anthropic_api_key) |
214 | 223 |
|
215 | 224 | async def create_chat_completion( |
216 | 225 | self, |
@@ -397,9 +406,15 @@ async def get_model_client( |
397 | 406 | model_config = get_model_config(model_name) |
398 | 407 |
|
399 | 408 | if model_config.provider == ModelProvider.OPENAI: |
400 | | - model = OpenAIClientWrapper(api_key=os.environ.get("OPENAI_API_KEY")) |
401 | | - if model_config.provider == ModelProvider.ANTHROPIC: |
402 | | - model = AnthropicClientWrapper(api_key=os.environ.get("ANTHROPIC_API_KEY")) |
| 409 | + model = OpenAIClientWrapper( |
| 410 | + api_key=settings.openai_api_key, |
| 411 | + base_url=settings.openai_api_base, |
| 412 | + ) |
| 413 | + elif model_config.provider == ModelProvider.ANTHROPIC: |
| 414 | + model = AnthropicClientWrapper( |
| 415 | + api_key=settings.anthropic_api_key, |
| 416 | + base_url=settings.anthropic_api_base, |
| 417 | + ) |
403 | 418 |
|
404 | 419 | if model: |
405 | 420 | _model_clients[model_name] = model |
|
0 commit comments