import { useEffect, useState } from 'react';
import DialogTemplate from '../../ui/DialogTemplate';
import { Dialog } from '../../ui/Dialog.tsx';
import * as Checkbox from '@radix-ui/react-checkbox';
import { CheckIcon } from '@radix-ui/react-icons';
import FileUpload from '../NewConversationMenu/FileUpload';
import store from '~/store';
import InputWithLabel from './InputWithLabel';
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
const SetTokenDialog = ({ open, onOpenChange, endpoint }) => {
const [token, setToken] = useState('');
const [showPanel, setShowPanel] = useState(false);
const { getToken, saveToken } = store.useToken(endpoint);
const submit = () => {
saveToken(token);
onOpenChange(false);
};
useEffect(() => {
let oldToken = getToken();
if (isJson(token)) {
setShowPanel(true);
}
setToken(oldToken ?? '');
}, [open]);
useEffect(() => {
if (!showPanel && isJson(token)) {
setToken('');
}
}, [showPanel]);
const helpText = {
bingAI: (
{`As of 5/23/23, to use Bing, you will need your full cookie string from bing.com. Use dev tools or an extension while
logged into the site to view it in your network request Cookie header value. For full instructions, see my `}
comment here
),
chatGPTBrowser: (
{`To get your Access token For ChatGPT 'Free Version', login to `}
https://chat.openai.com
, then visit{' '}
https://chat.openai.com/api/auth/session
. Copy access token.
),
google: (
You need to{' '}
Enable Vertex AI
{' '}
API on Google Cloud, then{' '}
Create a Service Account
{`. Make sure to click 'Create and Continue' to give at least the 'Vertex AI User' role.
Lastly, create a JSON key to import here.`}
)
};
function getAzure(name) {
if (isJson(token)) {
let newToken = JSON.parse(token);
return newToken[name];
} else {
return '';
}
}
function setAzure(name, value) {
let newToken = {};
if (isJson(token)) {
newToken = JSON.parse(token);
}
newToken[name] = value;
setToken(JSON.stringify(newToken));
}
return (
);
};
export default SetTokenDialog;