Changed API modal to include Python code
This commit is contained in:
parent
a80bf37be4
commit
50ba94e470
2 changed files with 22 additions and 6 deletions
|
|
@ -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"
|
API_URL = "${window.location.protocol}//${window.location.host}/predict"
|
||||||
|
|
||||||
|
|
@ -57,9 +57,21 @@ def predict(message):
|
||||||
|
|
||||||
print(predict("Your 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 = [
|
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",
|
mode: "python",
|
||||||
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
|
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
|
||||||
code: pythonCode,
|
code: pythonCode,
|
||||||
|
|
@ -123,7 +135,7 @@ print(predict("Your message"))`;
|
||||||
as="h3"
|
as="h3"
|
||||||
className="text-lg font-medium dark:text-white leading-10 text-gray-900"
|
className="text-lg font-medium dark:text-white leading-10 text-gray-900"
|
||||||
>
|
>
|
||||||
Use API
|
Code
|
||||||
</Dialog.Title>
|
</Dialog.Title>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -140,7 +152,10 @@ print(predict("Your message"))`;
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-hidden px-4 py-5 sm:p-6 w-full h-full rounded-lg shadow bg-white dark:bg-gray-800">
|
<div className="overflow-hidden px-4 py-5 sm:p-6 w-full h-full rounded-lg shadow bg-white dark:bg-gray-800">
|
||||||
<div className="w-full flex justify-end mb-2">
|
<div className="w-full flex items-center justify-between mb-2">
|
||||||
|
<span className="text-sm text-gray-500 dark:text-gray-300">
|
||||||
|
Export your flow to use it with this code.
|
||||||
|
</span>
|
||||||
<button
|
<button
|
||||||
className="flex gap-1.5 items-center rounded bg-none p-1 text-xs text-gray-500 dark:text-gray-300"
|
className="flex gap-1.5 items-center rounded bg-none p-1 text-xs text-gray-500 dark:text-gray-300"
|
||||||
onClick={copyToClipboard}
|
onClick={copyToClipboard}
|
||||||
|
|
@ -150,6 +165,7 @@ print(predict("Your message"))`;
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<SyntaxHighlighter
|
<SyntaxHighlighter
|
||||||
|
className="h-[370px]"
|
||||||
language={tabs[activeTab].mode}
|
language={tabs[activeTab].mode}
|
||||||
style={oneDark}
|
style={oneDark}
|
||||||
customStyle={{ margin: 0 }}
|
customStyle={{ margin: 0 }}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export default function TabsManagerComponent() {
|
||||||
onClick={() => openPopUp(<ApiModal flowName={flows[tabIndex].name} />)}
|
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"
|
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" />
|
Code <CodeBracketSquareIcon className="w-5 h-5" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => openPopUp(<ImportModal />)}
|
onClick={() => openPopUp(<ImportModal />)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue