fix: refresh model list after api key changes (#944)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { IconButton } from '~/components/ui/IconButton';
|
||||
import type { ProviderInfo } from '~/types/model';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
interface APIKeyManagerProps {
|
||||
provider: ProviderInfo;
|
||||
@@ -10,6 +11,23 @@ interface APIKeyManagerProps {
|
||||
labelForGetApiKey?: string;
|
||||
}
|
||||
|
||||
const apiKeyMemoizeCache: { [k: string]: Record<string, string> } = {};
|
||||
|
||||
export function getApiKeysFromCookies() {
|
||||
const storedApiKeys = Cookies.get('apiKeys');
|
||||
let parsedKeys = {};
|
||||
|
||||
if (storedApiKeys) {
|
||||
parsedKeys = apiKeyMemoizeCache[storedApiKeys];
|
||||
|
||||
if (!parsedKeys) {
|
||||
parsedKeys = apiKeyMemoizeCache[storedApiKeys] = JSON.parse(storedApiKeys);
|
||||
}
|
||||
}
|
||||
|
||||
return parsedKeys;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export const APIKeyManager: React.FC<APIKeyManagerProps> = ({ provider, apiKey, setApiKey }) => {
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
|
||||
Reference in New Issue
Block a user