Skip to content

Commit

Permalink
fix: handle skill prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
dolphin0618 committed Jan 19, 2024
1 parent 91f5fab commit 95382fd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function ParameterComponent({
info = "",
onChange
}: ParameterComponentType) {
// console.log('data, id :>> ', data.id, id, type);
// console.log('data, id :>> ', name, optionalHandle);
const { id: flowId } = useParams();

const ref = useRef(null);
Expand Down Expand Up @@ -390,6 +390,7 @@ export default function ParameterComponent({
updateEdge: (edge) => reactFlowInstance.setEdges(edge),
});
}
// onChange?.()
}}
nodeClass={data.node}
disabled={disabled}
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/src/CustomNodes/GenericNode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Zap } from "lucide-react";
import { useContext, useEffect, useRef, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { NodeToolbar } from "reactflow";
import ShadTooltip from "../../components/ShadTooltipComponent";
import Tooltip from "../../components/TooltipComponent";
import { Button } from "../../components/ui/button";
import { useSSE } from "../../contexts/SSEContext";
import { alertContext } from "../../contexts/alertContext";
import { PopUpContext } from "../../contexts/popUpContext";
Expand All @@ -16,8 +18,6 @@ import {
toTitleCase,
} from "../../utils";
import ParameterComponent from "./components/parameterComponent";
import { Link, useParams } from "react-router-dom";
import { Button } from "../../components/ui/button";

export default function GenericNode({ data, selected }: {
data: NodeDataType;
Expand Down Expand Up @@ -67,7 +67,6 @@ export default function GenericNode({ data, selected }: {
deleteNode(data.id);
return;
}
useEffect(() => { }, [closePopUp, data.node.template]);

const [_, fouceUpdateNode] = useState(false)

Expand Down
24 changes: 6 additions & 18 deletions src/frontend/src/components/promptComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { TextAreaComponentType } from "../../types/components";
import { TypeModal } from "../../utils";

import { ExternalLink } from "lucide-react";
import { typesContext } from "../../contexts/typesContext";
import { postValidatePrompt } from "../../controllers/API";

export default function PromptAreaComponent({
Expand All @@ -19,26 +18,13 @@ export default function PromptAreaComponent({
}: TextAreaComponentType) {
const [myValue, setMyValue] = useState(value);
const { openPopUp } = useContext(PopUpContext);
const { reactFlowInstance } = useContext(typesContext);
useEffect(() => {
if (disabled) {
setMyValue("");
onChange("");
}
}, [disabled, onChange]);

useEffect(() => {
setMyValue(value);
if (value !== "" && !editNode) {
postValidatePrompt(field_name, value, nodeClass).then((apiReturn) => {
if (apiReturn) {
setNodeClass(apiReturn.frontend_node);
// need to update reactFlowInstance to re-render the nodes.
}
});
}
}, [value, reactFlowInstance]);

// useEffect(() => {
// if (value !== "" && myValue !== value && reactFlowInstance) {
// // only executed once
Expand All @@ -57,6 +43,11 @@ export default function PromptAreaComponent({
// }
// }, [reactFlowInstance, field_name, myValue, nodeClass, setNodeClass, value]);

const handleSave = (t: string) => {
setMyValue(t);
onChange(t);
}

return (
<div className={disabled ? "pointer-events-none w-full " : " w-full"}>
<div className="flex w-full items-center">
Expand Down Expand Up @@ -95,10 +86,7 @@ export default function PromptAreaComponent({
value={myValue}
buttonText="check & Save"
modalTitle="Edit Prompt"
setValue={(t: string) => {
setMyValue(t);
onChange(t);
}}
setValue={handleSave}
nodeClass={nodeClass}
setNodeClass={setNodeClass}
/>
Expand Down
12 changes: 8 additions & 4 deletions src/frontend/src/contexts/tabsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export function TabsProvider({ children }: { children: ReactNode }) {
const { templates, reactFlowInstance } = useContext(typesContext);

async function saveFlow(flow: FlowType) {
// 按模板矫正数据格式
processFlowEdges(flow);
processFlowNodes(flow);
// save api
const newFlow = await captureAndAlertRequestErrorHoc(updateFlowApi(flow))
if (!newFlow) return {}
Expand Down Expand Up @@ -274,7 +271,8 @@ export function TabsProvider({ children }: { children: ReactNode }) {
flow.data.nodes.forEach((node: NodeType) => {
const template = templates[node.data.type];
if (!template) {
setErrorData({ title: `Unknown node type: ${node.data.type}` });
// setErrorData({ title: `Unknown node type: ${node.data.type}` });
console.warn(`Unknown node type: ${node.data.type}`)
return;
}
if (Object.keys(template["template"]).length > 0) {
Expand All @@ -297,6 +295,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
flow,
setFlow: (action, flow) => {
console.log('action :>> ', action);
if (action === "flow_init") {
// 按模板矫正数据格式
processFlowEdges(flow);
processFlowNodes(flow);
}

setFlow(flow);
},
saveFlow,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/pages/FlowPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function FlowPage() {
useEffect(() => {
if (id && flow?.id !== id) {
// 切换技能重新加载flow数据
getFlowApi(id).then(_flow => setFlow('flow init', _flow))
getFlowApi(id).then(_flow => setFlow('flow_init', _flow))
}
}, [])

Expand Down

0 comments on commit 95382fd

Please sign in to comment.