refactor(meet-kevin): switch LLM analyzer to OpenRouter via OpenAI SDK
User's Vault has openrouter_api_key but no direct sk-ant-* Anthropic key. OpenRouter passes through Claude Sonnet 4.6 (~3% markup over Anthropic list pricing) and matches the existing gpt_mini_endpoint pattern used by recruiter-responder. - Replace anthropic.AsyncAnthropic with openai.AsyncOpenAI + base_url - Convert Anthropic tool-use API to OpenAI function-calling - System prompt unchanged (analyst instructions are model-agnostic) - Drop cache_control (not in OpenAI API); revisit later if cost matters - Model slug: anthropic/claude-sonnet-4.5 (OpenRouter's current Claude tier) - Pricing: $3.10/M input, $15.50/M output (OpenRouter pass-through) - Config field anthropic_api_key -> openrouter_api_key - pyproject extras: anthropic>=0.40 -> openai>=1.50 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
3c20c8c12c
commit
89f01ad9c0
5 changed files with 244 additions and 216 deletions
|
|
@ -16,7 +16,7 @@ from datetime import timezone
|
|||
from decimal import Decimal
|
||||
|
||||
import httpx
|
||||
from anthropic import AsyncAnthropic
|
||||
from openai import AsyncOpenAI
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert
|
||||
|
||||
|
|
@ -179,10 +179,17 @@ async def run() -> None:
|
|||
# Database
|
||||
engine, session_factory = create_db(config)
|
||||
|
||||
# Anthropic client + LLM analyzer
|
||||
anthropic = AsyncAnthropic(api_key=config.anthropic_api_key)
|
||||
# OpenRouter client + LLM analyzer
|
||||
client = AsyncOpenAI(
|
||||
api_key=config.openrouter_api_key,
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
default_headers={
|
||||
"HTTP-Referer": "https://trading.viktorbarzin.me",
|
||||
"X-Title": "trading-bot meet-kevin",
|
||||
},
|
||||
)
|
||||
analyzer = LlmAnalyzer(
|
||||
client=anthropic,
|
||||
client=client,
|
||||
model=config.meet_kevin_llm_model,
|
||||
prompt_version=config.meet_kevin_prompt_version,
|
||||
)
|
||||
|
|
@ -241,7 +248,7 @@ async def run() -> None:
|
|||
except asyncio.TimeoutError:
|
||||
pass # Normal timeout — loop again
|
||||
finally:
|
||||
await anthropic.close()
|
||||
await client.close()
|
||||
await engine.dispose()
|
||||
logger.info("meet-kevin-watcher stopped gracefully")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue