37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import os
|
|
from typing import Any, Optional
|
|
|
|
from langchain_anthropic import ChatAnthropic
|
|
|
|
from .base_client import BaseLLMClient
|
|
from .validators import validate_model
|
|
|
|
|
|
class AnthropicClient(BaseLLMClient):
|
|
"""Client for Anthropic Claude models."""
|
|
|
|
def __init__(self, model: str, base_url: Optional[str] = None, **kwargs):
|
|
super().__init__(model, base_url, **kwargs)
|
|
|
|
def get_llm(self) -> Any:
|
|
"""Return configured ChatAnthropic instance."""
|
|
import certifi
|
|
|
|
# Fix SSL certificate path issue on Windows with conda
|
|
ssl_cert_file = os.environ.get("SSL_CERT_FILE", "")
|
|
if ssl_cert_file and not os.path.exists(ssl_cert_file):
|
|
os.environ.pop("SSL_CERT_FILE", None)
|
|
os.environ["SSL_CERT_FILE"] = certifi.where()
|
|
|
|
llm_kwargs = {"model": self.model}
|
|
|
|
for key in ("timeout", "max_retries", "api_key", "max_tokens", "callbacks"):
|
|
if key in self.kwargs:
|
|
llm_kwargs[key] = self.kwargs[key]
|
|
|
|
return ChatAnthropic(**llm_kwargs)
|
|
|
|
def validate_model(self) -> bool:
|
|
"""Validate model for Anthropic."""
|
|
return validate_model("anthropic", self.model)
|