fix: Fix Anthropic output processing and update dependency (#8283)
* chore: update langchain-anthropic dependency to version 0.3.14 and adjust revision in uv.lock * fix: add workaround for handling function calling in Anthropic output processing * Fix indentation Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: remove duplicate error message in _extract_output_text function * fix: update _build_llm_model to handle missing attributes gracefully * fix: handle max_tokens default value and improve error handling in AnthropicModelComponent * fix: enhance input handling in Component class to manage deepcopy errors * fix: add 'no_blockbuster' marker to pytest configuration for improved test control * fix: refactor agent component tests to include all OpenAI and Anthropic models, improving validation and error reporting * fix: update agent components to include pydantic validation and improve error handling across multiple starter projects * fix: set default max_tokens value in AnthropicModelComponent and improve API URL handling * fix: enhance error reporting in AgentComponent tests by capturing exceptions and response discrepancies for all Anthropic models * chore: update package versions in uv.lock, including alembic, arize-phoenix-otel, bce-python-sdk, boto3-stubs, botocore-stubs, tornado, and others for improved compatibility and features * fix: update agent components across multiple starter projects to include new imports and improve error handling * fix: streamline max_tokens handling in AnthropicModelComponent for improved clarity and robustness * [autofix.ci] apply automated fixes * fix: update artifacts_raw type to allow None for better flexibility * fix: initialize artifacts_raw as an empty dict if None to prevent errors * fix: specify type for similarity_score to enhance type safety and clarity * fix: refactor JSON parsing to improve variable naming and clarity * fix: skip flaky test in Portfolio Website Code Generator until stabilized --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
This commit is contained in:
parent
ae6f3429f0
commit
8fb9750a7b
32 changed files with 923 additions and 862 deletions
|
|
@ -45,7 +45,7 @@ load_dotenv()
|
|||
|
||||
@pytest.fixture(autouse=True)
|
||||
def blockbuster(request):
|
||||
if "benchmark" in request.keywords:
|
||||
if "benchmark" in request.keywords or "no_blockbuster" in request.keywords:
|
||||
yield
|
||||
else:
|
||||
with blockbuster_ctx() as bb:
|
||||
|
|
@ -78,6 +78,7 @@ def blockbuster(request):
|
|||
|
||||
for func in ["os.stat", "os.path.abspath", "os.scandir"]:
|
||||
bb.functions[func].can_block_in("alembic/util/pyfiles.py", "load_python_file")
|
||||
bb.functions[func].can_block_in("dotenv/main.py", "find_dotenv")
|
||||
|
||||
for func in ["os.path.abspath", "os.scandir"]:
|
||||
bb.functions[func].can_block_in("alembic/script/base.py", "_load_revisions")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any
|
|||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from dotenv import load_dotenv
|
||||
from langflow.base.models.anthropic_constants import ANTHROPIC_MODELS
|
||||
from langflow.base.models.model_input_constants import MODEL_PROVIDERS_DICT
|
||||
from langflow.base.models.openai_constants import (
|
||||
OPENAI_MODEL_NAMES,
|
||||
|
|
@ -112,10 +112,8 @@ class TestAgentComponentWithClient(ComponentTestBaseWithClient):
|
|||
return []
|
||||
|
||||
@pytest.mark.api_key_required
|
||||
@pytest.mark.no_blockbuster
|
||||
async def test_agent_component_with_calculator(self):
|
||||
# Mock inputs
|
||||
load_dotenv()
|
||||
|
||||
# Now you can access the environment variables
|
||||
api_key = os.getenv("OPENAI_API_KEY")
|
||||
tools = [CalculatorToolComponent().build_tool()] # Use the Calculator component as a tool
|
||||
|
|
@ -138,24 +136,64 @@ class TestAgentComponentWithClient(ComponentTestBaseWithClient):
|
|||
assert "4" in response.data.get("text")
|
||||
|
||||
@pytest.mark.api_key_required
|
||||
@pytest.mark.no_blockbuster
|
||||
async def test_agent_component_with_all_openai_models(self):
|
||||
# Mock inputs
|
||||
load_dotenv()
|
||||
api_key = os.getenv("OPENAI_API_KEY")
|
||||
tools = [CalculatorToolComponent().build_tool()] # Use the Calculator component as a tool
|
||||
input_value = "What is 2 + 2?"
|
||||
|
||||
# Iterate over all OpenAI models
|
||||
failed_models = []
|
||||
for model_name in OPENAI_MODEL_NAMES + OPENAI_REASONING_MODEL_NAMES:
|
||||
# Initialize the AgentComponent with mocked inputs
|
||||
tools = [CalculatorToolComponent().build_tool()] # Use the Calculator component as a tool
|
||||
agent = AgentComponent(
|
||||
tools=tools,
|
||||
input_value=input_value,
|
||||
api_key=api_key,
|
||||
model_name=model_name,
|
||||
llm_type="OpenAI",
|
||||
agent_llm="OpenAI",
|
||||
_session_id=str(uuid4()),
|
||||
)
|
||||
|
||||
response = await agent.message_response()
|
||||
assert "4" in response.data.get("text"), f"Failed for model: {model_name}"
|
||||
if "4" not in response.data.get("text"):
|
||||
failed_models.append(model_name)
|
||||
|
||||
assert not failed_models, f"The following models failed the test: {failed_models}"
|
||||
|
||||
@pytest.mark.api_key_required
|
||||
@pytest.mark.no_blockbuster
|
||||
async def test_agent_component_with_all_anthropic_models(self):
|
||||
# Mock inputs
|
||||
api_key = os.getenv("ANTHROPIC_API_KEY")
|
||||
input_value = "What is 2 + 2?"
|
||||
|
||||
# Iterate over all Anthropic models
|
||||
failed_models = {}
|
||||
|
||||
for model_name in ANTHROPIC_MODELS:
|
||||
try:
|
||||
# Initialize the AgentComponent with mocked inputs
|
||||
tools = [CalculatorToolComponent().build_tool()]
|
||||
agent = AgentComponent(
|
||||
tools=tools,
|
||||
input_value=input_value,
|
||||
api_key=api_key,
|
||||
model_name=model_name,
|
||||
agent_llm="Anthropic",
|
||||
_session_id=str(uuid4()),
|
||||
)
|
||||
|
||||
response = await agent.message_response()
|
||||
response_text = response.data.get("text", "")
|
||||
|
||||
if "4" not in response_text:
|
||||
failed_models[model_name] = f"Expected '4' in response but got: {response_text}"
|
||||
|
||||
except Exception as e: # noqa: BLE001
|
||||
failed_models[model_name] = f"Exception occurred: {e!s}"
|
||||
|
||||
assert not failed_models, "The following models failed the test:\n" + "\n".join(
|
||||
f"{model}: {error}" for model, error in failed_models.items()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue