From 50ba94e470493441c1323ca035d8f4cc4273299d Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Fri, 12 May 2023 08:43:43 -0300 Subject: [PATCH] Changed API modal to include Python code --- src/frontend/src/modals/ApiModal/index.tsx | 26 +++++++++++++++---- .../components/tabsManagerComponent/index.tsx | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index d0d2f676b..f64bf9951 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -44,7 +44,7 @@ export default function ApiModal({ flowName }) { } } - const pythonCode = `import requests + const pythonApiCode = `import requests API_URL = "${window.location.protocol}//${window.location.host}/predict" @@ -57,9 +57,21 @@ def predict(message): print(predict("Your message"))`; +const pythonCode = `from langflow import load_flow_from_json + +flow = load_flow_from_json("${flowName}.json") +# Now you can use it like any chain +flow("Hey, have you heard of LangFlow?")`; + const tabs = [ { - name: "Python", + name: "Python API", + mode: "python", + image: "https://images.squarespace-cdn.com/content/v1/5df3d8c5d2be5962e4f87890/1628015119369-OY4TV3XJJ53ECO0W2OLQ/Python+API+Training+Logo.png?format=1000w", + code: pythonApiCode, + }, + { + name: "Python Code", mode: "python", image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png", code: pythonCode, @@ -99,7 +111,7 @@ print(predict("Your message"))`; >
-
@@ -140,7 +152,10 @@ print(predict("Your message"))`; ))}
-
+
+ + Export your flow to use it with this code. +
openPopUp()} 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 + Code