DSPy: The framework for programming—not prompting—language models
Python
feat: Add support for additional Anthropic models This commit updates the `Claude` class to support additional models provided by the Anthropic API:
Arbaaz-Mahmood8f5d0ec04f33
diff --git a/dsp/modules/anthropic.py b/dsp/modules/anthropic.pyindex e78e9d2d2..2ccf932d2 100644--- a/dsp/modules/anthropic.py+++ b/dsp/modules/anthropic.py@@ -45,15 +45,26 @@ class Claude(LM):):super().__init__(model)+try:from anthropic import Anthropicexcept ImportError as err:raise ImportError("Claude requires `pip install anthropic`.") from err+ supported_models = [+ "claude-instant-1.2",+ "claude-2.0",+ "claude-2.1",+ "claude-3-opus-20240229",+ "claude-3-haiku-20240307",+ "claude-3-sonnet-20240229",+ ]++ if model not in supported_models:+ raise ValueError(f"Unsupported model: {model}. Supported models are: {', '.join(supported_models)}")self.provider = "anthropic"self.api_key = api_key = os.environ.get("ANTHROPIC_API_KEY") if api_key is None else api_keyself.api_base = BASE_URL if api_base is None else api_base-self.kwargs = {"temperature": kwargs.get("temperature", 0.0),"max_tokens": min(kwargs.get("max_tokens", 4096), 4096),@@ -134,4 +145,4 @@ class Claude(LM):if only_completed and response.stop_reason == "max_tokens":continuecompletions = [c.text for c in response.content]- return completions+ return completions\ No newline at end of file