Add version module and update imports
This commit is contained in:
parent
73a23ca096
commit
b603d73c62
12 changed files with 25 additions and 34 deletions
|
|
@ -9,10 +9,7 @@ from typing import Optional
|
|||
import httpx
|
||||
import typer
|
||||
from dotenv import load_dotenv
|
||||
from multiprocess import ( # noqa
|
||||
Process, # noqa
|
||||
cpu_count, # noqa; type: ignore
|
||||
)
|
||||
from multiprocess import Process, cpu_count # type: ignore
|
||||
from rich import box
|
||||
from rich import print as rprint
|
||||
from rich.console import Console
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ def get_is_component_from_data(data: dict):
|
|||
|
||||
|
||||
async def check_langflow_version(component: StoreComponentCreate):
|
||||
from langflow.version import __version__ as current_version
|
||||
from langflow.version.version import __version__ as current_version # type: ignore
|
||||
|
||||
if not component.last_tested_version:
|
||||
component.last_tested_version = current_version
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ async def create_upload_file(
|
|||
# get endpoint to return version of langflow
|
||||
@router.get("/version")
|
||||
def get_version():
|
||||
from langflow.version import __version__
|
||||
from langflow.version import __version__ # type: ignore
|
||||
|
||||
return {"version": __version__}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from typing import List, Union
|
||||
from typing import List, Optional, Union, cast
|
||||
|
||||
from langchain.agents import AgentExecutor, BaseMultiActionAgent, BaseSingleActionAgent
|
||||
|
||||
from langchain_core.runnables import Runnable
|
||||
|
||||
from langflow.custom import CustomComponent
|
||||
|
|
@ -45,7 +44,7 @@ class LCAgentComponent(CustomComponent):
|
|||
inputs: str,
|
||||
input_variables: list[str],
|
||||
tools: List[Tool],
|
||||
memory: BaseMemory = None,
|
||||
memory: Optional[BaseMemory] = None,
|
||||
handle_parsing_errors: bool = True,
|
||||
output_key: str = "output",
|
||||
) -> Text:
|
||||
|
|
@ -53,7 +52,11 @@ class LCAgentComponent(CustomComponent):
|
|||
runnable = agent
|
||||
else:
|
||||
runnable = AgentExecutor.from_agent_and_tools(
|
||||
agent=agent, tools=tools, verbose=True, memory=memory, handle_parsing_errors=handle_parsing_errors
|
||||
agent=agent, # type: ignore
|
||||
tools=tools,
|
||||
verbose=True,
|
||||
memory=memory,
|
||||
handle_parsing_errors=handle_parsing_errors,
|
||||
)
|
||||
input_dict = {"input": inputs}
|
||||
for var in input_variables:
|
||||
|
|
@ -62,11 +65,11 @@ class LCAgentComponent(CustomComponent):
|
|||
result = await runnable.ainvoke(input_dict)
|
||||
self.status = result
|
||||
if output_key in result:
|
||||
return result.get(output_key)
|
||||
return cast(str, result.get(output_key))
|
||||
elif "output" not in result:
|
||||
if output_key != "output":
|
||||
raise ValueError(f"Output key not found in result. Tried '{output_key}' and 'output'.")
|
||||
else:
|
||||
raise ValueError("Output key not found in result. Tried 'output'.")
|
||||
|
||||
return result.get("output")
|
||||
return cast(str, result.get("output"))
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ class LCModelComponent(CustomComponent):
|
|||
if input_value:
|
||||
messages.append(HumanMessage(content=input_value))
|
||||
if stream:
|
||||
result = runnable.stream(messages)
|
||||
return runnable.stream(messages)
|
||||
else:
|
||||
message = runnable.invoke(messages)
|
||||
result = message.content
|
||||
self.status = result
|
||||
return result
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, List, Optional, Text
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from langchain_core.tools import StructuredTool
|
||||
from loguru import logger
|
||||
|
|
@ -8,6 +8,7 @@ from langflow.field_typing import Tool
|
|||
from langflow.graph.graph.base import Graph
|
||||
from langflow.helpers.flow import build_function_and_schema
|
||||
from langflow.schema.dotdict import dotdict
|
||||
from langflow.schema.schema import Record
|
||||
|
||||
|
||||
class FlowToolComponent(CustomComponent):
|
||||
|
|
@ -19,7 +20,7 @@ class FlowToolComponent(CustomComponent):
|
|||
flow_records = self.list_flows()
|
||||
return [flow_record.data["name"] for flow_record in flow_records]
|
||||
|
||||
def get_flow(self, flow_name: str) -> Optional[Text]:
|
||||
def get_flow(self, flow_name: str) -> Optional[Record]:
|
||||
"""
|
||||
Retrieves a flow by its name.
|
||||
|
||||
|
|
@ -82,4 +83,4 @@ class FlowToolComponent(CustomComponent):
|
|||
description_repr = repr(tool.description).strip("'")
|
||||
args_str = "\n".join([f"- {arg_name}: {arg_data['description']}" for arg_name, arg_data in tool.args.items()])
|
||||
self.status = f"{description_repr}\nArguments:\n{args_str}"
|
||||
return tool
|
||||
return tool # type: ignore
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from typing import Any, List, Optional
|
||||
|
||||
from langflow.helpers.flow import get_flow_inputs
|
||||
from loguru import logger
|
||||
|
||||
from langflow.custom import CustomComponent
|
||||
|
|
@ -43,7 +44,7 @@ class SubFlowComponent(CustomComponent):
|
|||
raise ValueError(f"Flow {field_value} not found.")
|
||||
graph = Graph.from_payload(flow_record.data["data"])
|
||||
# Get all inputs from the graph
|
||||
inputs = self.get_flow_inputs(graph)
|
||||
inputs = get_flow_inputs(graph)
|
||||
# Add inputs to the build config
|
||||
build_config = self.add_inputs_to_build_config(inputs, build_config)
|
||||
except Exception as e:
|
||||
|
|
@ -51,14 +52,6 @@ class SubFlowComponent(CustomComponent):
|
|||
|
||||
return build_config
|
||||
|
||||
def get_flow_inputs(self, graph: Graph) -> List[Vertex]:
|
||||
inputs = []
|
||||
for vertex in graph.vertices:
|
||||
if vertex.is_input:
|
||||
inputs.append((vertex.id, vertex.display_name, vertex.description))
|
||||
logger.debug(inputs)
|
||||
return inputs
|
||||
|
||||
def add_inputs_to_build_config(self, inputs: List[Vertex], build_config: dotdict):
|
||||
new_fields: list[TemplateField] = []
|
||||
for vertex in inputs:
|
||||
|
|
@ -116,7 +109,7 @@ class SubFlowComponent(CustomComponent):
|
|||
run_output = run_outputs[0]
|
||||
|
||||
records = []
|
||||
if run_outputs is not None:
|
||||
if run_output is not None:
|
||||
for output in run_output.outputs:
|
||||
if output:
|
||||
records.extend(self.build_records_from_result_data(output))
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ class Graph:
|
|||
self,
|
||||
inputs: Dict[str, str],
|
||||
input_components: list[str],
|
||||
input_type: str,
|
||||
input_type: Literal["chat", "text", "json", "any"] | None,
|
||||
outputs: list[str],
|
||||
stream: bool,
|
||||
session_id: str,
|
||||
|
|
@ -236,7 +236,7 @@ class Graph:
|
|||
continue
|
||||
# If the input_type is not any and the input_type is not in the vertex id
|
||||
# Example: input_type = "chat" and vertex.id = "OpenAI-19ddn"
|
||||
elif input_type != "any" and input_type not in vertex.id.lower():
|
||||
elif input_type is not None and input_type != "any" and input_type not in vertex.id.lower():
|
||||
continue
|
||||
if vertex is None:
|
||||
raise ValueError(f"Vertex {vertex_id} not found")
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
from .record import docs_to_records, records_to_text
|
||||
|
||||
__all__ = ["docs_to_records", "records_to_text"]
|
||||
1
src/backend/langflow/version/__init__.py
Normal file
1
src/backend/langflow/version/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .version import __version__ # noqa: F401
|
||||
|
|
@ -3,6 +3,5 @@ from importlib import metadata
|
|||
try:
|
||||
__version__ = metadata.version(__package__)
|
||||
except metadata.PackageNotFoundError:
|
||||
# Case where package metadata is not available.
|
||||
__version__ = ""
|
||||
del metadata # optional, avoids polluting the results of dir(__package__)
|
||||
del metadata
|
||||
Loading…
Add table
Add a link
Reference in a new issue