mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
* 🤖 Assistants V2 Support: Part 1 - Separated Azure Assistants to its own endpoint - File Search / Vector Store integration is incomplete, but can toggle and use storage from playground - Code Interpreter resource files can be added but not deleted - GPT-4o is supported - Many improvements to the Assistants Endpoint overall data-provider v2 changes copy existing route as v1 chore: rename new endpoint to reduce comparison operations and add new azure filesource api: add azureAssistants part 1 force use of version for assistants/assistantsAzure chore: switch name back to azureAssistants refactor type version: string | number Ensure assistants endpoints have version set fix: isArchived type issue in ConversationListParams refactor: update assistants mutations/queries with endpoint/version definitions, update Assistants Map structure chore: FilePreview component ExtendedFile type assertion feat: isAssistantsEndpoint helper chore: remove unused useGenerations chore(buildTree): type issue chore(Advanced): type issue (unused component, maybe in future) first pass for multi-assistant endpoint rewrite fix(listAssistants): pass params correctly feat: list separate assistants by endpoint fix(useTextarea): access assistantMap correctly fix: assistant endpoint switching, resetting ID fix: broken during rewrite, selecting assistant mention fix: set/invalidate assistants endpoint query data correctly feat: Fix issue with assistant ID not being reset correctly getOpenAIClient helper function feat: add toast for assistant deletion fix: assistants delete right after create issue for azure fix: assistant patching refactor: actions to use getOpenAIClient refactor: consolidate logic into helpers file fix: issue where conversation data was not initially available v1 chat support refactor(spendTokens): only early return if completionTokens isNaN fix(OpenAIClient): ensure spendTokens has all necessary params refactor: route/controller logic fix(assistants/initializeClient): use defaultHeaders field fix: sanitize default operation id chore: bump openai package first pass v2 action service feat: retroactive domain parsing for actions added via v1 feat: delete db records of actions/assistants on openai assistant deletion chore: remove vision tools from v2 assistants feat: v2 upload and delete assistant vision images WIP first pass, thread attachments fix: show assistant vision files (save local/firebase copy) v2 image continue fix: annotations fix: refine annotations show analyze as error if is no longer submitting before progress reaches 1 and show file_search as retrieval tool fix: abort run, undefined endpoint issue refactor: consolidate capabilities logic and anticipate versioning frontend version 2 changes fix: query selection and filter add endpoint to unknown filepath add file ids to resource, deleting in progress enable/disable file search remove version log * 🤖 Assistants V2 Support: Part 2 🎹 fix: Autocompletion Chrome Bug on Action API Key Input chore: remove `useOriginNavigate` chore: set correct OpenAI Storage Source fix: azure file deletions, instantiate clients by source for deletion update code interpret files info feat: deleteResourceFileId chore: increase poll interval as azure easily rate limits fix: openai file deletions, TODO: evaluate rejected deletion settled promises to determine which to delete from db records file source icons update table file filters chore: file search info and versioning fix: retrieval update with necessary tool_resources if specified fix(useMentions): add optional chaining in case listMap value is undefined fix: force assistant avatar roundedness fix: azure assistants, check correct flag chore: bump data-provider * fix: merge conflict * ci: fix backend tests due to new updates * chore: update .env.example * meilisearch improvements * localization updates * chore: update comparisons * feat: add additional metadata: endpoint, author ID * chore: azureAssistants ENDPOINTS exclusion warning
204 lines
6.9 KiB
TypeScript
204 lines
6.9 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { useForm, FormProvider } from 'react-hook-form';
|
|
import { EModelEndpoint, alternateName, isAssistantsEndpoint } from 'librechat-data-provider';
|
|
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query';
|
|
import type { TDialogProps } from '~/common';
|
|
import DialogTemplate from '~/components/ui/DialogTemplate';
|
|
import { RevokeKeysButton } from '~/components/Nav';
|
|
import { Dialog, Dropdown } from '~/components/ui';
|
|
import { useUserKey, useLocalize } from '~/hooks';
|
|
import { useToastContext } from '~/Providers';
|
|
import CustomConfig from './CustomEndpoint';
|
|
import GoogleConfig from './GoogleConfig';
|
|
import OpenAIConfig from './OpenAIConfig';
|
|
import OtherConfig from './OtherConfig';
|
|
import HelpText from './HelpText';
|
|
|
|
const endpointComponents = {
|
|
[EModelEndpoint.google]: GoogleConfig,
|
|
[EModelEndpoint.openAI]: OpenAIConfig,
|
|
[EModelEndpoint.custom]: CustomConfig,
|
|
[EModelEndpoint.azureOpenAI]: OpenAIConfig,
|
|
[EModelEndpoint.gptPlugins]: OpenAIConfig,
|
|
[EModelEndpoint.assistants]: OpenAIConfig,
|
|
[EModelEndpoint.azureAssistants]: OpenAIConfig,
|
|
default: OtherConfig,
|
|
};
|
|
|
|
const formSet: Set<string> = new Set([
|
|
EModelEndpoint.openAI,
|
|
EModelEndpoint.custom,
|
|
EModelEndpoint.azureOpenAI,
|
|
EModelEndpoint.gptPlugins,
|
|
EModelEndpoint.assistants,
|
|
EModelEndpoint.azureAssistants,
|
|
]);
|
|
|
|
const EXPIRY = {
|
|
THIRTY_MINUTES: { display: 'in 30 minutes', value: 30 * 60 * 1000 },
|
|
TWO_HOURS: { display: 'in 2 hours', value: 2 * 60 * 60 * 1000 },
|
|
TWELVE_HOURS: { display: 'in 12 hours', value: 12 * 60 * 60 * 1000 },
|
|
ONE_DAY: { display: 'in 1 day', value: 24 * 60 * 60 * 1000 },
|
|
ONE_WEEK: { display: 'in 7 days', value: 7 * 24 * 60 * 60 * 1000 },
|
|
ONE_MONTH: { display: 'in 30 days', value: 30 * 24 * 60 * 60 * 1000 },
|
|
};
|
|
|
|
const SetKeyDialog = ({
|
|
open,
|
|
onOpenChange,
|
|
endpoint,
|
|
endpointType,
|
|
userProvideURL,
|
|
}: Pick<TDialogProps, 'open' | 'onOpenChange'> & {
|
|
endpoint: EModelEndpoint | string;
|
|
endpointType?: EModelEndpoint;
|
|
userProvideURL?: boolean | null;
|
|
}) => {
|
|
const methods = useForm({
|
|
defaultValues: {
|
|
apiKey: '',
|
|
baseURL: '',
|
|
azureOpenAIApiKey: '',
|
|
azureOpenAIApiInstanceName: '',
|
|
azureOpenAIApiDeploymentName: '',
|
|
azureOpenAIApiVersion: '',
|
|
// TODO: allow endpoint definitions from user
|
|
// name: '',
|
|
// TODO: add custom endpoint models defined by user
|
|
// models: '',
|
|
},
|
|
});
|
|
|
|
const [userKey, setUserKey] = useState('');
|
|
const { data: endpointsConfig } = useGetEndpointsQuery();
|
|
const [expiresAtLabel, setExpiresAtLabel] = useState(EXPIRY.TWELVE_HOURS.display);
|
|
const { getExpiry, saveUserKey } = useUserKey(endpoint);
|
|
const { showToast } = useToastContext();
|
|
const localize = useLocalize();
|
|
|
|
const expirationOptions = Object.values(EXPIRY);
|
|
|
|
const handleExpirationChange = (label: string) => {
|
|
setExpiresAtLabel(label);
|
|
};
|
|
|
|
const submit = () => {
|
|
const selectedOption = expirationOptions.find((option) => option.display === expiresAtLabel);
|
|
const expiresAt = Date.now() + (selectedOption ? selectedOption.value : 0);
|
|
|
|
const saveKey = (key: string) => {
|
|
saveUserKey(key, expiresAt);
|
|
onOpenChange(false);
|
|
};
|
|
|
|
if (formSet.has(endpoint) || formSet.has(endpointType ?? '')) {
|
|
// TODO: handle other user provided options besides baseURL and apiKey
|
|
methods.handleSubmit((data) => {
|
|
const isAzure = endpoint === EModelEndpoint.azureOpenAI;
|
|
const isOpenAIBase =
|
|
isAzure ||
|
|
endpoint === EModelEndpoint.openAI ||
|
|
endpoint === EModelEndpoint.gptPlugins ||
|
|
isAssistantsEndpoint(endpoint);
|
|
if (isAzure) {
|
|
data.apiKey = 'n/a';
|
|
}
|
|
|
|
const emptyValues = Object.keys(data).filter((key) => {
|
|
if (!isAzure && key.startsWith('azure')) {
|
|
return false;
|
|
}
|
|
if (isOpenAIBase && key === 'baseURL') {
|
|
return false;
|
|
}
|
|
if (key === 'baseURL' && !userProvideURL) {
|
|
return false;
|
|
}
|
|
return data[key] === '';
|
|
});
|
|
|
|
if (emptyValues.length > 0) {
|
|
showToast({
|
|
message: 'The following fields are required: ' + emptyValues.join(', '),
|
|
status: 'error',
|
|
});
|
|
onOpenChange(true);
|
|
return;
|
|
}
|
|
|
|
const { apiKey, baseURL, ...azureOptions } = data;
|
|
const userProvidedData = { apiKey, baseURL };
|
|
if (isAzure) {
|
|
userProvidedData.apiKey = JSON.stringify({
|
|
azureOpenAIApiKey: azureOptions.azureOpenAIApiKey,
|
|
azureOpenAIApiInstanceName: azureOptions.azureOpenAIApiInstanceName,
|
|
azureOpenAIApiDeploymentName: azureOptions.azureOpenAIApiDeploymentName,
|
|
azureOpenAIApiVersion: azureOptions.azureOpenAIApiVersion,
|
|
});
|
|
}
|
|
|
|
saveKey(JSON.stringify(userProvidedData));
|
|
methods.reset();
|
|
})();
|
|
return;
|
|
}
|
|
|
|
saveKey(userKey);
|
|
setUserKey('');
|
|
};
|
|
|
|
const EndpointComponent =
|
|
endpointComponents[endpointType ?? endpoint] ?? endpointComponents['default'];
|
|
const expiryTime = getExpiry();
|
|
const config = endpointsConfig?.[endpoint];
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogTemplate
|
|
title={`${localize('com_endpoint_config_key_for')} ${alternateName[endpoint] ?? endpoint}`}
|
|
className="w-11/12 max-w-[650px] sm:w-3/4 md:w-3/4 lg:w-3/4"
|
|
main={
|
|
<div className="grid w-full items-center gap-2">
|
|
<small className="text-red-600">
|
|
{`${localize('com_endpoint_config_key_encryption')} ${
|
|
!expiryTime
|
|
? localize('com_endpoint_config_key_expiry')
|
|
: `${new Date(expiryTime).toLocaleString()}`
|
|
}`}
|
|
</small>
|
|
<Dropdown
|
|
label="Expires "
|
|
value={expiresAtLabel}
|
|
onChange={handleExpirationChange}
|
|
options={expirationOptions.map((option) => option.display)}
|
|
width={185}
|
|
/>
|
|
<FormProvider {...methods}>
|
|
<EndpointComponent
|
|
userKey={userKey}
|
|
setUserKey={setUserKey}
|
|
endpoint={
|
|
endpoint === EModelEndpoint.gptPlugins && config?.azure
|
|
? EModelEndpoint.azureOpenAI
|
|
: endpoint
|
|
}
|
|
userProvideURL={userProvideURL}
|
|
/>
|
|
</FormProvider>
|
|
<HelpText endpoint={endpoint} />
|
|
</div>
|
|
}
|
|
selection={{
|
|
selectHandler: submit,
|
|
selectClasses: 'bg-green-500 hover:bg-green-600 dark:hover:bg-green-600 text-white',
|
|
selectText: localize('com_ui_submit'),
|
|
}}
|
|
leftButtons={
|
|
<RevokeKeysButton endpoint={endpoint} showText={false} disabled={!expiryTime} />
|
|
}
|
|
/>
|
|
</Dialog>
|
|
);
|
|
};
|
|
|
|
export default SetKeyDialog;
|