fix: correct indentation issue in PythonCodeStructuredTool and correct type for int and float inputs when updating custom component (#3323)
* enhancement: Update PythonCodeStructuredTool to create inputs automatically and accept global variables * [autofix.ci] apply automated fixes * feat: Create a tool to search using SearXNG * [autofix.ci] apply automated fixes * refactor: reorganize imports and type annotations in PythonCodeStructuredTool.py for clarity and consistency * refactor: clean up imports and enhance type annotations in SearXNGTool.py for improved readability and type safety * refactor: Improved PythonCodeStructuredTool to allow arguments to have any types * refactor: Formatted and refactored SearXNGTool * refactor: Allowed RunnableExecutor to stream output and changed its build method to asynchronous. * fix: correct indentation issue in PythonCodeStructuredTool * fix: correct type for int and float inputs when updating custom component * [autofix.ci] apply automated fixes * fix: change Tool to StructuredTool due to arguments in SearXNGTool * refactor(endpoints.py): remove duplicate imports of loguru and sqlmodel to improve code readability and maintainability --------- Co-authored-by: Haseong Kim <dynaferkim@gmail.com> 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
4bcc560f01
commit
de96aee509
4 changed files with 20 additions and 16 deletions
|
|
@ -6,9 +6,6 @@ from uuid import UUID
|
|||
|
||||
import sqlalchemy as sa
|
||||
from fastapi import APIRouter, BackgroundTasks, Body, Depends, HTTPException, Request, UploadFile, status
|
||||
from loguru import logger
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from langflow.api.v1.schemas import (
|
||||
ConfigResponse,
|
||||
CustomComponentRequest,
|
||||
|
|
@ -48,6 +45,8 @@ from langflow.services.task.service import TaskService
|
|||
from langflow.services.telemetry.schema import RunPayload
|
||||
from langflow.services.telemetry.service import TelemetryService
|
||||
from langflow.utils.version import get_version_info
|
||||
from loguru import logger
|
||||
from sqlmodel import Session, select
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.cache.base import CacheService
|
||||
|
|
@ -592,7 +591,15 @@ async def custom_component_update(
|
|||
if hasattr(cc_instance, "set_attributes"):
|
||||
template = code_request.get_template()
|
||||
params = {
|
||||
key: value_dict.get("value") for key, value_dict in template.items() if isinstance(value_dict, dict)
|
||||
key: value_dict.get("value")
|
||||
if value_dict.get("_input_type") != "IntInput"
|
||||
else (
|
||||
int(value_dict.get("value")) # type: ignore
|
||||
if value_dict.get("_input_type") != "FloatInput"
|
||||
else float(value_dict.get("value")) # type: ignore
|
||||
)
|
||||
for key, value_dict in template.items()
|
||||
if isinstance(value_dict, dict)
|
||||
}
|
||||
load_from_db_fields = [
|
||||
field_name
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class CreateDataComponent(Component):
|
|||
display_name="Number of Fields",
|
||||
info="Number of fields to be added to the record.",
|
||||
real_time_refresh=True,
|
||||
value=0,
|
||||
range_spec=RangeSpec(min=1, max=15, step=1, step_type="int"),
|
||||
),
|
||||
MessageTextInput(name="text_key", display_name="Text Key", info="Key to be used as text.", advanced=True),
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ import json
|
|||
from typing import Any
|
||||
|
||||
from langchain.agents import Tool
|
||||
from langflow.base.langchain_utilities.model import LCToolComponent
|
||||
from langflow.inputs.inputs import MultilineInput, MessageTextInput, BoolInput, DropdownInput, HandleInput, FieldTypes
|
||||
from langchain_core.tools import StructuredTool
|
||||
from pydantic.v1 import Field, create_model
|
||||
from pydantic.v1.fields import Undefined
|
||||
|
||||
from langflow.base.langchain_utilities.model import LCToolComponent
|
||||
from langflow.inputs.inputs import BoolInput, DropdownInput, FieldTypes, HandleInput, MessageTextInput, MultilineInput
|
||||
from langflow.io import Output
|
||||
from langflow.schema import Data
|
||||
from langflow.schema.dotdict import dotdict
|
||||
|
|
@ -259,12 +259,8 @@ class PythonCodeStructuredTool(LCToolComponent):
|
|||
|
||||
for default in node.args.defaults:
|
||||
if (
|
||||
(arg.lineno is not None and default.lineno is not None and arg.lineno > default.lineno)
|
||||
or (
|
||||
arg.col_offset is not None
|
||||
and default.col_offset is not None
|
||||
and arg.col_offset > default.col_offset
|
||||
)
|
||||
arg.lineno > default.lineno
|
||||
or arg.col_offset > default.col_offset
|
||||
or (
|
||||
arg.end_lineno is not None
|
||||
and default.end_lineno is not None
|
||||
|
|
@ -290,8 +286,8 @@ class PythonCodeStructuredTool(LCToolComponent):
|
|||
func_arg["annotation"] = annotation_line
|
||||
if isinstance(func_arg["annotation"], str) and func_arg["annotation"].count("=") > 0:
|
||||
func_arg["annotation"] = "=".join(func_arg["annotation"].split("=")[:-1]).strip()
|
||||
if isinstance(func["args"], list):
|
||||
func["args"].append(func_arg)
|
||||
if isinstance(func["args"], list):
|
||||
func["args"].append(func_arg)
|
||||
functions.append(func)
|
||||
|
||||
return classes, functions
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import json
|
|||
from pydantic.v1 import Field, create_model
|
||||
|
||||
from langchain.agents import Tool
|
||||
from langchain_core.tools import StructuredTool
|
||||
from langflow.base.langchain_utilities.model import LCToolComponent
|
||||
from langflow.inputs import MessageTextInput, MultiselectInput, DropdownInput, IntInput
|
||||
from langflow.schema.dotdict import dotdict
|
||||
|
|
@ -130,12 +131,11 @@ class SearXNGToolComponent(LCToolComponent):
|
|||
|
||||
SearxSearchSchema = create_model("SearxSearchSchema", **schema_fields) # type: ignore
|
||||
|
||||
tool = Tool.from_function(
|
||||
tool = StructuredTool.from_function(
|
||||
func=_local["SearxSearch"].search,
|
||||
args_schema=SearxSearchSchema,
|
||||
name="searxng_search_tool",
|
||||
description="A tool that searches for tools using SearXNG.\nThe available categories are: "
|
||||
+ ", ".join(self.categories),
|
||||
)
|
||||
self.status = tool
|
||||
return tool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue