feat: update Anthropic Tool calling model list and filters (#7630)
* update to models * Update anthropic_constants.py * Update anthropic_constants.py * Update anthropic.py * update template
This commit is contained in:
parent
b69175086e
commit
67f744cdf2
5 changed files with 58 additions and 24 deletions
|
|
@ -1,10 +1,30 @@
|
|||
ANTHROPIC_MODELS = [
|
||||
# all the models below support tool calling also
|
||||
"claude-3-7-sonnet-latest",
|
||||
"claude-3-5-sonnet-latest",
|
||||
"claude-3-5-haiku-latest",
|
||||
"claude-3-opus-latest",
|
||||
"claude-3-5-sonnet-20240620",
|
||||
"claude-3-5-sonnet-20241022",
|
||||
"claude-3-5-haiku-20241022",
|
||||
"claude-3-sonnet-20240229",
|
||||
"claude-3-haiku-20240307",
|
||||
]
|
||||
|
||||
TOOL_CALLING_SUPPORTED_ANTHROPIC_MODELS = [
|
||||
# all the models below support tool calling also
|
||||
"claude-3-7-sonnet-latest",
|
||||
"claude-3-5-sonnet-latest",
|
||||
"claude-3-5-haiku-latest",
|
||||
"claude-3-opus-latest",
|
||||
"claude-3-sonnet-20240229",
|
||||
"claude-3-haiku-20240307",
|
||||
]
|
||||
TOOL_CALLING_UNSUPPORTED_ANTHROPIC_MODELS = [
|
||||
"claude-2.1",
|
||||
"claude-2.0",
|
||||
]
|
||||
|
||||
DEPRECATED_MODELS = [
|
||||
"claude-3-5-sonnet-20240620",
|
||||
"claude-3-5-sonnet-20241022",
|
||||
"claude-3-5-haiku-20241022",
|
||||
"claude-3-haiku-20240307",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ from typing import Any
|
|||
import requests
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.models.anthropic_constants import ANTHROPIC_MODELS
|
||||
from langflow.base.models.anthropic_constants import (
|
||||
ANTHROPIC_MODELS,
|
||||
TOOL_CALLING_SUPPORTED_ANTHROPIC_MODELS,
|
||||
TOOL_CALLING_UNSUPPORTED_ANTHROPIC_MODELS,
|
||||
)
|
||||
from langflow.base.models.model import LCModelComponent
|
||||
from langflow.field_typing import LanguageModel
|
||||
from langflow.field_typing.range_spec import RangeSpec
|
||||
|
|
@ -99,24 +103,41 @@ class AnthropicModelComponent(LCModelComponent):
|
|||
|
||||
client = anthropic.Anthropic(api_key=self.api_key)
|
||||
models = client.models.list(limit=20).data
|
||||
model_ids = [model.id for model in models]
|
||||
model_ids = ANTHROPIC_MODELS + [model.id for model in models]
|
||||
except (ImportError, ValueError, requests.exceptions.RequestException) as e:
|
||||
logger.exception(f"Error getting model names: {e}")
|
||||
model_ids = ANTHROPIC_MODELS
|
||||
|
||||
if tool_model_enabled:
|
||||
try:
|
||||
from langchain_anthropic.chat_models import ChatAnthropic
|
||||
except ImportError as e:
|
||||
msg = "langchain_anthropic is not installed. Please install it with `pip install langchain_anthropic`."
|
||||
raise ImportError(msg) from e
|
||||
|
||||
# Create a new list instead of modifying while iterating
|
||||
filtered_models = []
|
||||
for model in model_ids:
|
||||
if model in TOOL_CALLING_SUPPORTED_ANTHROPIC_MODELS:
|
||||
filtered_models.append(model)
|
||||
continue
|
||||
|
||||
model_with_tool = ChatAnthropic(
|
||||
model=self.model_name,
|
||||
model=model, # Use the current model being checked
|
||||
anthropic_api_key=self.api_key,
|
||||
anthropic_api_url=self.base_url,
|
||||
)
|
||||
if not self.supports_tool_calling(model_with_tool):
|
||||
model_ids.remove(model)
|
||||
|
||||
if (
|
||||
not self.supports_tool_calling(model_with_tool)
|
||||
or model in TOOL_CALLING_UNSUPPORTED_ANTHROPIC_MODELS
|
||||
):
|
||||
continue
|
||||
|
||||
filtered_models.append(model)
|
||||
|
||||
return filtered_models
|
||||
|
||||
return model_ids
|
||||
|
||||
def _get_exception_message(self, exception: Exception) -> str | None:
|
||||
|
|
@ -151,6 +172,7 @@ class AnthropicModelComponent(LCModelComponent):
|
|||
ids = ANTHROPIC_MODELS
|
||||
build_config["model_name"]["options"] = ids
|
||||
build_config["model_name"]["value"] = ids[0]
|
||||
build_config["model_name"]["combobox"] = True
|
||||
except Exception as e:
|
||||
msg = f"Error getting model names: {e}"
|
||||
raise ValueError(msg) from e
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue