fix: add default models to Anthropic and make sure template is updated (#5839)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
64d82d407a
commit
050c12df35
19 changed files with 240 additions and 75 deletions
|
|
@ -1,9 +1,12 @@
|
|||
import inspect
|
||||
from typing import Any
|
||||
|
||||
from aiofile import async_open
|
||||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
from langflow.api.v1.schemas import UpdateCustomComponentRequest
|
||||
from langflow.components.agents.agent import AgentComponent
|
||||
from langflow.custom.utils import build_custom_component_template
|
||||
|
||||
|
||||
async def test_get_version(client: AsyncClient):
|
||||
|
|
@ -46,3 +49,59 @@ async def test_update_component_outputs(client: AsyncClient, logged_in_headers:
|
|||
assert response.status_code == status.HTTP_200_OK
|
||||
output_names = [output["name"] for output in result["outputs"]]
|
||||
assert "tool_output" in output_names
|
||||
|
||||
|
||||
async def test_update_component_model_name_options(client: AsyncClient, logged_in_headers: dict):
|
||||
"""Test that model_name options are updated when selecting a provider."""
|
||||
component = AgentComponent()
|
||||
component_node, cc_instance = build_custom_component_template(
|
||||
component,
|
||||
)
|
||||
|
||||
# Initial template with OpenAI as the provider
|
||||
template = component_node["template"]
|
||||
current_model_names = template["model_name"]["options"]
|
||||
|
||||
# load the code from the file at langflow.components.agents.agent.py asynchronously
|
||||
# we are at str/backend/tests/unit/api/v1/test_endpoints.py
|
||||
# find the file by using the class AgentComponent
|
||||
agent_component_file = inspect.getsourcefile(AgentComponent)
|
||||
async with async_open(agent_component_file, encoding="utf-8") as f:
|
||||
code = await f.read()
|
||||
|
||||
# Create the request to update the component
|
||||
request = UpdateCustomComponentRequest(
|
||||
code=code,
|
||||
frontend_node=component_node,
|
||||
field="agent_llm",
|
||||
field_value="Anthropic",
|
||||
template=template,
|
||||
)
|
||||
|
||||
# Make the request to update the component
|
||||
response = await client.post("api/v1/custom_component/update", json=request.model_dump(), headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
# Verify the response
|
||||
assert response.status_code == status.HTTP_200_OK, f"Response: {response.json()}"
|
||||
assert "template" in result
|
||||
assert "model_name" in result["template"]
|
||||
assert isinstance(result["template"]["model_name"]["options"], list)
|
||||
assert len(result["template"]["model_name"]["options"]) > 0, (
|
||||
f"Model names: {result['template']['model_name']['options']}"
|
||||
)
|
||||
assert current_model_names != result["template"]["model_name"]["options"], (
|
||||
f"Current model names: {current_model_names}, New model names: {result['template']['model_name']['options']}"
|
||||
)
|
||||
# Now test with Custom provider
|
||||
template["agent_llm"]["value"] = "Custom"
|
||||
request.field_value = "Custom"
|
||||
request.template = template
|
||||
|
||||
response = await client.post("api/v1/custom_component/update", json=request.model_dump(), headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
# Verify that model_name is not present for Custom provider
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert "template" in result
|
||||
assert "model_name" not in result["template"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue