add claude

This commit is contained in:
Kevin Turcios 2025-12-22 03:34:07 -05:00
parent 8ff900e687
commit 89cc252d35
5 changed files with 28 additions and 1 deletions

5
AGENTS.md Normal file
View file

@ -0,0 +1,5 @@
# Agent Rules <!-- tessl-managed -->
@.tessl/RULES.md follow the [instructions](.tessl/RULES.md)

View file

@ -8,3 +8,5 @@ AZURE_API_BASE=
# To run in local mode, set OPENAI_API_TYPE anything other than azure
OPENAI_API_TYPE=
OPENAI_API_KEY=
AZURE_ANTHROPIC_API_KEY=
AZURE_ANTHROPIC_ENDPOINT=https://codeflash-anthropic-resource.openai.azure.com/anthropic

View file

@ -54,11 +54,18 @@ def create_llm_client(model_type: Literal["openai", "anthropic", "google"]) -> A
os.environ.get("ANTHROPIC_API_KEY"),
os.environ.get("GEMINI_API_KEY"),
)
# Azure Anthropic endpoint configuration
azure_anthropic_api_key = os.environ.get("AZURE_ANTHROPIC_API_KEY")
azure_anthropic_endpoint = os.environ.get("AZURE_ANTHROPIC_ENDPOINT", "https://codeflash-anthropic-resource.openai.azure.com/anthropic")
if model_type == "openai" and azure_api_key and openai_api_type == "azure" and openai_api_base_url:
# check for azure first
return AsyncOpenAI(api_key=azure_api_key, base_url=openai_api_base_url)
if model_type == "openai" and openai_key:
return AsyncOpenAI(api_key=openai_key) # baseurl not needed for regular openai
if model_type == "anthropic" and azure_anthropic_api_key:
# Azure Anthropic endpoint takes precedence
return AsyncOpenAI(api_key=azure_anthropic_api_key, base_url=azure_anthropic_endpoint)
if model_type == "anthropic" and anthropic_key:
return AsyncOpenAI(api_key=anthropic_key, base_url="https://api.anthropic.com/v1/")
# # for future use : gemini supported only via GEMINI_API_KEY at the moment, todo for vertex ai

View file

@ -93,6 +93,16 @@ class Anthropic_Claude_4(LLM):
output_cost: float = 15.00
# AF = Azure Foundry
@dataclass
class Anthropic_Claude_Sonnet_4_5_AF(LLM):
name: str = "claude-sonnet-4-5"
model_type: Literal["openai", "anthropic", "google"] = "anthropic"
max_tokens: int = 200000
input_cost: float = 3.00
output_cost: float = 15.00
@dataclass
class OpenAI_GPT_4_1(LLM):
# name: str = "azure/gpt-4.1"
@ -194,12 +204,14 @@ def _get_openai_model() -> LLM:
def _get_anthropic_model() -> LLM:
"""Returns Anthropic Claude 4 if available, otherwise falls back to OpenAI GPT-4.1.
"""Returns Anthropic Claude model prioritizing Azure Foundry, otherwise falls back to OpenAI GPT-4.1.
Returns:
LLM: The appropriate model instance based on available API keys.
""" # noqa: D401
if os.environ.get("AZURE_ANTHROPIC_API_KEY"):
return Anthropic_Claude_Sonnet_4_5_AF()
if os.environ.get("ANTHROPIC_API_KEY"):
return Anthropic_Claude_4()
# Fall back to OpenAI if Anthropic not available

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import logging
import uuid
from pathlib import Path
from typing import TYPE_CHECKING