Merge branch 'logspace-ai:dev' into dev
This commit is contained in:
commit
943d3aa4a6
19 changed files with 167 additions and 171 deletions
|
|
@ -54,7 +54,7 @@ def instantiate_based_on_type(class_object, base_type, node_type, params):
|
|||
if base_type == "agents":
|
||||
return instantiate_agent(class_object, params)
|
||||
elif base_type == "prompts":
|
||||
return instantiate_prompt(class_object, node_type, params)
|
||||
return instantiate_prompt(node_type, class_object, params)
|
||||
elif base_type == "tools":
|
||||
return instantiate_tool(node_type, class_object, params)
|
||||
elif base_type == "toolkits":
|
||||
|
|
@ -77,7 +77,7 @@ def instantiate_agent(class_object, params):
|
|||
return load_agent_executor(class_object, params)
|
||||
|
||||
|
||||
def instantiate_prompt(class_object, node_type, params):
|
||||
def instantiate_prompt(node_type, class_object, params):
|
||||
if node_type == "ZeroShotPrompt":
|
||||
if "tools" not in params:
|
||||
params["tools"] = []
|
||||
|
|
@ -96,7 +96,7 @@ def instantiate_tool(node_type, class_object, params):
|
|||
raise ValueError("Function should be a string")
|
||||
elif node_type.lower() == "tool":
|
||||
return class_object(**params)
|
||||
return None # Or some other default action
|
||||
return class_object(**params)
|
||||
|
||||
|
||||
def instantiate_toolkit(node_type, class_object, params):
|
||||
|
|
|
|||
|
|
@ -23,4 +23,4 @@ RUN chmod +x set_proxy.sh && \
|
|||
USER node
|
||||
|
||||
RUN npm install --loglevel warn
|
||||
CMD ["npm", "start"]
|
||||
CMD ["npm", "run", "dev:docker"]
|
||||
|
|
@ -35,6 +35,7 @@
|
|||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"dev:docker": "vite --host 0.0.0.0",
|
||||
"start": "vite",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview"
|
||||
|
|
@ -76,4 +77,4 @@
|
|||
"typescript": "^5.0.2",
|
||||
"vite": "^4.3.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import { useState } from "react";
|
|||
import { ChatMessageType } from "../../../types/chat";
|
||||
import { nodeColors } from "../../../utils";
|
||||
import Convert from "ansi-to-html";
|
||||
var convert = new Convert({newline:true});
|
||||
const convert = new Convert({ newline: true });
|
||||
|
||||
export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
|
||||
const [hidden, setHidden] = useState(true);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
const { setNoticeData } = useContext(alertContext);
|
||||
const [tabIndex, setTabIndex] = useState(0);
|
||||
const [flows, setFlows] = useState<Array<FlowType>>([]);
|
||||
const [id, setId] = useState("");
|
||||
const [id, setId] = useState(uuidv4());
|
||||
const { templates } = useContext(typesContext);
|
||||
|
||||
const newNodeId = useRef(0);
|
||||
|
|
@ -47,46 +47,50 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
return newNodeId.current;
|
||||
}
|
||||
function save() {
|
||||
if (flows.length !== 0)
|
||||
window.localStorage.setItem(
|
||||
"tabsData",
|
||||
JSON.stringify({ tabIndex, flows, id, nodeId: newNodeId.current })
|
||||
);
|
||||
//disabled until flows can be saved on local storage again without bugs
|
||||
// if (flows.length !== 0)
|
||||
// window.localStorage.setItem(
|
||||
// "tabsData",
|
||||
// JSON.stringify({ tabIndex, flows, id, nodeId: newNodeId.current })
|
||||
// );
|
||||
}
|
||||
useEffect(() => {
|
||||
//disabled until flows can be saved on local storage again without bugs
|
||||
//save tabs locally
|
||||
save();
|
||||
// save();
|
||||
|
||||
}, [flows, id, tabIndex, newNodeId]);
|
||||
|
||||
useEffect(() => {
|
||||
//get tabs locally saved
|
||||
let cookie = window.localStorage.getItem("tabsData");
|
||||
if (cookie && Object.keys(templates).length > 0) {
|
||||
let cookieObject: LangFlowState = JSON.parse(cookie);
|
||||
cookieObject.flows.forEach((flow) => {
|
||||
flow.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,
|
||||
// useEffect(() => {
|
||||
// //get tabs locally saved
|
||||
// let cookie = window.localStorage.getItem("tabsData");
|
||||
// if (cookie && Object.keys(templates).length > 0) {
|
||||
// let cookieObject: LangFlowState = JSON.parse(cookie);
|
||||
// cookieObject.flows.forEach((flow) => {
|
||||
// flow.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
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// setTabIndex(cookieObject.tabIndex);
|
||||
// setFlows(cookieObject.flows);
|
||||
// setId(cookieObject.id);
|
||||
// newNodeId.current = cookieObject.nodeId;
|
||||
// }
|
||||
// }, [templates]);
|
||||
|
||||
node.data.node.template as APITemplateType
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
setTabIndex(cookieObject.tabIndex);
|
||||
setFlows(cookieObject.flows);
|
||||
setId(cookieObject.id);
|
||||
newNodeId.current = cookieObject.nodeId;
|
||||
}
|
||||
}, [templates]);
|
||||
function hardReset() {
|
||||
newNodeId.current = 0;
|
||||
setTabIndex(0);
|
||||
setFlows([]);
|
||||
setId("");
|
||||
setId(uuidv4());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -182,7 +186,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
let newFlow: FlowType = {
|
||||
description,
|
||||
name: flow?.name ?? "New Flow",
|
||||
id: id.toString(),
|
||||
id: uuidv4(),
|
||||
data,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export default function ApiModal({ flowName }) {
|
|||
}
|
||||
|
||||
const pythonApiCode = `import requests
|
||||
import json
|
||||
|
||||
API_URL = "${window.location.protocol}//${window.location.host}/predict"
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ def predict(message):
|
|||
|
||||
print(predict("Your message"))`;
|
||||
|
||||
const pythonCode = `from langflow import load_flow_from_json
|
||||
const pythonCode = `from langflow import load_flow_from_json
|
||||
|
||||
flow = load_flow_from_json("${flowName}.json")
|
||||
# Now you can use it like any chain
|
||||
|
|
@ -165,7 +166,7 @@ flow("Hey, have you heard of LangFlow?")`;
|
|||
</button>
|
||||
</div>
|
||||
<SyntaxHighlighter
|
||||
className="h-[370px]"
|
||||
className="h-[370px]"
|
||||
language={tabs[activeTab].mode}
|
||||
style={oneDark}
|
||||
customStyle={{ margin: 0 }}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { CodeBlock } from "./codeBlock";
|
|||
import Convert from "ansi-to-html";
|
||||
|
||||
export default function ChatMessage({ chat, lockChat }: { chat: ChatMessageType, lockChat: boolean }) {
|
||||
const convert = new Convert({ newline: true });
|
||||
const [message, setMessage] = useState("");
|
||||
const imgRef = useRef(null);
|
||||
useEffect(() => {
|
||||
|
|
@ -35,9 +36,9 @@ export default function ChatMessage({ chat, lockChat }: { chat: ChatMessageType,
|
|||
)}
|
||||
>
|
||||
{!chat.isSend && <div className="relative w-8 h-8">
|
||||
<img className={"absolute transition-opacity duration-500 scale-150 " + (lockChat ? "opacity-100" : "opacity-0")} src={AiIcon} />
|
||||
<img className={"absolute transition-opacity duration-500 scale-150 " + (lockChat ? "opacity-0" : "opacity-100")} src={AiIconStill} />
|
||||
</div>}
|
||||
<img className={"absolute transition-opacity duration-500 scale-150 " + (lockChat ? "opacity-100" : "opacity-0")} src={AiIcon} />
|
||||
<img className={"absolute transition-opacity duration-500 scale-150 " + (lockChat ? "opacity-0" : "opacity-100")} src={AiIconStill} />
|
||||
</div>}
|
||||
{chat.isSend && <UserIcon className="w-6 h-6 -mb-1 text-gray-800 dark:text-gray-200" />}
|
||||
</div>
|
||||
{!chat.isSend ? (
|
||||
|
|
|
|||
|
|
@ -30,10 +30,16 @@ export default function ChatModal({
|
|||
const ws = useRef<WebSocket | null>(null);
|
||||
const [lockChat, setLockChat] = useState(false);
|
||||
const isOpen = useRef(open);
|
||||
const id = useRef(flow.id);
|
||||
|
||||
useEffect(() => {
|
||||
isOpen.current = open;
|
||||
}, [open]);
|
||||
useEffect(() => {
|
||||
id.current = flow.id;
|
||||
},[flow.id])
|
||||
|
||||
|
||||
var isStream = false;
|
||||
|
||||
const addChatHistory = (
|
||||
|
|
@ -164,10 +170,9 @@ export default function ChatModal({
|
|||
try {
|
||||
const urlWs =
|
||||
process.env.NODE_ENV === "development"
|
||||
? `ws://localhost:7860/chat/${flow.id}`
|
||||
? `ws://localhost:7860/chat/${id.current}`
|
||||
: `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host
|
||||
}/chat/${flow.id}`;
|
||||
|
||||
}/chat/${id.current}`;
|
||||
const newWs = new WebSocket(urlWs);
|
||||
newWs.onopen = () => {
|
||||
console.log("WebSocket connection established!");
|
||||
|
|
@ -184,6 +189,26 @@ export default function ChatModal({
|
|||
};
|
||||
newWs.onerror = (ev) => {
|
||||
console.log(ev, "error");
|
||||
if(flow.id===""){
|
||||
connectWS();
|
||||
}
|
||||
else{
|
||||
setErrorData({
|
||||
title: "There was an error on web connection, please: ",
|
||||
list: [
|
||||
"Refresh the page",
|
||||
"Use a new flow tab",
|
||||
"Check if the backend is up",
|
||||
],
|
||||
});
|
||||
}
|
||||
};
|
||||
ws.current = newWs;
|
||||
} catch {
|
||||
if(flow.id===""){
|
||||
connectWS();
|
||||
}
|
||||
else{
|
||||
setErrorData({
|
||||
title: "There was an error on web connection, please: ",
|
||||
list: [
|
||||
|
|
@ -192,17 +217,7 @@ export default function ChatModal({
|
|||
"Check if the backend is up",
|
||||
],
|
||||
});
|
||||
};
|
||||
ws.current = newWs;
|
||||
} catch {
|
||||
setErrorData({
|
||||
title: "There was an error on web connection, please: ",
|
||||
list: [
|
||||
"Refresh the page",
|
||||
"Use a new flow tab",
|
||||
"Check if the backend is up",
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,32 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react-swc';
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react-swc";
|
||||
|
||||
const apiRoutes = [
|
||||
'/all',
|
||||
'/predict',
|
||||
'^/validate/*',
|
||||
'^/chat/*',
|
||||
];
|
||||
const apiRoutes = ["/all", "/predict", "^/validate/*", "^/chat/*"];
|
||||
|
||||
// Use environment variable to determine the target.
|
||||
const target = process.env.VITE_PROXY_TARGET || "http://127.0.0.1:7860";
|
||||
|
||||
const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
|
||||
proxyObj[route] = {
|
||||
target: 'http://127.0.0.1:7860',
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
ws: true,
|
||||
};
|
||||
return proxyObj;
|
||||
proxyObj[route] = {
|
||||
target: target,
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
ws: true,
|
||||
};
|
||||
return proxyObj;
|
||||
}, {});
|
||||
|
||||
export default defineConfig(() => {
|
||||
return {
|
||||
build: {
|
||||
outDir: 'build',
|
||||
},
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3000,
|
||||
proxy: {
|
||||
...proxyTargets
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
return {
|
||||
build: {
|
||||
outDir: "build",
|
||||
},
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3000,
|
||||
proxy: {
|
||||
...proxyTargets,
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue