2023-04-10 00:41:34 +08:00
|
|
|
import React, { useState } from 'react';
|
2023-07-06 11:47:08 -04:00
|
|
|
import { StopGeneratingIcon } from '~/components';
|
2023-04-10 00:41:34 +08:00
|
|
|
import { Settings } from 'lucide-react';
|
2023-07-06 11:47:08 -04:00
|
|
|
import { SetTokenDialog } from './SetTokenDialog';
|
|
|
|
|
import store from '~/store';
|
2023-04-10 00:41:34 +08:00
|
|
|
|
|
|
|
|
export default function SubmitButton({
|
|
|
|
|
endpoint,
|
|
|
|
|
submitMessage,
|
|
|
|
|
handleStopGenerating,
|
|
|
|
|
disabled,
|
|
|
|
|
isSubmitting,
|
2023-07-14 09:36:49 -04:00
|
|
|
endpointsConfig,
|
2023-04-10 00:41:34 +08:00
|
|
|
}) {
|
|
|
|
|
const [setTokenDialogOpen, setSetTokenDialogOpen] = useState(false);
|
|
|
|
|
const { getToken } = store.useToken(endpoint);
|
|
|
|
|
|
|
|
|
|
const isTokenProvided = endpointsConfig?.[endpoint]?.userProvide ? !!getToken() : true;
|
2023-07-12 11:37:27 -04:00
|
|
|
const endpointsToHideSetTokens = new Set(['openAI', 'azureOpenAI', 'bingAI']);
|
2023-02-06 21:17:46 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const clickHandler = (e) => {
|
2023-02-07 16:22:35 -05:00
|
|
|
e.preventDefault();
|
|
|
|
|
submitMessage();
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-10 00:41:34 +08:00
|
|
|
const setToken = () => {
|
|
|
|
|
setSetTokenDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-21 11:13:31 -04:00
|
|
|
if (isSubmitting) {
|
2023-02-07 16:22:35 -05:00
|
|
|
return (
|
2023-03-16 13:29:13 -04:00
|
|
|
<button
|
2023-04-01 02:12:15 +08:00
|
|
|
onClick={handleStopGenerating}
|
|
|
|
|
type="button"
|
2023-06-21 11:13:31 -04:00
|
|
|
className="group absolute bottom-0 right-0 z-[101] flex h-[100%] w-[50px] items-center justify-center bg-transparent p-1 text-gray-500"
|
2023-03-16 13:29:13 -04:00
|
|
|
>
|
2023-05-18 04:51:30 +05:30
|
|
|
<div className="m-1 mr-0 rounded-md p-2 pb-[10px] pt-[10px] group-hover:bg-gray-100 group-disabled:hover:bg-transparent dark:group-hover:bg-gray-900 dark:group-hover:text-gray-400 dark:group-disabled:hover:bg-transparent">
|
2023-04-01 02:12:15 +08:00
|
|
|
<StopGeneratingIcon />
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
2023-07-12 11:37:27 -04:00
|
|
|
} else if (!isTokenProvided && (!endpointsToHideSetTokens.has(endpoint))) {
|
2023-04-10 00:41:34 +08:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<button
|
|
|
|
|
onClick={setToken}
|
|
|
|
|
type="button"
|
2023-06-21 11:13:31 -04:00
|
|
|
className="group absolute bottom-0 right-0 z-[101] flex h-[100%] w-auto items-center justify-center bg-transparent p-1 text-gray-500"
|
2023-04-10 00:41:34 +08:00
|
|
|
>
|
2023-05-18 04:51:30 +05:30
|
|
|
<div className="m-1 mr-0 rounded-md p-2 pb-[10px] pt-[10px] align-middle text-xs group-hover:bg-gray-100 group-disabled:hover:bg-transparent dark:group-hover:bg-gray-900 dark:group-hover:text-gray-400 dark:group-disabled:hover:bg-transparent">
|
2023-04-10 00:41:34 +08:00
|
|
|
<Settings className="mr-1 inline-block w-[18px]" />
|
|
|
|
|
Set Token First
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
<SetTokenDialog
|
|
|
|
|
open={setTokenDialogOpen}
|
|
|
|
|
onOpenChange={setSetTokenDialogOpen}
|
|
|
|
|
endpoint={endpoint}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-06-21 11:13:31 -04:00
|
|
|
} else {
|
2023-04-01 02:12:15 +08:00
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
onClick={clickHandler}
|
|
|
|
|
disabled={disabled}
|
2023-06-21 11:13:31 -04:00
|
|
|
className="group absolute bottom-0 right-0 z-[101] flex h-[100%] w-[50px] items-center justify-center bg-transparent p-1 text-gray-500"
|
2023-04-01 02:12:15 +08:00
|
|
|
>
|
2023-06-21 11:13:31 -04:00
|
|
|
<div className="m-1 mr-0 rounded-md pb-[9px] pl-[9.5px] pr-[7px] pt-[11px] group-hover:bg-gray-100 group-disabled:hover:bg-transparent dark:group-hover:bg-gray-900 dark:group-hover:text-gray-400 dark:group-disabled:hover:bg-transparent">
|
2023-04-01 02:12:15 +08:00
|
|
|
<svg
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
fill="none"
|
|
|
|
|
strokeWidth="2"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
strokeLinecap="round"
|
|
|
|
|
strokeLinejoin="round"
|
|
|
|
|
className="mr-1 h-4 w-4 "
|
|
|
|
|
height="1em"
|
|
|
|
|
width="1em"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
2023-03-29 01:09:03 +08:00
|
|
|
>
|
2023-05-18 11:09:31 -07:00
|
|
|
<line x1="22" y1="2" x2="11" y2="13" />
|
2023-04-01 02:12:15 +08:00
|
|
|
<polygon points="22 2 15 22 11 13 2 9 22 2" />
|
|
|
|
|
</svg>
|
2023-02-07 16:22:35 -05:00
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
2023-06-21 11:13:31 -04:00
|
|
|
}
|
2023-02-06 21:17:46 -05:00
|
|
|
}
|
2023-02-07 16:22:35 -05:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* <div class="text-2xl"><span class="">·</span><span class="">·</span><span class="invisible">·</span></div> */
|
|
|
|
|
}
|