Merge branch 'dev' into uiImprovements

This commit is contained in:
anovazzi1 2023-05-02 22:52:57 -03:00
commit e2c8dfab2f
21 changed files with 598 additions and 564 deletions

View file

@ -1,4 +1,4 @@
from langflow.interface.loading import load_flow_from_json
from langflow.cache import cache_manager
from langflow.interface.loading import load_flow_from_json
__all__ = ["load_flow_from_json", "cache_manager"]

View file

@ -1,4 +1,5 @@
from typing import Any
from langchain.callbacks.base import AsyncCallbackHandler
from langflow.api.schemas import ChatResponse

View file

@ -1,9 +1,12 @@
import asyncio
from typing import Dict, List
from collections import defaultdict
from fastapi import WebSocket
import json
from collections import defaultdict
from typing import Dict, List
from fastapi import WebSocket
from langflow.api.schemas import ChatMessage, ChatResponse, FileResponse
from langflow.cache import cache_manager
from langflow.cache.manager import Subject
from langflow.interface.run import (
get_result_and_steps,
@ -11,7 +14,6 @@ from langflow.interface.run import (
)
from langflow.interface.utils import pil_to_base64, try_setting_streaming_options
from langflow.utils.logger import logger
from langflow.cache import cache_manager
class ChatHistory(Subject):

View file

@ -1,4 +1,5 @@
from typing import Any, Union
from pydantic import BaseModel, validator

View file

@ -2,13 +2,13 @@ import base64
import contextlib
import functools
import hashlib
import json
import os
import tempfile
from collections import OrderedDict
from pathlib import Path
from typing import Any, Dict
import dill # type: ignore
CACHE: Dict[str, Any] = {}

View file

@ -1,7 +1,8 @@
from contextlib import contextmanager
from typing import Any, Awaitable, Callable, List, Optional
from PIL import Image
import pandas as pd
from PIL import Image
class Subject:

View file

@ -26,9 +26,9 @@ from langchain.agents.agent_toolkits.vectorstore.prompt import (
)
from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS
from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS as SQL_FORMAT_INSTRUCTIONS
from langchain.base_language import BaseLanguageModel
from langchain.llms.base import BaseLLM
from langchain.memory.chat_memory import BaseChatMemory
from langchain.base_language import BaseLanguageModel
from langchain.sql_database import SQLDatabase
from langchain.tools.python.tool import PythonAstREPLTool
from langchain.tools.sql_database.prompt import QUERY_CHECKER
@ -51,7 +51,7 @@ class JsonAgent(AgentExecutor):
@classmethod
def from_toolkit_and_llm(cls, toolkit: JsonToolkit, llm: BaseLanguageModel):
tools = toolkit.get_tools()
tool_names = [tool.name for tool in tools]
tool_names = {tool.name for tool in tools}
prompt = ZeroShotAgent.create_prompt(
tools,
prefix=JSON_PREFIX,
@ -109,7 +109,7 @@ class CSVAgent(AgentExecutor):
llm=llm,
prompt=partial_prompt,
)
tool_names = [tool.name for tool in tools]
tool_names = {tool.name for tool in tools}
agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs)
return cls.from_agent_and_tools(agent=agent, tools=tools, verbose=True)
@ -146,7 +146,7 @@ class VectorStoreAgent(AgentExecutor):
llm=llm,
prompt=prompt,
)
tool_names = [tool.name for tool in tools]
tool_names = {tool.name for tool in tools}
agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs)
return AgentExecutor.from_agent_and_tools(
agent=agent, tools=tools, verbose=True
@ -212,7 +212,7 @@ class SQLAgent(AgentExecutor):
llm=llm,
prompt=prompt,
)
tool_names = [tool.name for tool in tools] # type: ignore
tool_names = {tool.name for tool in tools} # type: ignore
agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs)
return AgentExecutor.from_agent_and_tools(
agent=agent,
@ -255,7 +255,7 @@ class VectorStoreRouterAgent(AgentExecutor):
llm=llm,
prompt=prompt,
)
tool_names = [tool.name for tool in tools]
tool_names = {tool.name for tool in tools}
agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names, **kwargs)
return AgentExecutor.from_agent_and_tools(
agent=agent, tools=tools, verbose=True

View file

@ -21,7 +21,7 @@ class MalfoyAgent(AgentExecutor):
@classmethod
def from_toolkit_and_llm(cls, toolkit: JsonToolkit, llm: BaseLanguageModel):
tools = toolkit.get_tools()
tool_names = [tool.name for tool in tools]
tool_names = {tool.name for tool in tools}
prompt = ZeroShotAgent.create_prompt(
tools,
prefix=JSON_PREFIX,

View file

@ -17,6 +17,7 @@ from langchain.callbacks.base import BaseCallbackManager
from langchain.chains.loading import load_chain_from_config
from langchain.llms.base import BaseLLM
from langchain.llms.loading import load_llm_from_config
from pydantic import ValidationError
from langflow.interface.agents.custom import CUSTOM_AGENTS
from langflow.interface.importing.utils import import_by_type
@ -25,7 +26,6 @@ from langflow.interface.toolkits.base import toolkits_creator
from langflow.interface.types import get_type_list
from langflow.interface.utils import load_file_into_dict
from langflow.utils import util, validate
from pydantic import ValidationError
def instantiate_class(node_type: str, base_type: str, params: Dict) -> Any:

View file

@ -1,6 +1,7 @@
import contextlib
import io
from typing import Any, Dict
from chromadb.errors import NotEnoughElementsException # type: ignore
from langflow.cache.base import compute_dict_hash, load_cache, memoize_dict

View file

@ -1,14 +1,15 @@
import base64
from io import BytesIO
import json
import os
from PIL.Image import Image
from io import BytesIO
import yaml
from langchain.callbacks.manager import AsyncCallbackManager
from langchain.chat_models import AzureChatOpenAI, ChatOpenAI
from langchain.llms import AzureOpenAI, OpenAI
from langflow.api.callback import StreamingLLMCallbackHandler
from PIL.Image import Image
import yaml
from langflow.api.callback import StreamingLLMCallbackHandler
def load_file_into_dict(file_path: str) -> dict:

View file

@ -1,9 +1,9 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from langflow.api.chat import router as chat_router
from langflow.api.endpoints import router as endpoints_router
from langflow.api.validate import router as validate_router
from langflow.api.chat import router as chat_router
def create_app():

View file

@ -162,14 +162,23 @@ class FrontendNode(BaseModel):
_type = _type.replace("Optional[", "")[:-1]
# Check for list type
if "List" in _type:
_type = _type.replace("List[", "")[:-1]
if "List" in _type or "Sequence" in _type:
_type = _type.replace("List[", "")
_type = _type.replace("Sequence[", "")[:-1]
field.is_list = True
# Replace 'Mapping' with 'dict'
if "Mapping" in _type:
_type = _type.replace("Mapping", "dict")
# {'type': 'Union[float, Tuple[float, float], NoneType]'} != {'type': 'float'}
if "Union" in _type:
_type = _type.replace("Union[", "")[:-1]
_type = _type.split(",")[0]
_type = _type.replace("]", "").replace("[", "")
field.field_type = _type
# Change type from str to Tool
field.field_type = "Tool" if key in {"allowed_tools"} else field.field_type

View file

@ -1,7 +1,7 @@
from functools import wraps
import importlib
import inspect
import re
from functools import wraps
from typing import Dict, Optional
from docstring_parser import parse # type: ignore

View file

@ -8,10 +8,10 @@ import {
} from "react";
import { FlowType } from "../types/flow";
import { LangFlowState, TabsContextType } from "../types/tabs";
import { normalCaseToSnakeCase, updateObject } from "../utils";
import { normalCaseToSnakeCase, updateObject, updateTemplate } from "../utils";
import { alertContext } from "./alertContext";
import { typesContext } from "./typesContext";
import { TemplateVariableType } from "../types/api";
import { APITemplateType, TemplateVariableType } from "../types/api";
const { v4: uuidv4 } = require("uuid");
const TabsContextInitialValue: TabsContextType = {
@ -64,12 +64,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
cookieObject.flows.forEach((flow) => {
flow.data.nodes.forEach((node) => {
if (Object.keys(templates[node.data.type]["template"]).length > 0) {
node.data.node.template = updateObject(
node.data.node.template = updateTemplate(
templates[node.data.type][
"template"
] as unknown as TemplateVariableType,
] as unknown as APITemplateType,
node.data.node.template as TemplateVariableType
node.data.node.template as APITemplateType
);
}
});
@ -127,16 +127,6 @@ export function TabsProvider({ children }: { children: ReactNode }) {
file.text().then((text) => {
// parse the text into a JSON object
let flow: FlowType = JSON.parse(text);
flow.data.nodes.forEach((node) => {
if (Object.keys(templates[node.data.type]["template"]).length > 0) {
node.data.node.template = updateObject(
templates[node.data.type][
"template"
] as unknown as TemplateVariableType,
node.data.node.template as TemplateVariableType
);
}
});
addFlow(flow);
});
@ -176,6 +166,16 @@ export function TabsProvider({ children }: { children: ReactNode }) {
const data = flow?.data ? flow.data : null;
const description = flow?.description ? flow.description : "";
if (data) {
data.nodes.forEach((node) => {
if (Object.keys(templates[node.data.type]["template"]).length > 0) {
node.data.node.template = updateTemplate(
templates[node.data.type]["template"] as unknown as APITemplateType,
node.data.node.template as APITemplateType
);
}
});
}
// Create a new flow with a default name if no flow is provided.
let newFlow: FlowType = {
description,

View file

@ -18,6 +18,7 @@ import {
} from "@heroicons/react/24/outline";
import { Connection, Edge, Node, ReactFlowInstance } from "reactflow";
import { FlowType } from "./types/flow";
import { APITemplateType, TemplateVariableType } from "./types/api";
var _ = require("lodash");
export function classNames(...classes: Array<string>) {
@ -437,3 +438,19 @@ export function debounce(func, wait) {
timeout = setTimeout(() => func.apply(context, args), wait);
};
}
export function updateTemplate(
reference: APITemplateType,
objectToUpdate: APITemplateType
): APITemplateType {
let clonedObject:APITemplateType = _.cloneDeep(reference);
// Loop through each key in the reference object
for (const key in clonedObject) {
// If the key is not in the object to update, add it
if (objectToUpdate[key] && objectToUpdate[key].value) {
clonedObject[key].value = objectToUpdate[key].value;
}
}
return clonedObject;
}

View file

@ -1,11 +1,10 @@
import json
from pathlib import Path
from typing import AsyncGenerator
from httpx import AsyncClient
import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient
def pytest_configure():

View file

@ -48,6 +48,7 @@ def test_zero_shot_agent(client: TestClient):
"type": "Tool",
"list": True,
"advanced": False,
"value": [],
}

View file

@ -1,8 +1,9 @@
import pytest
from PIL import Image
import pandas as pd
from io import StringIO
import pandas as pd
import pytest
from langflow.cache.manager import CacheManager
from PIL import Image
@pytest.fixture

View file

@ -291,7 +291,7 @@ def test_openai(client: TestClient):
"multiline": False,
"password": False,
"name": "request_timeout",
"type": "Union[float, Tuple[float, float], NoneType]",
"type": "float",
"list": False,
"advanced": False,
}
@ -418,10 +418,9 @@ def test_chat_open_ai(client: TestClient):
"placeholder": "",
"show": False,
"multiline": False,
"value": 60,
"password": False,
"name": "request_timeout",
"type": "int",
"type": "float",
"list": False,
"advanced": False,
}

View file

@ -1,5 +1,6 @@
import json
from unittest.mock import patch
from fastapi.testclient import TestClient