mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-22 10:24:09 +01:00
feat: OpenRouter Support & Improve Model Fetching ⇆ (#936)
* chore(ChatGPTClient.js): add support for OpenRouter API chore(OpenAIClient.js): add support for OpenRouter API * chore: comment out token debugging * chore: add back streamResult assignment * chore: remove double condition/assignment from merging * refactor(routes/endpoints): -> controller/services logic * feat: add openrouter model fetching * chore: remove unused endpointsConfig in cleanupPreset function * refactor: separate models concern from endpointsConfig * refactor(data-provider): add TModels type and make TEndpointsConfig adaptible to new endpoint keys * refactor: complete models endpoint service in data-provider * refactor: onMutate for refreshToken and login, invalidate models query * feat: complete models endpoint logic for frontend * chore: remove requireJwtAuth from /api/endpoints and /api/models as not implemented yet * fix: endpoint will not be overwritten and instead use active value * feat: openrouter support for plugins * chore(EndpointOptionsDialog): remove unused recoil value * refactor(schemas/parseConvo): add handling of secondaryModels to use first of defined secondary models, which includes last selected one as first, or default to the convo's secondary model value * refactor: remove hooks from store and move to hooks refactor(switchToConversation): make switchToConversation use latest recoil state, which is necessary to get the most up-to-date models list, replace wrapper function refactor(getDefaultConversation): factor out logic into 3 pieces to reduce complexity. * fix: backend tests * feat: optimistic update by calling newConvo when models are fetched * feat: openrouter support for titling convos * feat: cache models fetch * chore: add missing dep to AuthContext useEffect * chore: fix useTimeout types * chore: delete old getDefaultConvo file * chore: remove newConvo logic from Root, remove console log from api models caching * chore: ensure bun is used for building in b:client script * fix: default endpoint will not default to null on a completely fresh login (no localStorage/cookies) * chore: add openrouter docs to free_ai_apis.md and .env.example * chore: remove openrouter console logs * feat: add debugging env variable for Plugins
This commit is contained in:
parent
ccb46164c0
commit
fd70e21732
58 changed files with 809 additions and 523 deletions
|
|
@ -1,19 +1,19 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { useAuthContext } from '~/hooks';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
|
||||
import Landing from '~/components/ui/Landing';
|
||||
import Messages from '~/components/Messages/Messages';
|
||||
import TextChat from '~/components/Input/TextChat';
|
||||
|
||||
import store from '~/store';
|
||||
import {
|
||||
useGetMessagesByConvoId,
|
||||
useGetConversationByIdMutation,
|
||||
useGetStartupConfig,
|
||||
} from 'librechat-data-provider';
|
||||
|
||||
import Landing from '~/components/ui/Landing';
|
||||
import Messages from '~/components/Messages/Messages';
|
||||
import TextChat from '~/components/Input/TextChat';
|
||||
|
||||
import { useAuthContext, useConversation } from '~/hooks';
|
||||
import store from '~/store';
|
||||
|
||||
export default function Chat() {
|
||||
const { isAuthenticated } = useAuthContext();
|
||||
const [shouldNavigate, setShouldNavigate] = useState(true);
|
||||
|
|
@ -22,7 +22,7 @@ export default function Chat() {
|
|||
const setMessages = useSetRecoilState(store.messages);
|
||||
const messagesTree = useRecoilValue(store.messagesTree);
|
||||
const isSubmitting = useRecoilValue(store.isSubmitting);
|
||||
const { newConversation } = store.useConversation();
|
||||
const { newConversation } = useConversation();
|
||||
const { conversationId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { useRecoilValue, useSetRecoilState } from 'recoil';
|
|||
import { Outlet } from 'react-router-dom';
|
||||
import {
|
||||
useGetEndpointsQuery,
|
||||
useGetModelsQuery,
|
||||
useGetPresetsQuery,
|
||||
useGetSearchEnabledQuery,
|
||||
} from 'librechat-data-provider';
|
||||
|
|
@ -13,6 +14,7 @@ import { useAuthContext, useServerStream } from '~/hooks';
|
|||
import store from '~/store';
|
||||
|
||||
export default function Root() {
|
||||
const { user, isAuthenticated } = useAuthContext();
|
||||
const [navVisible, setNavVisible] = useState(() => {
|
||||
const savedNavVisible = localStorage.getItem('navVisible');
|
||||
return savedNavVisible !== null ? JSON.parse(savedNavVisible) : false;
|
||||
|
|
@ -21,13 +23,14 @@ export default function Root() {
|
|||
const submission = useRecoilValue(store.submission);
|
||||
useServerStream(submission ?? null);
|
||||
|
||||
const setPresets = useSetRecoilState(store.presets);
|
||||
const setIsSearchEnabled = useSetRecoilState(store.isSearchEnabled);
|
||||
const setEndpointsConfig = useSetRecoilState(store.endpointsConfig);
|
||||
const setPresets = useSetRecoilState(store.presets);
|
||||
const { user, isAuthenticated } = useAuthContext();
|
||||
const setModelsConfig = useSetRecoilState(store.modelsConfig);
|
||||
|
||||
const searchEnabledQuery = useGetSearchEnabledQuery();
|
||||
const endpointsQuery = useGetEndpointsQuery();
|
||||
const modelsQuery = useGetModelsQuery();
|
||||
const presetsQuery = useGetPresetsQuery({ enabled: !!user });
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -42,6 +45,14 @@ export default function Root() {
|
|||
}
|
||||
}, [endpointsQuery.data, endpointsQuery.isError]);
|
||||
|
||||
useEffect(() => {
|
||||
if (modelsQuery.data) {
|
||||
setModelsConfig(modelsQuery.data);
|
||||
} else if (modelsQuery.isError) {
|
||||
console.error('Failed to get models', modelsQuery.error);
|
||||
}
|
||||
}, [modelsQuery.data, modelsQuery.isError]);
|
||||
|
||||
useEffect(() => {
|
||||
if (presetsQuery.data) {
|
||||
setPresets(presetsQuery.data);
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ import { useRecoilState, useRecoilValue } from 'recoil';
|
|||
import Messages from '~/components/Messages/Messages';
|
||||
import TextChat from '~/components/Input/TextChat';
|
||||
|
||||
import { useConversation } from '~/hooks';
|
||||
import store from '~/store';
|
||||
|
||||
export default function Search() {
|
||||
const [searchQuery, setSearchQuery] = useRecoilState(store.searchQuery);
|
||||
const conversation = useRecoilValue(store.conversation);
|
||||
const { searchPlaceholderConversation } = store.useConversation();
|
||||
const { searchPlaceholderConversation } = useConversation();
|
||||
const { query } = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue