Fixed Python API code

This commit is contained in:
Lucas Oliveira 2023-05-11 18:58:07 -03:00
commit 9496728eb5
2 changed files with 26 additions and 28 deletions

View file

@ -3,44 +3,18 @@ import { IconCheck, IconClipboard, IconDownload } from '@tabler/icons-react';
import { XMarkIcon, CommandLineIcon, CodeBracketSquareIcon } from "@heroicons/react/24/outline";
import { Fragment, useContext, useRef, useState } from "react";
import { PopUpContext } from "../../contexts/popUpContext";
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-python";
import "ace-builds/src-noconflict/theme-github";
import "ace-builds/src-noconflict/theme-twilight";
import "ace-builds/src-noconflict/ext-language_tools";
import "ace-builds/webpack-resolver";
import { darkContext } from "../../contexts/darkContext";
import { checkCode } from "../../controllers/API";
import { alertContext } from "../../contexts/alertContext";
import { FaPython } from "react-icons/fa";
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
const pythonCode = `import requests
API_URL = "{window.location.protocol}//{window.location.host}/predict"
def predict(message):
with open("FLOW NAME.json:, "r") as f:
json_data = json.load(f)
payload['exported_flow'] = json_data
payload['message'] = message
response = requests.post(API_URL, json=payload)
return response.json() # JSON {"result": "Response"}
print(predict("Your message"))`;
const tabs = [
{
name: "Python",
mode: "python",
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
code: pythonCode,
},
]
export default function ApiModal() {
export default function ApiModal({flowName}) {
const [open, setOpen] = useState(true);
const { dark } = useContext(darkContext);
const { closePopUp } = useContext(PopUpContext);
@ -69,6 +43,30 @@ export default function ApiModal() {
}, 300);
}
}
const pythonCode = `import requests
API_URL = "${window.location.protocol}//${window.location.host}/predict"
def predict(message):
with open("${flowName}.json:, "r") as f:
json_data = json.load(f)
payload['exported_flow'] = json_data
payload['message'] = message
response = requests.post(API_URL, json=payload)
return response.json() # JSON {"result": "Response"}
print(predict("Your message"))`;
const tabs = [
{
name: "Python",
mode: "python",
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
code: pythonCode,
},
]
return (
<Transition.Root show={open} appear={true} as={Fragment}>
<Dialog

View file

@ -58,7 +58,7 @@ export default function TabsManagerComponent() {
/>
<div className="ml-auto mr-2 flex gap-3">
<button
onClick={() => openPopUp(<ApiModal />)}
onClick={() => openPopUp(<ApiModal flowName={flows[tabIndex].name} />)}
className="flex items-center gap-1 pr-2 border-gray-400 border-r text-sm text-gray-600 hover:text-gray-500 dark:text-gray-300 dark:hover:text-gray-200"
>
API <CodeBracketSquareIcon className="w-5 h-5" />