Merge branch 'main' into terminal-error-detection
This commit is contained in:
@@ -125,6 +125,9 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
||||
|
||||
useEffect(() => {
|
||||
// Load API keys from cookies on component mount
|
||||
|
||||
let parsedApiKeys: Record<string, string> | undefined = {};
|
||||
|
||||
try {
|
||||
const storedApiKeys = Cookies.get('apiKeys');
|
||||
|
||||
@@ -133,6 +136,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
||||
|
||||
if (typeof parsedKeys === 'object' && parsedKeys !== null) {
|
||||
setApiKeys(parsedKeys);
|
||||
parsedApiKeys = parsedKeys;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -161,7 +165,8 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
||||
Cookies.remove('providers');
|
||||
}
|
||||
|
||||
initializeModelList(providerSettings).then((modelList) => {
|
||||
initializeModelList({ apiKeys: parsedApiKeys, providerSettings }).then((modelList) => {
|
||||
console.log('Model List: ', modelList);
|
||||
setModelList(modelList);
|
||||
});
|
||||
|
||||
@@ -381,7 +386,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
||||
modelList={modelList}
|
||||
provider={provider}
|
||||
setProvider={setProvider}
|
||||
providerList={providerList || PROVIDER_LIST}
|
||||
providerList={providerList || (PROVIDER_LIST as ProviderInfo[])}
|
||||
apiKeys={apiKeys}
|
||||
/>
|
||||
{(providerList || []).length > 0 && provider && (
|
||||
|
||||
@@ -21,6 +21,7 @@ import { debounce } from '~/utils/debounce';
|
||||
import { useSettings } from '~/lib/hooks/useSettings';
|
||||
import type { ProviderInfo } from '~/types/model';
|
||||
import { useSearchParams } from '@remix-run/react';
|
||||
import { createSampler } from '~/utils/sampler';
|
||||
|
||||
const toastAnimation = cssTransition({
|
||||
enter: 'animated fadeInRight',
|
||||
@@ -77,6 +78,24 @@ export function Chat() {
|
||||
);
|
||||
}
|
||||
|
||||
const processSampledMessages = createSampler(
|
||||
(options: {
|
||||
messages: Message[];
|
||||
initialMessages: Message[];
|
||||
isLoading: boolean;
|
||||
parseMessages: (messages: Message[], isLoading: boolean) => void;
|
||||
storeMessageHistory: (messages: Message[]) => Promise<void>;
|
||||
}) => {
|
||||
const { messages, initialMessages, isLoading, parseMessages, storeMessageHistory } = options;
|
||||
parseMessages(messages, isLoading);
|
||||
|
||||
if (messages.length > initialMessages.length) {
|
||||
storeMessageHistory(messages).catch((error) => toast.error(error.message));
|
||||
}
|
||||
},
|
||||
50,
|
||||
);
|
||||
|
||||
interface ChatProps {
|
||||
initialMessages: Message[];
|
||||
storeMessageHistory: (messages: Message[]) => Promise<void>;
|
||||
@@ -104,7 +123,7 @@ export const ChatImpl = memo(
|
||||
});
|
||||
const [provider, setProvider] = useState(() => {
|
||||
const savedProvider = Cookies.get('selectedProvider');
|
||||
return PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER;
|
||||
return (PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER) as ProviderInfo;
|
||||
});
|
||||
|
||||
const { showChat } = useStore(chatStore);
|
||||
@@ -170,11 +189,13 @@ export const ChatImpl = memo(
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
parseMessages(messages, isLoading);
|
||||
|
||||
if (messages.length > initialMessages.length) {
|
||||
storeMessageHistory(messages).catch((error) => toast.error(error.message));
|
||||
}
|
||||
processSampledMessages({
|
||||
messages,
|
||||
initialMessages,
|
||||
isLoading,
|
||||
parseMessages,
|
||||
storeMessageHistory,
|
||||
});
|
||||
}, [messages, isLoading, parseMessages]);
|
||||
|
||||
const scrollTextArea = () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ProviderInfo } from '~/types/model';
|
||||
import type { ModelInfo } from '~/utils/types';
|
||||
import { useEffect } from 'react';
|
||||
import type { ModelInfo } from '~/lib/modules/llm/types';
|
||||
|
||||
interface ModelSelectorProps {
|
||||
model?: string;
|
||||
|
||||
Reference in New Issue
Block a user