render api templates if exitst

This commit is contained in:
2023-10-24 22:39:45 +08:00
parent 2bd36d4b34
commit 83833187f0

View File

@@ -316,63 +316,64 @@ export default function ChatBOX(props: {
API Endpoint
</p>
)}
{(chatStore.history.filter((msg) => !msg.example).length == 0 ||
!chatStore.apiEndpoint ||
!chatStore.apiKey) && (
<p className="break-all opacity-80 p-3 rounded bg-white my-3 text-left dark:text-black">
<h2> API </h2>
<hr className="my-2" />
<div className="flex flex-wrap">
{templateAPIs.map((t, index) => (
<div
className={`cursor-pointer rounded ${
chatStore.apiEndpoint === t.endpoint &&
chatStore.apiKey === t.key
? "bg-red-600"
: "bg-red-400"
} w-fit p-2 m-1 flex flex-col`}
onClick={() => {
chatStore.apiEndpoint = t.endpoint;
chatStore.apiKey = t.key;
setChatStore({ ...chatStore });
}}
>
<span className="w-full text-center">{t.name}</span>
<hr className="mt-2" />
<span className="flex justify-between">
<button
onClick={() => {
const name = prompt("Give **API** template a name");
if (!name) {
return;
}
t.name = name;
setTemplateAPIs(structuredClone(templateAPIs));
}}
>
🖋
</button>
<button
onClick={() => {
if (
!confirm(
"Are you sure to delete this **API** template?"
)
) {
return;
}
templateAPIs.splice(index, 1);
setTemplateAPIs(structuredClone(templateAPIs));
}}
>
</button>
</span>
</div>
))}
</div>
</p>
)}
{templateAPIs.length > 0 &&
(chatStore.history.filter((msg) => !msg.example).length == 0 ||
!chatStore.apiEndpoint ||
!chatStore.apiKey) && (
<p className="break-all opacity-80 p-3 rounded bg-white my-3 text-left dark:text-black">
<h2> API </h2>
<hr className="my-2" />
<div className="flex flex-wrap">
{templateAPIs.map((t, index) => (
<div
className={`cursor-pointer rounded ${
chatStore.apiEndpoint === t.endpoint &&
chatStore.apiKey === t.key
? "bg-red-600"
: "bg-red-400"
} w-fit p-2 m-1 flex flex-col`}
onClick={() => {
chatStore.apiEndpoint = t.endpoint;
chatStore.apiKey = t.key;
setChatStore({ ...chatStore });
}}
>
<span className="w-full text-center">{t.name}</span>
<hr className="mt-2" />
<span className="flex justify-between">
<button
onClick={() => {
const name = prompt("Give **API** template a name");
if (!name) {
return;
}
t.name = name;
setTemplateAPIs(structuredClone(templateAPIs));
}}
>
🖋
</button>
<button
onClick={() => {
if (
!confirm(
"Are you sure to delete this **API** template?"
)
) {
return;
}
templateAPIs.splice(index, 1);
setTemplateAPIs(structuredClone(templateAPIs));
}}
>
</button>
</span>
</div>
))}
</div>
</p>
)}
{templates.length > 0 &&
chatStore.history.filter((msg) => !msg.example).length == 0 && (
<p className="break-all opacity-80 p-3 rounded bg-white my-3 text-left dark:text-black">