fix: anthropic Model component base url empty issue (#7872)
* Update anthropic.py * updates to templates * [autofix.ci] apply automated fixes * update the templates * Refactor Anthropic API URL handling to use a constant. Introduced DEFAULT_ANTHROPIC_API_URL in anthropic_constants.py and updated references in anthropic.py for improved maintainability and clarity. * [autofix.ci] apply automated fixes * Refactor AnthropicModelComponent to streamline API URL handling. Removed unnecessary base_url checks and ensured consistent use of DEFAULT_ANTHROPIC_API_URL for improved clarity and maintainability. * [autofix.ci] apply automated fixes * Fix base_url check in update_build_config to ensure key existence before accessing value * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
99d9a52bd9
commit
c5306643bb
5 changed files with 20 additions and 12 deletions
|
|
@ -28,3 +28,6 @@ DEPRECATED_MODELS = [
|
|||
"claude-3-5-haiku-20241022",
|
||||
"claude-3-haiku-20240307",
|
||||
]
|
||||
|
||||
|
||||
DEFAULT_ANTHROPIC_API_URL = "https://api.anthropic.com"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
import requests
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.models.anthropic_constants import (
|
||||
ANTHROPIC_MODELS,
|
||||
DEFAULT_ANTHROPIC_API_URL,
|
||||
TOOL_CALLING_SUPPORTED_ANTHROPIC_MODELS,
|
||||
TOOL_CALLING_UNSUPPORTED_ANTHROPIC_MODELS,
|
||||
)
|
||||
|
|
@ -58,8 +59,9 @@ class AnthropicModelComponent(LCModelComponent):
|
|||
name="base_url",
|
||||
display_name="Anthropic API URL",
|
||||
info="Endpoint of the Anthropic API. Defaults to 'https://api.anthropic.com' if not specified.",
|
||||
value="https://api.anthropic.com",
|
||||
value=DEFAULT_ANTHROPIC_API_URL,
|
||||
real_time_refresh=True,
|
||||
advanced=True,
|
||||
),
|
||||
BoolInput(
|
||||
name="tool_model_enabled",
|
||||
|
|
@ -88,7 +90,7 @@ class AnthropicModelComponent(LCModelComponent):
|
|||
anthropic_api_key=self.api_key,
|
||||
max_tokens_to_sample=self.max_tokens,
|
||||
temperature=self.temperature,
|
||||
anthropic_api_url=self.base_url,
|
||||
anthropic_api_url=DEFAULT_ANTHROPIC_API_URL,
|
||||
streaming=self.stream,
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
@ -125,7 +127,7 @@ class AnthropicModelComponent(LCModelComponent):
|
|||
model_with_tool = ChatAnthropic(
|
||||
model=model, # Use the current model being checked
|
||||
anthropic_api_key=self.api_key,
|
||||
anthropic_api_url=self.base_url,
|
||||
anthropic_api_url=cast(str, self.base_url) or DEFAULT_ANTHROPIC_API_URL,
|
||||
)
|
||||
|
||||
if (
|
||||
|
|
@ -160,6 +162,9 @@ class AnthropicModelComponent(LCModelComponent):
|
|||
return None
|
||||
|
||||
def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None):
|
||||
if "base_url" in build_config and build_config["base_url"]["value"] is None:
|
||||
build_config["base_url"]["value"] = DEFAULT_ANTHROPIC_API_URL
|
||||
self.base_url = DEFAULT_ANTHROPIC_API_URL
|
||||
if field_name in {"base_url", "model_name", "tool_model_enabled", "api_key"} and field_value:
|
||||
try:
|
||||
if len(self.api_key) == 0:
|
||||
|
|
|
|||
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