Fix various issues and refactor code (#1647)
* Add options field to FIELD_FORMAT_ATTRIBUTES constant and import pathlib in test_initial_setup.py * Update TEXT_FILE_TYPES in utils.py and handle missing file path error in Vertex class * Fix tweak value assignment in process.py and clear session cache in test_process.py * New lock * Update repository URLs and fix file paths in code blocks * Fix data retrieval in test_pickle_graph and test_pickle_each_vertex in test_graph.py * Refactor load_starter_projects function to include type hinting in setup.py * Update name of Basic Prompting (Hello, world!) project to Basic Prompting (Hello, World) * Refactor Graph.process() method to accept start_component_id parameter * Refactor test_endpoints.py to use "Chat Output" instead of "Prompt Output" and "ChatOutput" instead of "TextOutput"
This commit is contained in:
parent
a465d71a5e
commit
254f11485e
13 changed files with 3452 additions and 3430 deletions
|
|
@ -24,4 +24,5 @@ FIELD_FORMAT_ATTRIBUTES = [
|
|||
"real_time_refresh",
|
||||
"refresh_button",
|
||||
"refresh_button_text",
|
||||
"options",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,26 @@ from langflow.schema.schema import Record
|
|||
|
||||
# Types of files that can be read simply by file.read()
|
||||
# and have 100% to be completely readable
|
||||
TEXT_FILE_TYPES = ["txt", "md", "mdx", "csv", "json", "yaml", "yml", "xml", "html", "htm", "pdf", "docx"]
|
||||
TEXT_FILE_TYPES = [
|
||||
"txt",
|
||||
"md",
|
||||
"mdx",
|
||||
"csv",
|
||||
"json",
|
||||
"yaml",
|
||||
"yml",
|
||||
"xml",
|
||||
"html",
|
||||
"htm",
|
||||
"pdf",
|
||||
"docx",
|
||||
"py",
|
||||
"sh",
|
||||
"sql",
|
||||
"js",
|
||||
"ts",
|
||||
"tsx",
|
||||
]
|
||||
|
||||
|
||||
def is_hidden(path: Path) -> bool:
|
||||
|
|
|
|||
|
|
@ -249,7 +249,10 @@ class Graph:
|
|||
vertex.update_raw_params({"session_id": session_id})
|
||||
# Process the graph
|
||||
try:
|
||||
await self.process()
|
||||
start_component_id = next(
|
||||
(vertex_id for vertex_id in self._is_input_vertices if "chat" in vertex_id.lower()), None
|
||||
)
|
||||
await self.process(start_component_id=start_component_id)
|
||||
self.increment_run_count()
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
|
|
@ -345,7 +348,7 @@ class Graph:
|
|||
if types is None:
|
||||
types = []
|
||||
for _ in range(len(inputs) - len(types)):
|
||||
types.append("any")
|
||||
types.append("chat") # default to chat
|
||||
for run_inputs, components, input_type in zip(inputs, inputs_components, types):
|
||||
run_outputs = await self._run(
|
||||
inputs=run_inputs,
|
||||
|
|
@ -733,8 +736,10 @@ class Graph:
|
|||
vertices.append(vertex)
|
||||
return vertices
|
||||
|
||||
async def process(self) -> "Graph":
|
||||
async def process(self, start_component_id: Optional[str] = None) -> "Graph":
|
||||
"""Processes the graph with vertices in each layer run in parallel."""
|
||||
|
||||
self.sort_vertices(start_component_id=start_component_id)
|
||||
vertices_layers = self.sorted_vertices_layers
|
||||
vertex_task_run_count: Dict[str, int] = {}
|
||||
for layer_index, layer in enumerate(vertices_layers):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import ast
|
||||
import asyncio
|
||||
import inspect
|
||||
import os
|
||||
import types
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any, AsyncIterator, Callable, Dict, Iterator, List, Optional
|
||||
import os
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
|
@ -315,7 +315,8 @@ class Vertex:
|
|||
raise e
|
||||
params[field_name] = full_path
|
||||
elif field.get("required"):
|
||||
raise ValueError(f"File path not found for {self.display_name}")
|
||||
field_display_name = field.get("display_name")
|
||||
raise ValueError(f"File path not found for {field_display_name} in component {self.display_name}")
|
||||
elif field.get("type") in DIRECT_TYPES and params.get(field_name) is None:
|
||||
val = field.get("value")
|
||||
if field.get("type") == "code":
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ def log_node_changes(node_changes_log):
|
|||
logger.debug("\n".join(formatted_messages))
|
||||
|
||||
|
||||
def load_starter_projects():
|
||||
def load_starter_projects() -> list[tuple[Path, dict]]:
|
||||
starter_projects = []
|
||||
folder = Path(__file__).parent / "starter_projects"
|
||||
for file in folder.glob("*.json"):
|
||||
|
|
|
|||
|
|
@ -882,7 +882,7 @@
|
|||
}
|
||||
},
|
||||
"description": "This flow will get you experimenting with the basics of the UI, the Chat and the Prompt component. \n\nTry changing the Template in it to see how the model behaves. \nYou can change it to this and a Text Input into the `type_of_person` variable : \"Answer the user as if you were a pirate.\n\nUser: {user_input}\n\nAnswer: \" ",
|
||||
"name": "Basic Prompting (Hello, world!)",
|
||||
"name": "Basic Prompting (Hello, World)",
|
||||
"last_tested_version": "1.0.0a4",
|
||||
"is_component": false
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -245,7 +245,7 @@ def apply_tweaks(node: Dict[str, Any], node_tweaks: Dict[str, Any]) -> None:
|
|||
logger.warning(f"Node {node.get('id')} does not have a tweak named {tweak_name}")
|
||||
continue
|
||||
if tweak_name in template_data:
|
||||
key = tweak_name if tweak_name == "file_path" else "value"
|
||||
key = "file_path" if template_data[tweak_name]["type"] == "file" else "value"
|
||||
template_data[tweak_name][key] = tweak_value
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue