Compare commits

...

101 Commits

Author SHA1 Message Date
Fuegovic
f101419af3 docs: general update (#781)
* Update windows_install.md

* Update linux_install.md

* Update mac_install.md

* Update docker_install.md

* Update linux_install.md

* Update windows_install.md

* Update README.md

* Update breaking_changes.md

* Update breaking_changes.md
2023-08-09 13:38:17 -04:00
Danny Avila
251d8ac410 Release 0.5.7 (#780) 2023-08-09 12:22:05 -04:00
Danny Avila
bdccadbe06 fix(playwright.yml): fix condition for running Playwright tests on pull requests
The condition for running Playwright tests on pull requests was not properly formatted. The repository name was not enclosed in quotes. This commit fixes the condition by adding single quotes around the repository name.
2023-08-09 10:28:04 -04:00
Danny Avila
70a56ac04a chore(client): update @vitejs/plugin-react to version 4.0.4
chore(client): update vite to version 4.4.9
2023-08-09 10:28:04 -04:00
Danny Avila
193ed93ee8 chore(style.css): update font paths to use a variable for the fonts directory
chore(vite.config.ts): import the resolve function from the path module
2023-08-09 10:28:04 -04:00
Danny Avila
b096fb98ce chore: remove next.js artifacts from ui primitives 2023-08-09 10:28:04 -04:00
Danny Avila
002bba20f9 refactor(Slider.tsx): remove unused import and type declaration
fix(Slider.tsx): fix type error in onClick event handler
2023-08-09 10:28:04 -04:00
Fuegovic
b896225bd8 Language Translation: French (#778) 2023-08-09 09:27:32 -04:00
XHyperDEVX
de34d8b47c feat: German translations (#772)
* Language translation: German translation

* Language translation: German translation

* Language translation: German translation
2023-08-08 11:48:56 -04:00
Danny Avila
759e585c29 chore(playwright.yml): add condition to run the job only for pull requests from danny-avila/LibreChat repository (#773)
chore(playwright.yml): comment out caching of Node.js modules and Playwright installations
2023-08-08 11:35:17 -04:00
Danny Avila
c6f5d5d65c ci: add e2e workflow, optimize client code for testing (#771)
* refactor(e2e): fix tests with latest changes, convert to TS, use test Ids

* chore(EndpointMenu.jsx): add data-testid attribute to new-conversation-menu button

* refactor(EndpointItem): add data-testid attr., convert to TS

* refactor(e2e): remove unnecessary awaits and convert to TS

* chore(playwright.config.local.ts): add absolute path to server index.js file
chore(playwright.config.local.ts): add dotenv configuration
chore(playwright.config.local.ts): change webServer command to use absolute path
chore(playwright.config.local.ts): add NODE_ENV and process.env to webServer env
chore(playwright.config.local.ts): remove unused import
chore(login.spec.js): delete login.spec.js file

* chore(.gitignore): add 'my.secrets' to the list of ignored files
fix(Registration.tsx): add 'data-testid' attribute to the error message div
fix(Registration.spec.tsx): comment out test case that calls 'registerUser.mutate'

* chore(ConvoIcon.tsx): add data-testid attribute to svg element
chore(messages.spec.ts): refactor conversation navigation logic

* chore(playwright.config.ts): add support for absolute path to server index.js file
feat(playwright.config.ts): add support for dotenv configuration
feat(playwright.config.ts): set NODE_ENV to 'production' in webServer environment variables

* chore(workflows): comment out push event and specify paths for pull_request event in backend-review.yml
chore(workflows): comment out push event and specify paths for pull_request event in frontend-review.yml

* chore(install.js): add check to skip install script in CI environment

* chore: complete playwright workflow

* chore(Landing.tsx): add data-testid attribute to landing title element
chore(authenticate.ts): update selector to wait for landing title element by test id instead of text content

* chore(playwright.yml): add step to upload screenshot artifact on failure
fix(authenticate.ts): capture screenshot before waiting for landing title and increase timeout due to GH Actions load time

* chore(playwright.yml): rename artifact name from 'screenshot' to 'login-screenshot'
feat(LoginForm.tsx): add data-testid attribute to login button
fix(authenticate.ts): change screenshot name to 'login-screenshot.png' and conditionally take screenshot only in CI environment

* chore(playwright.yml): add CI environment variable and set it to true

* chore(playwright.yml): update Playwright installation command
chore(playwright.config.ts): update storageState path to use process.cwd()

* fix(playwright.yml): update node version to 18 in setup-node action
fix(playwright.yml): update actions/cache to v3 in Cache Node.js modules step
fix(playwright.yml): update actions/cache to v3 in Cache Playwright installations step
fix(authenticate.ts): change login button click to press 'Enter' on password input

* chore(playwright.yml): update E2E_USER_EMAIL and E2E_USER_PASSWORD values for testing purposes
chore(authenticate.ts): add console.dir to log user object for debugging

* chore(playwright.yml): add step to upload storageState artifact

The storageState artifact is now uploaded as part of the workflow. This artifact contains the state of the storage used during the end-to-end tests. It will be retained for 2 days.

* chore(playwright.yml): comment out upload screenshot step
chore(playwright.config.ts): change NODE_ENV to development
chore(authenticate.ts): comment out screenshot related code

* chore(playwright.config.ts): add SESSION_EXPIRY environment variable with value 86400000

* chore(playwright.yml): update environment variables in Playwright workflow
fix(General.tsx): add data-testid attributes to clear conversations buttons
test(messages.spec.ts): add setup and teardown steps for clearing conversations before and after tests

* fix(messages.spec.ts): fix clearing conversations before and after message tests
feat(messages.spec.ts): add beforeEach and afterEach hooks to create and close new page for each test

* chore: remove storageStage upload artifact
2023-08-08 11:17:15 -04:00
Danny Avila
cb3cf9b33e chore: Update pull_request_template.md 2023-08-07 12:27:48 -04:00
Danny Avila
68ad46a9be fix(typing): minor typing resolutions and convert SearchBar to TS (#766)
* refactor(SearchBar): convert to TS, useLocalize

* fix(typing): minor type issues

* chore(package.json): add 'reinstall:docker' script for rebuilding Docker environment in current branch
2023-08-06 21:30:16 -04:00
Danny Avila
600a0d15b1 fix(backend-review.yml): update Node.js version from 19.x to 20.x (#767)
fix(frontend-review.yml): update Node.js version from 19.x to 20.x
2023-08-06 13:08:23 -04:00
Danny Avila
92f87b8dcc fix: strict typescript issue, plugins localStorage, both causing App Errors (#765)
* fix(Enum): cannot be used as a value when imported as type

* hotfix(types): corrected types, some causing application error (bing null model)

* hotfix(Plugins): fix undefined localStorage item causing Application error
2023-08-06 11:26:37 -04:00
Danny Avila
06a7fba39b fix(Enum): cannot be used as a value when imported as type (#764) 2023-08-05 20:23:07 -04:00
Dan Orlando
96d29f7390 refactor(client): Refactors recent typescript changes for best practices (#763)
* create common types in client

* remove unnecessary rules from eslint config

* cleanup types

* put back eslintrc rules
2023-08-05 16:45:26 -04:00
Danny Avila
5828200197 refactor(types): use zod for better type safety, style(Messages): new scroll behavior, style(Buttons): match ChatGPT (#761)
* feat: add zod schemas for better type safety

* refactor(useSetOptions): remove 'as Type' in favor of zod schema

* fix: descendant console error, change <p> tag to <div> tag for content in PluginTooltip component

* style(MessagesView): instant/snappier scroll behavior matching official site

* fix(Messages): add null check for scrollableRef before accessing its properties in handleScroll and useEffect

* fix(messageSchema.js): change type of invocationId from string to number
fix(schemas.ts): make authenticated property in tPluginSchema optional
fix(schemas.ts): make isButton property in tPluginSchema optional
fix(schemas.ts): make messages property in tConversationSchema optional and change its type to array of strings
fix(schemas.ts): make systemMessage property in tConversationSchema nullable and optional
fix(schemas.ts): make modelLabel property in tConversationSchema nullable and optional
fix(schemas.ts): make chatGptLabel property in tConversationSchema nullable and optional
fix(schemas.ts): make promptPrefix property in tConversationSchema nullable and optional
fix(schemas.ts): make context property in tConversationSchema nullable and optional
fix(schemas.ts): make jailbreakConversationId property in tConversationSchema nullable and optional
fix(schemas.ts): make conversationSignature property in tConversationSchema nullable and optional
fix(schemas.ts): make clientId property

* refactor(types): replace main types with zod schemas and inferred types

* refactor(types/schemas): use schemas for better type safety of main types

* style(ModelSelect/Buttons): remove shadow and transition

* style(ModelSelect): button changes to closer match OpenAI

* style(ModelSelect): remove green rings which flicker

* style(scrollToBottom): add two separate scrolling functions

* fix(OptionsBar.tsx): handle onFocus and onBlur events to update opacityClass
fix(Messages/index.jsx): increase debounce time for scrollIntoView function
2023-08-05 12:10:36 -04:00
Anirudh
173b8ce2da feat: Add SearchBar component to Nav (#760)
* feat: Add SearchBar component to Nav

This commit adds the SearchBar component to the navigation bar in order to enable search functionality. Now users can easily search for specific items within the navigation.

* Refactor Nav and SearchBar components

The commit refactors the Nav component by moving the SearchBar component within the Nav component. This change ensures that the SearchBar is rendered only when the isSearchEnabled condition is true.

In addition, the commit also modifies the styling of the SearchBar component by adding rounded corners and border to enhance the visual appearance.

* Update gitignore

* C

Refactor search bar styles

This commit refactors the styles of the search bar component in the Nav component. The border color and hover background color have been modified to improve the visual appearance.

* Fix margin

* Rename Logout.jsx to Logout.tsx and update import statements accordingly.
Replace the use of Recoil and store with useLocalize hook for localization.
Update the usage of localize function by removing the lang parameter.
2023-08-05 10:24:56 -04:00
Danny Avila
1f5a79f073 fix(Plugins.tsx): fix incorrect params (mismatch) of setOption calls for frequency_penalty and presence_penalty (#757) 2023-08-04 22:33:06 -04:00
Marco Beretta
495ffaeb06 Update README.md (#754) 2023-08-04 17:19:34 -04:00
Danny Avila
c7b586ba4c refactor(Nav): improve toggle animation, refactor to TS (#755)
* style(Nav): match transition effect of official site

* fix(Pages): fix bug when searchResults pageSize is < prev PageSize causes currentPage to be impossible value

* refactor/fix(Nav): fix width transition animation and refactor to TS
2023-08-04 16:51:23 -04:00
Danny Avila
d6dbd56e33 Update mkdocs.yml 2023-08-04 14:41:34 -04:00
Danny Avila
315faf707e Update and rename azure.md to azure-terraform.md with repo instructions 2023-08-04 14:40:56 -04:00
AndrejG82
d79f585052 fix: allow setting username in openIdStrategy (#744)
* fixed bug in setting username from openid jwt token

* bugfix - changed , to ; at end of line
2023-08-04 14:26:14 -04:00
Alex
6ee0dbfdbd docs: Add Azure Instructions (Terraform) to Cloud Deployments Guide (#738)
* added Azure to cloud Deployments

* Update devcontainer.json

added git feature to devcontainer

* updated azure deployment docs
2023-08-04 14:23:41 -04:00
Danny Avila
60d0e97425 chore(data-provider): update package.json to add @types/react dependency (#753)
feat(data-provider): import React in types.ts file
2023-08-04 14:17:06 -04:00
Danny Avila
956aa6c674 refactor: Settings/Presets UI Restructure, convert many files to TS (#740)
* progress on settings refactor

* fix(helpers.js): replace fs.rmdirSync with fs.rm to delete node_modules directory recursively
fix(packages.js): delete package-lock.json if it exists before running the script

* feat(CrossIcon.tsx): add CrossIcon component

* wip: refactor Options for modularity into higher order components, OptionsBar > ModelSelect/Settings

* refactor: import more from utils/index, including cardStyle used by model select/settings

* refactor(AnthropicOptions): refactor to new format, OpenAI: reduce format to name of endpoint

* refactor(AnthropicSettings): refactor to new format, match defaults to API docs

* fix: google and anthropic defaults

* refactor(conversation/submission atoms): add typing, remove unused code

* chore(types.ts): add missing type definitions for TMessages, TMessagesAtom, TConversationAtom, and ModelSelectProps
feat(types.ts): make endpoint property nullable in TSubmission, TEndpointOption, TConversation, and TPreset types

* refactor(ChatGPT): refactor to new format, add omit settings logic

* refactor(EndpointSettings/BingAI): new dir structure and format BingAI options/settings to new

* fix: update useUpdateTokenCountMutation to accept an object with a 'text' property instead of a string

* fix(endpoints): ensure expected behaviors for preset dialogs

* chore(index.ts): add defaultTextProps to utils/index.ts for use in settings components

* chore(index.ts): add optionText to utils/index.ts for use in settings components

* wip: refactor google settings

* wip: progress with Google refactor, needs AdditionalButtons handling and global state setters

* refactor(OptionsBar.tsx): The setOption function has been refactored to use the useSetOptions custom hook for setting conversation options.

* chore(Anthropic.tsx, BingAI.tsx, Google.tsx, OpenAI.tsx): adjust height of container div in Settings component; chore(Examples.tsx): adjust height in Examples component

* refactor(Google): complete google refactor
feat(client): add new component PopoverButtons for displaying popover buttons in EndpointPopover
feat(data-provider): add types for PopoverButton and EndpointOptionsPopoverProps

* fix(OptionsBar.tsx): add useEffect hook to handle opacity class based on messagesTree and advancedMode
fix(style.css): rename class from 'openAIOptions-simple-container' to 'options-bar' and update references

* refactor(Plugins/OptionsBar): complete refactor of Plugins Select options, consolidate logic from TextChat to OptionsBar

* fix(Plugins.tsx): filter lastSelectedTools to remove any tools that are not in the current tools list
fix(useSetOptions.ts): remove unnecessary empty line

* feat(useSetOptions.ts): add setAgentOption function to update agentOptions in conversation state
feat(types.ts): add setAgentOption function to UseSetOptions type

* refactor(Settings/Plugins): refactor to new format, refactor(OptionHover): use same component for all endpoints

* refactor(OptionHover.tsx): refactor types object to use nested objects for openAI and gptPlugins
feat(OptionHover.tsx): add openAI object with specific properties for openAI configuration

* refactor(AgentSettings): new format, feat(types.ts): add TAgentOptions type for defining agent options in a conversation

* feat(PopoverButtons.tsx): add support for GPT plugin settings button
feat(Plugins.tsx): create PluginsView component for displaying plugin settings
feat(optionSettings.ts): add showAgentSettings atom for controlling agent settings visibility

* feat(client): add support for PluginsSettings in Input/Settings component
fix(client): change import path for PluginsSettings in Input/Settings component

* refactor(Settings/Plugins): complete refactor, store: refactor to TS, refactor: import defaultTextPropsLabel from utils

* feat(EndpointSettings, AgentSettings, Anthropic, Google, types.ts): Add support for Recoil state management and useRecoilValue hook; Pass models from endpointsConfig to various components; Add TModels type and update ModelSelectProps type.
fix(AgentSettings, Anthropic, Google, GoogleView, Plugins, OpenAI, Settings.tsx): Change import statements for ModelSelectProps from librechat-data-provider; Add models as a parameter to various components; Add models prop to PluginsView, Settings, and other components.

* refactor(EditPresetDialog.jsx): update import statements for Examples and AgentSettings components
feat(Settings/index.ts): add export statements for Examples and AgentSettings components

* chore(package.json): update eslint-plugin-import to version 2.28.0

* fix(eslint): dependency cycle rule is now working

* fix: dependency cycle errors and type errors

* refactor(EditPresetDialog.jsx): update import path for DialogTemplate component
refactor(NewConversationMenu/index.jsx): update import path for DialogTemplate component
refactor(ExportModel.jsx): update import path for DialogTemplate component

* refactor: rename NewConversationMenu to EndpointMenu

* style: mobile and desktop optimizations

* chore: eslint changes

* chore(eslintrc.js): update eslint configuration to use 'prettier' plugin
chore(postcss.config.cjs): update postcss configuration to use single quotes for require statements
fix(helpers.js): fix fs.rmSync function call to delete node_modules directory recursively
feat(update.js): add support for skipping git commands with '-g' flag

* chore(ModelSelect.tsx): add support for azureOpenAI option component
chore(Settings.tsx): add support for azureOpenAI option component
chore(package.json): add rebuild:package-lock and update:branch scripts

* fix(OptionHover.tsx): fix accessing nested properties in types object
feat(OptionHover.tsx): add check for existence of text before rendering HoverCardContent

* chore(style.css): update transition duration for options-bar from 0.3s to 0.25s

* fix(ScrollToBottom.jsx): fix z-index value for scroll button

* style: improve dialogs

* fix(Nav.jsx): adjust width and max-width of nav component

* chore(Nav.jsx): update max-width class for nav component in different screen sizes
chore(Dialog.tsx): update class for DialogFooter component to use flex-row layout

* fix(client): fix node_module resolution with path mapping

* fix(AdjustToneButton.jsx): add z-index to adjust tone button for proper layering
fix(TextChat.jsx): change onClick function to use arrow function to avoid immediate execution
fix(mobile.css): update z-index for nav and nav-mask for proper layering
chore(package.json): rename update:branch script to reinstall for clarity and consistency

* fix(OptionsBar/Settings): add null checks for conversation in BingAI.tsx, ChatGPT.tsx, Plugins.tsx, Settings.tsx

* style(TextChat/OptionsBar): match official site styles, setup regen/continue/stop buttons div

* chore: Import and apply removeFocusOutlines utility across various components, and rename removeButtonOutline to removeFocusOutlines
chore(Settings): Remove unused import and conditionally return null if conversation is falsy

* feat(hooks): add useLocalize hook

The useLocalize hook is added to the hooks/index.ts file. This hook allows for localization of phrases using the localize function from the ~/localization/Translation module. The hook uses the lang value from the store to determine the current language and returns a function that takes a phraseKey and optional values array as arguments and returns the localized phrase.

* refactor(OptionHover.tsx): Update text keys for OptionHover component, use new hook: useLocalize

* refactor(useDocumentTitle.ts): refactor to TS

* fix(typescript): type issues and update typescript linting deps

* refactor: Update ThemeContext and useOnClickOutside to TypeScript
chore(useDidMountEffect.js): Remove useDidMountEffect hook

* feat: GenerationButtons for stop/continue/regen, remove AdjustToneButton in favor of alternate advanced mode/Settings in OptionsBar

* fix(EndpointOptionsPopover.tsx): change switchToSimpleMode function name to closePopover
fix(GenerationButtons.tsx): change advancedMode prop name to showPopover
fix(OptionsBar.tsx): change advancedMode state name to showPopover
feat(OptionsBar.tsx): add logic to show/hide popover based on showPopover state
fix(types.ts): change switchToSimpleMode function name to closePopover

* chore: remove template button

* chore(GenerationButtons.tsx): adjust positioning of the div element
chore(Plugins.tsx): adjust width of the MultiSelectDropDown component
chore(OptionsBar.tsx): adjust padding of the button element

* refactor(EditPresetDialog): use new modular higher order components

* chore(newoptionsbar.html): delete unused file newoptionsbar.html

* refactor(EditPresetDialog): convert to TS

* chore(babel.config.cjs): update babel configuration, linting

* chore(EditPresetDialog.tsx): update className for DialogTemplate to include pb-0
chore(EndpointOptionsDialog.jsx): update className for DialogTemplate to include pb-0
chore(PopoverButtons.tsx): add buttonClass prop to PopoverButtons component
chore(DialogTemplate.tsx): update className for the footer div to include h-auto
chore(Dropdown.jsx): remove id prop from Dropdown component
chore(mobile.css): update transition duration for .nav class from 0.2s to 0.15s

* refactor(EditPresetDialog.tsx): simplify localization usage with hook

* chore(EditPresetDialog.tsx): update containerClassName to include z-index value

* fix(endpoints.ts): change type of endpointsConfig atom to TEndpointsConfig
refactor(cleanupPreset.ts): convert to TS
fix(index.ts): export cleanupPreset utility function
fix(types.ts): add missing properties to TPreset type

* refactor(EndpointOptionsDialog): convert to TS

* fix(EditPresetDialog.tsx):
  - import cleanupPreset from index
  - add null check before submitting preset
  - add null check before exporting preset

refactor(SaveAsPresetDialog.tsx): convert to TS

fix(usePresetOptions.ts): import cleanupPreset from index

fix(types.ts):
  - make title prop optional in EditPresetProps
  - change preset prop in CleanupPreset to be partial

* chore: reorganize imports in App, EndpointMenu, Messages, and ExportModel components
feat(ScreenshotContext.jsx): add ScreenshotContext to hooks/index
chore(index.ts): export ThemeContext, ScreenshotContext, ApiErrorBoundaryContext hooks, cleanupPreset, and getIcon functions from utils

* wip: add headerClassName for dialog template

* chore(EndpointOptionsDialog.tsx): remove unused headerClassName prop
chore(EndpointOptionsDialog.tsx): adjust height of main container in mobile and desktop view

* fix(react-query-service.ts): change return type of useGetEndpointsQuery to QueryObserverResult<t.TEndpointsConfig>

* refactor: imports from index and refactor to TS

* refactor: refactor all svg components to TS

* refactor: refactor all UI components to TS, remove unused component

* fix(SelectDropDown.tsx): remove file extension from import statement for CheckMark component

* fix: SaveAsPresetDialog typing issue

* fix(OptionsBar): close popover when an endpoint with no settings is selected

* chore(ChatGPT.tsx): update width of model select dropdown to 60px
refactor(types.ts): decouple ModelSelectProps from SettingsProps

* fix(popover Settings): space taken from the options menu for each endpoint

* fix:'Set token first' element alignment, add padding to endpointmenu icon in mobile

* style: match official site header

* refactor(EndpointOptionsDialog): make functionality explicitly saving current convos as presets

* fix(useLocalize.ts): change values parameter from an array to rest parameters

* refactor(EndpointSettings): Utilize useLocalize hook for all endpoint settings

* fix(Popover): correct spacing/center and remove focus outlines for close button

* chore: employ use of cn (clsx) in Popover styles

* chore(EditPresetDialog.tsx): update className to add padding bottom
chore(EndpointOptionsDialog.tsx): update className to add padding bottom

* style(EndpointMenu, TextChat): add better styling at diff. breakpoints

* refactor(EndpointSettings): consolidate container style to higher order component

* refactor(EditPresetDialog.tsx): pass custom style to Settings from here

* style: setting dialogs improved in all views

* style(EndpointMenu): improve UX for mobile

* style(PresetDialog): increase height so scrollbar isn't triggered

* chore(EditPresetDialog.tsx): update className to include xl height for DialogTemplate
chore(InputNumber.tsx): update className to include max height for InputNumber component

* fix: light mode styling

* fix(OptionsBar/ScrollToBottom/Popover): quick fix to rework in future: hide scrollToBottom when Popover is open

* style: remove bg-gradient around textarea in mobile view

* chore(ThemeContext.tsx): refactor ThemeContext to use default context value, also fixes type issue

* chore(EditPresetDialog.tsx): adjust grid layout in EditPresetDialog component

* style(TextChat): make gradient more opaque/smoother

* fix(TextChat.jsx): fix background gradient color based on theme and system preference

* test(layout-test-utils.tsx): add mock implementation for window.matchMedia in test setup
feat(layout-test-utils.tsx): add authConfig prop to AuthContextProvider in renderWithProvidersWrapper function
chore(tsconfig.json): include test directory in tsconfig include section

* chore(jest.config.cjs): update test file paths in jest configuration
chore(Login.spec.tsx): update test file path in import statement
chore(LoginForm.spec.tsx): update test file path in import statement
chore(Registration.spec.tsx): update test file path in import statement
chore(PluginAuthForm.spec.tsx): update test file path in import statement
chore(PluginStoreDialog.spec.tsx): update test file path in import statement
chore(layout-test-utils.tsx): move matchMedia mock to separate file
chore(tsconfig.json): add path mapping for test files in client directory

* test: add import for 'test/matchMedia.mock' in test files

The changes in this commit add an import statement for 'test/matchMedia.mock' in multiple test files. This import is necessary for mocking the behavior of the matchMedia function during testing.

* style(ClearConvosDialog): remove borders from button and modal, uniform button size

* fix(AgentSettings.tsx): overlapping issue

* fix(PresetDialogs): improve spacing of top row and dialog content

* style(Settings): 2nd column will now dynamically adjust better across all screen sizes

* style(ModelSelect): improve styling for mobile/desktop, add hover shadow
feat(ModelSelect/Plugins): hide ModelSelect when screen is small

* refactor(RowButton, buildTree): convert to TS

* style(ModelSelect): add transition effect to shadows on hover
2023-08-04 13:56:44 -04:00
Marco Beretta
fb99e5a7da docs: added how to setup a email service (#737)
* Update README.md

* Update mkdocs.yml

* Create email.md

* Delete email.md

* Update user_auth_system.md

* Update README.md

* Update mkdocs.yml
2023-08-01 08:14:31 -04:00
Marco Beretta
0630b54193 docs: add how to add a language (#732)
* Create language-contributions.md

* Update language-contributions.md

* Update README.md

* Update mkdocs.yml

* Update README.md

* Update language-contributions.md

* Create languages.md

* Update languages.md

* Update README.md

* Update mkdocs.yml

* fix space languages.md

fix space at line 61
2023-08-01 08:14:01 -04:00
Marco Beretta
851dce720f Rename italy to italian (#731) 2023-07-31 22:38:38 -04:00
Dan Orlando
30a49ae611 Feat email password reset (#730)
* change name of auth.service to AuthService

* Add emailEnabled to config api

* Setup email

* update nodemailer version

* add translations

* update .env.example

* clean up console.log's)

* refactor RequestPasswordReset component

* chore: rebuild package-lock.json

---------

Co-authored-by: Daniel Avila <messagedaniel@protonmail.com>
2023-07-31 22:37:46 -04:00
Abner Chou
2faeebfae2 Add a dropdown list in setting to allow change language. (#726)
* init localization

* Update defaul to en

* Fix merge issue and import path.

* Set default to en

* Change jsx to tsx

* Update the password max length string.

* Remove languageContext as using the recoil instead.

* Add localization to component endpoints pages

* Revert default to en after testing.

* Update LoginForm.tsx

* Fix translation.

* Make lint happy

* Merge (#1)

* Create deploy.yml

* Add localization support for endpoint pages components  (#667)

* init localization

* Update defaul to en

* Fix merge issue and import path.

* Set default to en

* Change jsx to tsx

* Update the password max length string.

* Remove languageContext as using the recoil instead.

* Add localization to component endpoints pages

* Revert default to en after testing.

* Update LoginForm.tsx

* Fix translation.

* Make lint happy

* Add a restart to melisearch in docker-compose.yml (#684)

* Oauth fixes for Cognito (#686)

* Add a restart to melisearch in docker-compose.yml

* Oauth fixes for Cognito

* Use the username or email for full name from oath if not provided

---------

Co-authored-by: Donavan <snark@hey.com>

* Italian localization support for endpoint (#687)

---------

Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Donavan Stanley <donavan.stanley@gmail.com>
Co-authored-by: Donavan <snark@hey.com>
Co-authored-by: Marco Beretta <81851188+Berry-13@users.noreply.github.com>

* Translate Nav pages

* Fix npm test

* Add setting dropdown to change the language

* Fix unit test

* Use useRecoilState

---------

Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Donavan Stanley <donavan.stanley@gmail.com>
Co-authored-by: Donavan <snark@hey.com>
Co-authored-by: Marco Beretta <81851188+Berry-13@users.noreply.github.com>
2023-07-31 11:47:14 -04:00
Danny Avila
41ed33e792 refactor(PluginsClient.js): remove initial thinking agentAction to make plugin use appear smarter and more seamless. (#729) 2023-07-30 13:10:46 -04:00
Daniel Avila
da60d77a14 chore(deploy-compose.yml): add volume mapping for images directory 2023-07-30 11:50:24 -04:00
Daniel Avila
b5aadc4b6d feat(data-provider): add GitHub Actions workflow for building and publishing package
chore(data-provider): update package version to 0.1.2
chore(data-provider): update repository URL in package.json
2023-07-30 11:50:24 -04:00
Daniel Avila
545342bbcb chore(package.json): update librechat-data-provider version to any
chore(package.json): add packages/* to workspaces
feat(package.json): add build:data-provider script
feat(package.json): update frontend and frontend:ci scripts to include build:data-provider script
2023-07-30 11:50:24 -04:00
Daniel Avila
2c00279aaf chore(Dockerfile.multi): add data-provider package build and copy step 2023-07-30 11:50:24 -04:00
Daniel Avila
77a76f8511 chore: add back data-provider 2023-07-30 11:50:24 -04:00
Fuegovic
488b373695 Update index.html to replace ChatGPT Clone with LibreChat (#724) 2023-07-28 19:14:58 -04:00
Danny Avila
94764c9c2a Release v0.5.6 (#723) 2023-07-28 13:51:41 -04:00
Fuegovic
e9c981c202 feat: add version number in UI (#704)
* feat: add version number in UI

* feat: add version number in UI

* feat: add version number in footer

* Update Footer.tsx

More concise, cleaner message

---------

Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
2023-07-28 13:48:02 -04:00
Danny Avila
bec1d245bd fix(Eng.tsx): change 'New Chat' to 'New chat' for consistency with other translations 2023-07-28 13:42:39 -04:00
Danny Avila
131cb6cddb chore: remove no longer needed route for nonexistant method 2023-07-28 13:42:39 -04:00
Danny Avila
a2b6e9a6a8 fix(meilisearch): results will now properly paginate 2023-07-28 13:42:39 -04:00
Danny Avila
428fd5bed8 chore(mongoMeili.js): update console log messages for indexing in Meilisearch 2023-07-28 13:42:39 -04:00
Danny Avila
9cacf76c10 refactor(mongoMeili.js): remove console.log statement for document not indexed 2023-07-28 13:42:39 -04:00
Danny Avila
7b8036a369 fix(anthropic.js, gptPlugins.js, openAI.js): add error handling to abortMessage function calls 2023-07-28 13:42:39 -04:00
Danny Avila
d56817850c chore(convos.js): comment out console.log statement for debugging deletion source 2023-07-28 13:42:39 -04:00
Danny Avila
f88a0685f7 fix(db/indexSync.js): update import paths for Conversation and Message models
feat(db/indexSync.js): add synchronization logic between MongoDB collection and MeiliSearch index
fix(models/plugins/mongoMeili.js): update createMeiliMongooseModel function to remove unused parameters and add documentation for syncWithMeili method
2023-07-28 13:42:39 -04:00
Marco Beretta
ae51e6153f docs: Improved ngrok installation and enhanced user_auth_system.md (#721)
* Update ngrok.md

* Update user_auth_system.md

* Update user_auth_system.md

* Update user_auth_system.md
2023-07-28 13:40:47 -04:00
Danny Avila
745eef2eb0 feat: build dev images on changes to api/client or manually (#720) 2023-07-27 19:00:21 -04:00
Danny Avila
1f8520cdad wip: testing leaner docker strategy and deployment compose file (#719)
* nginx setup

* chore(dev-images.yml): update workflow trigger to push events on main branch
chore(dev-images.yml): remove building and pushing of librechat-dev-client image
chore(nginx.conf): comment out SSL configuration in nginx.conf
chore(deploy-compose.yml): uncomment api build configuration in deploy-compose.yml
chore(deploy-compose.yml): update client build configuration in deploy-compose.yml
2023-07-27 18:52:10 -04:00
Danny Avila
dae2805d27 chore(dev-images.yml): rename workflow to "Docker Dev Images Build" (#717)
chore(deploy-compose.yml): change port mapping from 9000:3080 to 3080:3080
2023-07-27 17:05:35 -04:00
Danny Avila
ba2e95db04 Update Dockerfile.multi 2023-07-27 16:50:33 -04:00
Danny Avila
2a6e000217 wip: testing dev image workflows and deployment setup (#716)
* chore(deploy-compose.yml): update API and client image references to use latest versions from ghcr.io
feat(deploy-compose.yml): add NODE_ENV environment variable with value 'production' for API service

* chore(dev-images.yml): tag and push latest images to container registry
chore(dev-images.yml): tag and push latest client image to container registry
chore(dev-images.yml): tag and push latest dev image to container registry
fix(Dockerfile.multi): fix CMD command to properly set NODE_ENV variable
2023-07-27 16:48:41 -04:00
Danny Avila
32281d1b8d wip: testing container workflows and deployment images (#715)
* feat: add Dockerfile.multi for building API, Client, and Data Provider

feat: add nginx.conf for client-side routing in Nginx

feat: add deploy-compose.yml for deploying the application with Docker Compose

chore: update version in deploy-compose.yml to 3.8

chore: remove unused configuration in docs/dev/deploy-compose.yml

* chore(Dockerfile.multi): Remove data-provider build stage
chore(deploy-compose.yml): Add NODE_ENV=production environment variable

* chore(Dockerfile.multi): add environment variable NODE_OPTIONS with value "--max-old-space-size=776"
feat(Dockerfile.multi): copy client build output to api build stage

* chore(Dockerfile.multi): update NODE_OPTIONS to increase max-old-space-size to 2048
chore(deploy-compose.yml): remove NODE_ENV=production environment variable

* feat(dev-images.yml): add GitHub Actions workflow for Docker multi-stage build on push to main branch
2023-07-27 16:24:06 -04:00
Danny Avila
369b1f4eba chore: remove data-provider and use npm package instead (#713)
* chore: remove data-provider, install npm package

* chore: replace monorepo package with npm package: librechat-data-provider

* chore: remove data-provider scripts

* chore: remove data-provider from .eslintrc.js
2023-07-27 14:49:47 -04:00
Danny Avila
777d64088b feat: stop-backend.js and update.js linux support (#712)
* chore(dependabot.yml): update target-branch from "develop" to "dev" for npm package updates in /api, /client, and root directory

* feat: stop-backend.js and update.js linux support (#701)

* feat: stop-backend.js and update.js linux support

* feat: update.js sudo support

* chore(helpers.js): add deleteNodeModules function
feat(packages.js): add script to delete node_modules and install dependencies
refactor(update.js): remove unnecessary imports and use deleteNodeModules function
feat(package.json): add update:linux script to update with sudo

* chore(package.json): rename 'update:linux'  script to 'update:sudo'

* refactor(update.js): simplify downCommand and buildCommand by removing redundant use of sudo command, add sudo to single docker command

---------

Co-authored-by: Fuegovic <32828263+fuegovic@users.noreply.github.com>
2023-07-27 11:11:56 -04:00
Danny Avila
d59a3f20cb chore: linting 2023-07-27 10:32:23 -04:00
Danny Avila
8959576d75 fix(Settings/General): fix clear convos bug where active convo would still appear after clearing convos 2023-07-27 10:32:23 -04:00
Danny Avila
dd8bc39001 refactor(Nav/Conversation): reorganize imports and fix import paths 2023-07-27 10:32:23 -04:00
Danny Avila
4898f7489b chore(jest.config.cjs): linting 2023-07-27 10:32:23 -04:00
Danny Avila
c9c77d6fdf chore(eslint): add 'import' plugin to eslint configuration
chore(prettier): add 'prettier-plugin-tailwindcss' plugin to prettier configuration
chore(package.json): update eslint-plugin-import to version 2.27.5
2023-07-27 10:32:23 -04:00
Fuegovic
4dc86c4c18 feat: add more plugins to the Plugin store (#709) 2023-07-27 08:10:22 -04:00
Marco Beretta
6ae807c404 Update free_ai_apis.md (#707) 2023-07-27 08:08:53 -04:00
Marco Beretta
b5353e2640 Organize the getting started menu (#708)
* Create installation.md

* Delete installation.md

* Create installation.md

* Update installation.md

* Update README.md

* Update mkdocs.yml

* Update apis_and_tokens.md

* Update README.md

* Delete installation.md

* Update README.md

* Update mkdocs.yml
2023-07-27 08:05:49 -04:00
Danny Avila
f4f1199a55 feat: docker-compose deployment file (#706)
* feat(deploy-compose.yml): add docker-compose file for development deployment

A new docker-compose file has been added for development deployment. This file defines the services required for running the application in a development environment. The services include a client service running nginx, an api service running the LibreChat application, a mongodb service for the database, and a meilisearch service for search functionality.

The client service is configured to use the latest version of the nginx image, with port 3080 mapped to port 80. It also mounts the nginx.conf file and the client's node_modules directory.

The api service is named LibreChat and is built from the librechat image. It exposes port 9000 and depends on the mongodb service. It also mounts the api directory, the .env files, and the client's node_modules directory.

The mongodb service is named chat-mongodb and uses the mongo image. It exposes port 27018 and mounts the data-node directory for data storage

* chore(deploy-compose.yml): update env_file path to ../../.env

* chore(deploy-compose.yml): update image name to librechat_deploy
chore(deploy-compose.yml): update build context to ../../

* chore(deploy-compose.yml): update image and comment out build section

The image for the service has been updated to `ghcr.io/danny-avila/librechat:latest`. The build section has been commented out as it is no longer needed.

* refactor(nginx.conf): reformat nginx.conf for better readability and maintainability

* chore(nginx.conf): add worker_connections configuration to events block
chore(nginx.conf): add listen configuration to server block

* chore(deploy-compose.yml): update nginx container ports configuration
feat(deploy-compose.yml): add support for HTTPS by exposing port 443

* docs(dev/README.md): add instructions for deploying with deploy-compose.yml

* docs(dev/README.md): update instructions for deploying with deploy-compose.yml
2023-07-26 12:57:26 -04:00
Danny Avila
b6028a3434 Update breaking_changes.md 2023-07-26 08:48:12 -04:00
Danny Avila
abef8c02c1 Update breaking_changes.md 2023-07-26 08:44:51 -04:00
Danny Avila
19af2b06ce feat: utitlize lean queries, remove migration script, index createdAt timestamps (#698)
* feat(mongoDb): utitlize lean queries and index createdAt timestamps for cosmosDB support

* fix: remove unnecessary lean() method from deleteMany calls

* fix: remove unnecessary lean() method from deleteMany calls

* fix: remove lean() from queries that need hydration

* chore(migrateDb.js): remove unused migration script
fix(Preset.js): return lean documents when retrieving presets
refactor(index.js): remove migration script from server initialization
refactor(convos.js): remove toObject() when sending conversation object
refactor(presets.js): remove toObject() when sending presets object
2023-07-25 19:27:55 -04:00
Marco Beretta
2f7658e39f Italian-localization-support-for-Nav-components-and-small-fix (#697) 2023-07-25 18:29:32 -04:00
Raí
d3138c79fc Language files: Spanish translation and Portuguese corrections for PR. (#694)
* Add files via upload

* Add files via upload
2023-07-24 16:22:14 -04:00
Abner Chou
1e49b7ecb1 Support localization for Nav components (#688)
* init localization

* Update defaul to en

* Fix merge issue and import path.

* Set default to en

* Change jsx to tsx

* Update the password max length string.

* Remove languageContext as using the recoil instead.

* Add localization to component endpoints pages

* Revert default to en after testing.

* Update LoginForm.tsx

* Fix translation.

* Make lint happy

* Merge (#1)

* Create deploy.yml

* Add localization support for endpoint pages components  (#667)

* init localization

* Update defaul to en

* Fix merge issue and import path.

* Set default to en

* Change jsx to tsx

* Update the password max length string.

* Remove languageContext as using the recoil instead.

* Add localization to component endpoints pages

* Revert default to en after testing.

* Update LoginForm.tsx

* Fix translation.

* Make lint happy

* Add a restart to melisearch in docker-compose.yml (#684)

* Oauth fixes for Cognito (#686)

* Add a restart to melisearch in docker-compose.yml

* Oauth fixes for Cognito

* Use the username or email for full name from oath if not provided

---------

Co-authored-by: Donavan <snark@hey.com>

* Italian localization support for endpoint (#687)

---------

Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Donavan Stanley <donavan.stanley@gmail.com>
Co-authored-by: Donavan <snark@hey.com>
Co-authored-by: Marco Beretta <81851188+Berry-13@users.noreply.github.com>

* Translate Nav pages

* Fix npm test

---------

Co-authored-by: Danny Avila <110412045+danny-avila@users.noreply.github.com>
Co-authored-by: Donavan Stanley <donavan.stanley@gmail.com>
Co-authored-by: Donavan <snark@hey.com>
Co-authored-by: Marco Beretta <81851188+Berry-13@users.noreply.github.com>
2023-07-24 08:33:08 -04:00
Danny Avila
3b865fbc59 Update mkdocs.yml 2023-07-23 20:34:41 -04:00
Danny Avila
afd894553c docs: add installation guide for free AI APIs (ChimeraGPT) (#692)
* docs: add installation guide for free AI APIs (chimeraGPT)

* docs: Update free_ai_apis.md with screenshots
2023-07-23 20:30:58 -04:00
Daniel Avila
df485e5bfe chore(.env.example): comment out OPENAI_MODELS and PLUGIN_MODELS
The OPENAI_MODELS and PLUGIN_MODELS variables are being commented out in the .env.example file. This is done to prefer fetching api/models as the default behavior
2023-07-23 16:51:42 -07:00
Daniel Avila
77252bafc1 chore(.prettierrc.js): update tabWidth to 2 and remove commented out code 2023-07-23 16:51:42 -07:00
Daniel Avila
bd1d5e991d feat(endpoints): fetch v1/api/models for model selection when no default models are set 2023-07-23 16:51:42 -07:00
Danny Avila
18c4883ae0 refactor(PluginsClient.js): simplify getFunctionModelName logic using if-else statements
refactor(PluginsClient.js): improve readability by extracting observedImagePath variable
fix(PluginsClient.js): check if responseMessage already includes observedImagePath before appending observation
2023-07-23 16:51:42 -07:00
Youngwook Kim
197307d514 fix(OpenAIClient): resolve null pointer exception in tokenizer management (#689) 2023-07-23 11:59:11 -04:00
Marco Beretta
130356654c Italian localization support for endpoint (#687) 2023-07-22 20:12:48 -04:00
Donavan Stanley
8f9f09698b Oauth fixes for Cognito (#686)
* Add a restart to melisearch in docker-compose.yml

* Oauth fixes for Cognito

* Use the username or email for full name from oath if not provided

---------

Co-authored-by: Donavan <snark@hey.com>
2023-07-22 20:12:15 -04:00
Donavan Stanley
5da833e066 Add a restart to melisearch in docker-compose.yml (#684) 2023-07-22 15:10:07 -04:00
Abner Chou
b64273957a Add localization support for endpoint pages components (#667)
* init localization

* Update defaul to en

* Fix merge issue and import path.

* Set default to en

* Change jsx to tsx

* Update the password max length string.

* Remove languageContext as using the recoil instead.

* Add localization to component endpoints pages

* Revert default to en after testing.

* Update LoginForm.tsx

* Fix translation.

* Make lint happy
2023-07-22 15:09:45 -04:00
Danny Avila
4148c6d219 Create deploy.yml 2023-07-22 13:49:49 -04:00
Danny Avila
e9d68e3bef Update build.yml 2023-07-22 13:35:00 -04:00
Danny Avila
bbe690cc4b Update build.yml 2023-07-22 13:29:48 -04:00
Danny Avila
a1ad471d87 Update build.yml 2023-07-22 13:21:30 -04:00
Danny Avila
c319d709f3 Create build.yml 2023-07-22 11:31:56 -04:00
Danny Avila
6943f1c2c7 refactor: improve passport strategy handling in async/await manner to prevent race conditions upon importing modules (#682) 2023-07-22 10:29:17 -04:00
Danny Avila
e38483a8b9 feat(config/update.js): add support for updating with single-compose file (#680) 2023-07-21 21:51:35 -04:00
Danny Avila
2a2e6d9991 docs(dev): update README.md with instructions for using single-compose.yml (#676)
feat(single-compose.yml): add single-compose.yml for building leaner app container without meilisearch and mongodb services
- This is useful for deploying on Google, Azure, etc., as a single, leaner container.
- Instructions for running the container are added to the README.md file.
- The container requires a MongoDB Atlas connection string for the `MONGO_URI` environment variable.
- Remote Meilisearch may also be possible, but is not tested.
2023-07-21 20:11:05 -04:00
Danny Avila
deb1472aa5 chore: add update script for assuring clean installations (#673) 2023-07-21 16:44:59 -04:00
Danny Avila
8aa58ea240 chore(api): update langchain dependency to version 0.0.114 (#669) 2023-07-21 00:14:54 -04:00
Daniel Avila
3a112a344d fix(Content.jsx): remove 'z-index: 1;' from currentContent variable
fix(Content.jsx): exclude rehypePlugins if isIFrame is true
fix(Content.jsx): update content rendering to use currentContent variable
2023-07-20 19:40:31 -07:00
Daniel Avila
712be248be chore: bump app version to 0.5.5
chore: bump @waylaidwanderer/chatgpt-api to 1.37.2
2023-07-20 19:40:31 -07:00
fuegovic
530f9d303f feat: Bing Image Creator 2023-07-20 19:40:31 -07:00
Fuegovic
ad29d25396 docs: updates (#662)
* docs: updates

* docs: updates

* Update Settings.jsx
2023-07-19 08:35:41 -07:00
Danny Avila
1ef53a41f0 chore(Settings.jsx): update placeholder text for promptPrefix/system message (#656) 2023-07-16 13:22:36 -04:00
Fuegovic
0246f164b0 docs: add "chatgpt_plugins_openapi.md" to readme.md and mkdocs (#655)
* docs: add chatgpt_plugins_openapi.md to toc

* docs: add chatgpt_plugins_openapi.md to mkdocs toc
2023-07-16 13:14:07 -04:00
346 changed files with 29388 additions and 6882 deletions

View File

@@ -39,7 +39,7 @@
}
}
},
"postCreateCommand": ""
"postCreateCommand": "",
// "workspaceMount": "src=${localWorkspaceFolder},dst=/code,type=bind,consistency=cached"
// "runArgs": [
@@ -54,4 +54,5 @@
// "settings": {
// "terminal.integrated.shell.linux": "/bin/bash"
// },
}
"features": {"ghcr.io/devcontainers/features/git:1": {}}
}

View File

@@ -32,7 +32,7 @@ OPENAI_API_KEY="user_provided"
# Identify the available models, separated by commas *without spaces*.
# The first will be default.
# Leave it blank to use internal settings.
OPENAI_MODELS=gpt-3.5-turbo,gpt-3.5-turbo-16k,gpt-3.5-turbo-0301,text-davinci-003,gpt-4,gpt-4-0314,gpt-4-0613
# OPENAI_MODELS=gpt-3.5-turbo,gpt-3.5-turbo-16k,gpt-3.5-turbo-0301,text-davinci-003,gpt-4,gpt-4-0314,gpt-4-0613
# Reverse proxy settings for OpenAI:
# https://github.com/waylaidwanderer/node-chatgpt-api#using-a-reverse-proxy
@@ -124,7 +124,7 @@ ANTHROPIC_MODELS=claude-1,claude-instant-1,claude-2
# Identify the available models, separated by commas *without spaces*.
# The first will be default.
# Leave it blank to use internal settings.
PLUGIN_MODELS=gpt-3.5-turbo,gpt-3.5-turbo-16k,gpt-3.5-turbo-0301,gpt-4,gpt-4-0314,gpt-4-0613
# PLUGIN_MODELS=gpt-3.5-turbo,gpt-3.5-turbo-16k,gpt-3.5-turbo-0301,gpt-4,gpt-4-0314,gpt-4-0613
# For securely storing credentials, you need a fixed key and IV. You can set them here for prod and dev environments
# If you don't set them, the app will crash on startup.
@@ -261,3 +261,13 @@ DISCORD_CALLBACK_URL=/oauth/discord/callback # this should be the same for every
DOMAIN_CLIENT=http://localhost:3080
DOMAIN_SERVER=http://localhost:3080
###########################
# Email
###########################
# Email is used for password reset. Note that all 4 values must be set for email to work.
EMAIL_SERVICE= # eg. gmail
EMAIL_USERNAME= # eg. your email address if using gmail
EMAIL_PASSWORD= # eg. this is the "app password" if using gmail
EMAIL_FROM= # eg. email address for from field like noreply@librechat.ai

View File

@@ -13,7 +13,6 @@ module.exports = {
'plugin:jest/recommended',
'prettier',
],
// ignorePatterns: ['packages/data-provider/types/**/*'],
ignorePatterns: [
'client/dist/**/*',
'client/public/**/*',
@@ -29,7 +28,7 @@ module.exports = {
jsx: true,
},
},
plugins: ['react', 'react-hooks', '@typescript-eslint'],
plugins: ['react', 'react-hooks', '@typescript-eslint', 'import'],
rules: {
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow' }],
@@ -44,15 +43,17 @@ module.exports = {
},
],
'linebreak-style': 0,
'curly': ['error', 'all'],
'semi': ['error', 'always'],
'no-trailing-spaces': 'error',
curly: ['error', 'all'],
semi: ['error', 'always'],
'object-curly-spacing': ['error', 'always'],
'no-multiple-empty-lines': ['error', { max: 1 }],
'no-trailing-spaces': 'error',
'comma-dangle': ['error', 'always-multiline'],
// "arrow-parens": [2, "as-needed", { requireForBlockBody: true }],
// 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'no-console': 'off',
'import/no-cycle': 'error',
'import/no-self-import': 'error',
'import/extensions': 'off',
'no-promise-executor-return': 'off',
'no-param-reassign': 'off',
@@ -100,7 +101,7 @@ module.exports = {
},
},
{
files: '**/*.+(ts)',
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './client/tsconfig.json',
@@ -110,6 +111,9 @@ module.exports = {
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
},
{
files: './packages/data-provider/**/*.ts',
@@ -132,5 +136,16 @@ module.exports = {
fragment: 'Fragment', // Fragment to use (may be a property of <pragma>), default to "Fragment"
version: 'detect', // React version. "detect" automatically picks the version you have installed.
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
project: ['./client/tsconfig.json'],
},
node: {
project: ['./client/tsconfig.json'],
},
},
},
};

View File

@@ -7,7 +7,7 @@ version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/api" # Location of package manifests
target-branch: "develop"
target-branch: "dev"
versioning-strategy: increase-if-necessary
schedule:
interval: "weekly"
@@ -20,7 +20,7 @@ updates:
include: "scope"
- package-ecosystem: "npm" # See documentation for possible values
directory: "/client" # Location of package manifests
target-branch: "develop"
target-branch: "dev"
versioning-strategy: increase-if-necessary
schedule:
interval: "weekly"
@@ -33,7 +33,7 @@ updates:
include: "scope"
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
target-branch: "develop"
target-branch: "dev"
versioning-strategy: increase-if-necessary
schedule:
interval: "weekly"

View File

@@ -1,62 +0,0 @@
name: Playwright Tests
on:
push:
branches: [feat/playwright-jest-cicd]
pull_request:
branches: [feat/playwright-jest-cicd]
jobs:
tests_e2e:
name: Run Playwright tests
timeout-minutes: 60
runs-on: ubuntu-latest
env:
# BINGAI_TOKEN: ${{ secrets.BINGAI_TOKEN }}
# CHATGPT_TOKEN: ${{ secrets.CHATGPT_TOKEN }}
MONGO_URI: ${{ secrets.MONGO_URI }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
E2E_USER_EMAIL: ${{ secrets.E2E_USER_EMAIL }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
CREDS_KEY: ${{ secrets.CREDS_KEY }}
CREDS_IV: ${{ secrets.CREDS_IV }}
# NODE_ENV: ${{ vars.NODE_ENV }}
DOMAIN_CLIENT: ${{ vars.DOMAIN_CLIENT }}
DOMAIN_SERVER: ${{ vars.DOMAIN_SERVER }}
# PALM_KEY: ${{ secrets.PALM_KEY }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install global dependencies
run: npm ci --ignore-scripts
- name: Install API dependencies
working-directory: ./api
run: npm ci --ignore-scripts
- name: Install Client dependencies
working-directory: ./client
run: npm ci --ignore-scripts
- name: Build Client
run: cd client && npm run build:ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps && npm install -D @playwright/test
- name: Start server
run: |
npm run backend & sleep 10
- name: Run Playwright tests
run: npx playwright test --config=e2e/playwright.config.ts
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30

View File

@@ -1,35 +1,48 @@
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
# Pull Request Template
### ⚠️ Pre-Submission Steps:
## Type of change
1. Before starting work, make sure your main branch has the latest commits with `npm run update`
2. Run linting command to find errors: `npm run lint`. Alternatively, ensure husky pre-commit checks are functioning.
3. After your changes, reinstall packages in your current branch using `npm run reinstall` and ensure everything still works.
- Restart the ESLint server ("ESLint: Restart ESLint Server" in VS Code command bar) and your IDE after reinstalling or updating.
4. Clear web app localStorage and cookies before and after changes.
5. For frontend changes:
- Install typescript globally: `npm i -g typescript`.
- Compile typescript before and after changes to check for introduced errors: `tsc --noEmit`.
6. Run tests locally:
- Backend unit tests: `npm run test:api`
- Frontend unit tests: `npm run test:client`
- Integration tests: `npm run e2e` (requires playwright installed, `npx install playwright`)
Please delete options that are not relevant.
## Summary
Please provide a brief summary of your changes and the related issue. Include any motivation and context that is relevant to your changes. If there are any dependencies necessary for your changes, please list them here.
## Change Type
Please delete any irrelevant options.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Documentation update
- [ ] Documentation update
## How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration:
##
## Testing
Please describe your test process and include instructions so that we can reproduce your test. If there are any important variables for your testing configuration, list them here.
### **Test Configuration**:
##
## Checklist
## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
- [ ] My code adheres to this project's style guidelines
- [ ] I have performed a self-review of my own code
- [ ] I have commented in any complex areas of my code
- [ ] I have made pertinent documentation changes
- [ ] My changes do not introduce new warnings
- [ ] I have written tests demonstrating that my changes are effective or that my feature works
- [ ] Local unit tests pass with my changes
- [ ] Any changes dependent on mine have been merged and published in downstream modules.

View File

@@ -1,28 +0,0 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
tests_e2e:
name: Run end-to-end tests
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30

View File

@@ -1,15 +1,17 @@
name: Backend Unit Tests
on:
push:
branches:
- main
- dev
- release/*
# push:
# branches:
# - main
# - dev
# - release/*
pull_request:
branches:
- main
- dev
- release/*
paths:
- 'api/**'
jobs:
tests_Backend:
name: Run Backend unit tests
@@ -23,10 +25,10 @@ jobs:
CREDS_IV: ${{ secrets.CREDS_IV }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js 19.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 19.x
node-version: 20
cache: 'npm'
- name: Install dependencies

38
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: Linux_Container_Workflow
on:
workflow_dispatch:
env:
RUNNER_VERSION: 2.293.0
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Build GitHub Runner container image'
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- run: |
docker build --build-arg RUNNER_VERSION=${{ env.RUNNER_VERSION }} -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/pwd9000-github-runner-lin:${{ env.RUNNER_VERSION }} .
- name: 'Push container image to ACR'
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- run: |
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/pwd9000-github-runner-lin:${{ env.RUNNER_VERSION }}

34
.github/workflows/data-provider.yml vendored Normal file
View File

@@ -0,0 +1,34 @@
name: Node.js Package
on:
push:
branches:
- main
paths:
- 'packages/data-provider/package.json'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: cd packages/data-provider && npm ci
- run: cd packages/data-provider && npm run build
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: cd packages/data-provider && npm ci
- run: cd packages/data-provider && npm run build
- run: cd packages/data-provider && npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

38
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: Deploy_GHRunner_Linux_ACI
on:
workflow_dispatch:
env:
RUNNER_VERSION: 2.293.0
ACI_RESOURCE_GROUP: 'Demo-ACI-GitHub-Runners-RG'
ACI_NAME: 'gh-runner-linux-01'
DNS_NAME_LABEL: 'gh-lin-01'
GH_OWNER: ${{ github.repository_owner }}
GH_REPOSITORY: 'LibreChat' #Change here to deploy self hosted runner ACI to another repo.
jobs:
deploy-gh-runner-aci:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Deploy to Azure Container Instances'
uses: 'azure/aci-deploy@v1'
with:
resource-group: ${{ env.ACI_RESOURCE_GROUP }}
image: ${{ secrets.REGISTRY_LOGIN_SERVER }}/pwd9000-github-runner-lin:${{ env.RUNNER_VERSION }}
registry-login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
registry-username: ${{ secrets.REGISTRY_USERNAME }}
registry-password: ${{ secrets.REGISTRY_PASSWORD }}
name: ${{ env.ACI_NAME }}
dns-name-label: ${{ env.DNS_NAME_LABEL }}
environment-variables: GH_TOKEN=${{ secrets.PAT_TOKEN }} GH_OWNER=${{ env.GH_OWNER }} GH_REPOSITORY=${{ env.GH_REPOSITORY }}
location: 'eastus'

51
.github/workflows/dev-images.yml vendored Normal file
View File

@@ -0,0 +1,51 @@
name: Docker Dev Images Build
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'api/**'
- 'client/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
# Check out the repository
- name: Checkout
uses: actions/checkout@v2
# Set up Docker
- name: Set up Docker
uses: docker/setup-buildx-action@v1
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build Docker images
- name: Build Docker images
run: |
cp .env.example .env
docker build -f Dockerfile.multi --target api-build -t librechat-dev-api .
docker build -f Dockerfile -t librechat-dev .
# Tag and push the images to GitHub Container Registry
- name: Tag and push images
run: |
docker tag librechat-dev-api:latest ghcr.io/${{ github.repository_owner }}/librechat-dev-api:${{ github.sha }}
docker push ghcr.io/${{ github.repository_owner }}/librechat-dev-api:${{ github.sha }}
docker tag librechat-dev-api:latest ghcr.io/${{ github.repository_owner }}/librechat-dev-api:latest
docker push ghcr.io/${{ github.repository_owner }}/librechat-dev-api:latest
docker tag librechat-dev:latest ghcr.io/${{ github.repository_owner }}/librechat-dev:${{ github.sha }}
docker push ghcr.io/${{ github.repository_owner }}/librechat-dev:${{ github.sha }}
docker tag librechat-dev:latest ghcr.io/${{ github.repository_owner }}/librechat-dev:latest
docker push ghcr.io/${{ github.repository_owner }}/librechat-dev:latest

View File

@@ -1,16 +1,19 @@
#github action to run unit tests for frontend with jest
name: Frontend Unit Tests
on:
push:
branches:
- main
- dev
- release/*
# push:
# branches:
# - main
# - dev
# - release/*
pull_request:
branches:
- main
- dev
- release/*
paths:
- 'client/**'
- 'packages/**'
jobs:
tests_frontend:
name: Run frontend unit tests
@@ -18,10 +21,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 19.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 19.x
node-version: 20
cache: 'npm'
- name: Install dependencies

81
.github/workflows/playwright.yml vendored Normal file
View File

@@ -0,0 +1,81 @@
name: Playwright Tests
on:
pull_request:
branches:
- main
- dev
- release/*
paths:
- 'api/**'
- 'client/**'
- 'packages/**'
- 'e2e/**'
jobs:
tests_e2e:
name: Run Playwright tests
if: github.event.pull_request.head.repo.full_name == 'danny-avila/LibreChat'
timeout-minutes: 60
runs-on: ubuntu-latest
env:
NODE_ENV: ci
CI: true
SEARCH: false
BINGAI_TOKEN: user_provided
CHATGPT_TOKEN: user_provided
MONGO_URI: ${{ secrets.MONGO_URI }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
E2E_USER_EMAIL: ${{ secrets.E2E_USER_EMAIL }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
CREDS_KEY: ${{ secrets.CREDS_KEY }}
CREDS_IV: ${{ secrets.CREDS_IV }}
DOMAIN_CLIENT: ${{ secrets.DOMAIN_CLIENT }}
DOMAIN_SERVER: ${{ secrets.DOMAIN_SERVER }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
# - name: Cache Node.js modules
# uses: actions/cache@v3
# with:
# path: ~/.npm
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-node-
- name: Install global dependencies
run: npm ci
- name: Remove sharp dependency
run: rm -rf node_modules/sharp
- name: Install sharp with linux dependencies
run: cd api && SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux --libc=glibc sharp
- name: Build Client
run: npm run frontend
# - name: Cache Playwright installations
# uses: actions/cache@v3
# with:
# path: ~/.cache/ms-playwright/
# key: ${{ runner.os }}-pw-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-pw-
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium && npm install -D @playwright/test@latest
- name: Run Playwright tests
run: npm run e2e:ci
- name: Upload playwright report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30

2
.gitignore vendored
View File

@@ -50,6 +50,7 @@ types/
# Environment
.npmrc
.env*
my.secrets
!**/.env.example
!**/.env.test.example
cache.json
@@ -71,6 +72,7 @@ junit.xml
# meilisearch
meilisearch
meilisearch.exe
data.ms/*
auth.json

40
Dockerfile.multi Normal file
View File

@@ -0,0 +1,40 @@
# Build API, Client and Data Provider
FROM node:19-alpine AS base
WORKDIR /app
COPY config/loader.js ./config/
RUN npm install dotenv
WORKDIR /app/api
COPY api/package*.json ./
COPY api/ ./
RUN npm install
# React client build
FROM base AS client-build
WORKDIR /app/client
COPY ./client/ ./
WORKDIR /app/packages/data-provider
COPY ./packages/data-provider ./
RUN npm install
RUN npm run build
RUN mkdir -p /app/client/node_modules/librechat-data-provider/
RUN cp -R /app/packages/data-provider/* /app/client/node_modules/librechat-data-provider/
WORKDIR /app/client
RUN npm install
ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run build
# Node API setup
FROM base AS api-build
COPY --from=client-build /app/client/dist /app/client/dist
EXPOSE 3080
ENV HOST=0.0.0.0
CMD ["node", "server/index.js"]
# Nginx setup
FROM nginx:1.21.1-alpine AS prod-stage
COPY ./client/nginx.conf /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -31,7 +31,10 @@ LibreChat brings together the future of assistant AIs with the revolutionary tec
With LibreChat, you no longer need to opt for ChatGPT Plus and can instead use free or pay-per-call APIs. We welcome contributions, cloning, and forking to enhance the capabilities of this advanced chatbot platform.
https://github.com/danny-avila/LibreChat/assets/110412045/c1eb0c0f-41f6-4335-b982-84b278b53d59
<!-- https://github.com/danny-avila/LibreChat/assets/110412045/c1eb0c0f-41f6-4335-b982-84b278b53d59 -->
[![Watch the video](https://img.youtube.com/vi/pNIOs1ovsXw/maxresdefault.jpg)](https://youtu.be/pNIOs1ovsXw)
Click on the thumbnail to open the video☝
# Features
- Response streaming identical to ChatGPT through server-sent events
@@ -44,7 +47,8 @@ https://github.com/danny-avila/LibreChat/assets/110412045/c1eb0c0f-41f6-4335-b98
---
## ⚠️ [Breaking Changes as of v0.5.0](docs/general_info/breaking_changes.md#v050) ⚠️
## ⚠️ [Breaking Changes](docs/general_info/breaking_changes.md) ⚠️
**Please read this before updating from a previous version**
---
@@ -59,12 +63,16 @@ Keep up with the latest updates by visiting the releases page - [Releases](https
<details open>
<summary><strong>Getting Started</strong></summary>
* [Docker Install](docs/install/docker_install.md)
* [Linux Install](docs/install/linux_install.md)
* [Mac Install](docs/install/mac_install.md)
* [Windows Install](docs/install/windows_install.md)
* [APIs and Tokens](docs/install/apis_and_tokens.md)
* [User Auth System](docs/install/user_auth_system.md)
* Installation
* [Docker Install🐳](docs/install/docker_install.md)
* [Linux Install🐧](docs/install/linux_install.md)
* [Mac Install🍎](docs/install/mac_install.md)
* [Windows Install💙](docs/install/windows_install.md)
* Configuration
* [APIs and Tokens](docs/install/apis_and_tokens.md)
* [User Auth System](docs/install/user_auth_system.md)
* [Online MongoDB Database](docs/install/mongodb.md)
* [Languages](docs/install/languages.md)
</details>
<details>
@@ -85,6 +93,7 @@ Keep up with the latest updates by visiting the releases page - [Releases](https
* [Stable Diffusion](docs/features/plugins/stable_diffusion.md)
* [Wolfram](docs/features/plugins/wolfram.md)
* [Make Your Own Plugin](docs/features/plugins/make_your_own.md)
* [Using official ChatGPT Plugins](docs/features/plugins/chatgpt_plugins_openapi.md)
* [Proxy](docs/features/proxy.md)
* [Bing Jailbreak](docs/features/bing_jailbreak.md)
@@ -99,11 +108,12 @@ Keep up with the latest updates by visiting the releases page - [Releases](https
* [Cloudflare](docs/deployment/cloudflare.md)
* [Ngrok](docs/deployment/ngrok.md)
* [Render](docs/deployment/render.md)
* [Azure](docs/deployment/azure-terraform.md)
</details>
<details>
<summary><strong>Contributions</strong></summary>
* [Contributor Guidelines](CONTRIBUTING.md)
* [Documentation Guidelines](docs/contributions/documentation_guidelines.md)
* [Code Standards and Conventions](docs/contributions/coding_conventions.md)

View File

@@ -47,6 +47,16 @@ const askBing = async ({
parentMessageId,
toneStyle,
onProgress,
clientOptions: {
features: {
genImage: {
server: {
enable: true,
type: 'markdown_list',
},
},
},
},
};
} else {
options = {
@@ -56,6 +66,16 @@ const askBing = async ({
parentMessageId,
toneStyle,
onProgress,
clientOptions: {
features: {
genImage: {
server: {
enable: true,
type: 'markdown_list',
},
},
},
},
};
// don't give those parameters for new conversation

View File

@@ -6,7 +6,10 @@ const {
} = require('@dqbd/tiktoken');
const { maxTokensMap, genAzureChatCompletion } = require('../../utils');
// Cache to store Tiktoken instances
const tokenizersCache = {};
// Counter for keeping track of the number of tokenizer calls
let tokenizerCallsCount = 0;
class OpenAIClient extends BaseClient {
constructor(apiKey, options = {}) {
@@ -89,7 +92,6 @@ class OpenAIClient extends BaseClient {
this.chatGptLabel = this.options.chatGptLabel || 'Assistant';
this.setupTokens();
this.setupTokenizer();
if (!this.modelOptions.stop) {
const stopTokens = [this.startToken];
@@ -133,68 +135,87 @@ class OpenAIClient extends BaseClient {
}
}
setupTokenizer() {
// Selects an appropriate tokenizer based on the current configuration of the client instance.
// It takes into account factors such as whether it's a chat completion, an unofficial chat GPT model, etc.
selectTokenizer() {
let tokenizer;
this.encoding = 'text-davinci-003';
if (this.isChatCompletion) {
this.encoding = 'cl100k_base';
this.gptEncoder = this.constructor.getTokenizer(this.encoding);
tokenizer = this.constructor.getTokenizer(this.encoding);
} else if (this.isUnofficialChatGptModel) {
this.gptEncoder = this.constructor.getTokenizer(this.encoding, true, {
const extendSpecialTokens = {
'<|im_start|>': 100264,
'<|im_end|>': 100265,
});
};
tokenizer = this.constructor.getTokenizer(this.encoding, true, extendSpecialTokens);
} else {
try {
this.encoding = this.modelOptions.model;
this.gptEncoder = this.constructor.getTokenizer(this.modelOptions.model, true);
tokenizer = this.constructor.getTokenizer(this.modelOptions.model, true);
} catch {
this.gptEncoder = this.constructor.getTokenizer(this.encoding, true);
tokenizer = this.constructor.getTokenizer(this.encoding, true);
}
}
}
static getTokenizer(encoding, isModelName = false, extendSpecialTokens = {}) {
if (tokenizersCache[encoding]) {
return tokenizersCache[encoding];
}
let tokenizer;
if (isModelName) {
tokenizer = encodingForModel(encoding, extendSpecialTokens);
} else {
tokenizer = getEncoding(encoding, extendSpecialTokens);
}
tokenizersCache[encoding] = tokenizer;
return tokenizer;
}
freeAndResetEncoder() {
try {
if (!this.gptEncoder) {
return;
// Retrieves a tokenizer either from the cache or creates a new one if one doesn't exist in the cache.
// If a tokenizer is being created, it's also added to the cache.
static getTokenizer(encoding, isModelName = false, extendSpecialTokens = {}) {
let tokenizer;
if (tokenizersCache[encoding]) {
tokenizer = tokenizersCache[encoding];
} else {
if (isModelName) {
tokenizer = encodingForModel(encoding, extendSpecialTokens);
} else {
tokenizer = getEncoding(encoding, extendSpecialTokens);
}
this.gptEncoder.free();
delete tokenizersCache[this.encoding];
delete tokenizersCache.count;
this.setupTokenizer();
tokenizersCache[encoding] = tokenizer;
}
return tokenizer;
}
// Frees all encoders in the cache and resets the count.
static freeAndResetAllEncoders() {
try {
Object.keys(tokenizersCache).forEach((key) => {
if (tokenizersCache[key]) {
tokenizersCache[key].free();
delete tokenizersCache[key];
}
});
// Reset count
tokenizerCallsCount = 1;
} catch (error) {
console.log('freeAndResetEncoder error');
console.log('Free and reset encoders error');
console.error(error);
}
}
getTokenCount(text) {
try {
if (tokenizersCache.count >= 25) {
if (this.options.debug) {
console.debug('freeAndResetEncoder: reached 25 encodings, reseting...');
}
this.freeAndResetEncoder();
// Checks if the cache of tokenizers has reached a certain size. If it has, it frees and resets all tokenizers.
resetTokenizersIfNecessary() {
if (tokenizerCallsCount >= 25) {
if (this.options.debug) {
console.debug('freeAndResetAllEncoders: reached 25 encodings, resetting...');
}
tokenizersCache.count = (tokenizersCache.count || 0) + 1;
return this.gptEncoder.encode(text, 'all').length;
this.constructor.freeAndResetAllEncoders();
}
tokenizerCallsCount++;
}
// Returns the token count of a given text. It also checks and resets the tokenizers if necessary.
getTokenCount(text) {
this.resetTokenizersIfNecessary();
try {
const tokenizer = this.selectTokenizer();
return tokenizer.encode(text, 'all').length;
} catch (error) {
this.freeAndResetEncoder();
return this.gptEncoder.encode(text, 'all').length;
this.constructor.freeAndResetAllEncoders();
const tokenizer = this.selectTokenizer();
return tokenizer.encode(text, 'all').length;
}
}

View File

@@ -132,14 +132,13 @@ Only respond with your conversational reply to the following User Message:
}
getFunctionModelName(input) {
const prefixMap = {
'gpt-4': 'gpt-4-0613',
'gpt-4-32k': 'gpt-4-32k-0613',
'gpt-3.5-turbo': 'gpt-3.5-turbo-0613',
};
const prefix = Object.keys(prefixMap).find((key) => input.startsWith(key));
return prefix ? prefixMap[prefix] : 'gpt-3.5-turbo-0613';
if (input.startsWith('gpt-3.5-turbo')) {
return 'gpt-3.5-turbo';
} else if (input.startsWith('gpt-4')) {
return 'gpt-4';
} else {
return 'gpt-3.5-turbo';
}
}
getBuildMessagesOptions(opts) {
@@ -184,7 +183,9 @@ Only respond with your conversational reply to the following User Message:
const model = this.createLLM(modelOptions, configOptions);
if (this.options.debug) {
console.debug(`<-----Agent Model: ${model.modelName} | Temp: ${model.temperature}----->`);
console.debug(
`<-----Agent Model: ${model.modelName} | Temp: ${model.temperature} | Functions: ${this.functionsAgent}----->`,
);
}
this.availableTools = await loadTools({
@@ -269,15 +270,6 @@ Only respond with your conversational reply to the following User Message:
if (this.options.debug) {
console.debug('Loaded agent.');
}
onAgentAction(
{
tool: 'self-reflection',
toolInput: `Processing the User's message:\n"${message}"`,
log: '',
},
true,
);
}
async executorCall(message, signal) {
@@ -328,7 +320,12 @@ Only respond with your conversational reply to the following User Message:
return;
}
if (!responseMessage.text.includes(observation)) {
// Extract the image file path from the observation
const observedImagePath = observation.match(/\(\/images\/.*\.\w*\)/g)[0];
// Check if the responseMessage already includes the image file path
if (!responseMessage.text.includes(observedImagePath)) {
// If the image file path is not found, append the whole observation
responseMessage.text += '\n' + observation;
if (this.options.debug) {
console.debug('added image from intermediateSteps');

View File

@@ -1,7 +1,7 @@
const OpenAIClient = require('../OpenAIClient');
describe('OpenAIClient', () => {
let client;
let client, client2;
const model = 'gpt-4';
const parentMessageId = '1';
const messages = [
@@ -19,11 +19,13 @@ describe('OpenAIClient', () => {
},
};
client = new OpenAIClient('test-api-key', options);
client2 = new OpenAIClient('test-api-key', options);
client.refineMessages = jest.fn().mockResolvedValue({
role: 'assistant',
content: 'Refined answer',
tokenCount: 30,
});
client.constructor.freeAndResetAllEncoders();
});
describe('setOptions', () => {
@@ -34,10 +36,25 @@ describe('OpenAIClient', () => {
});
});
describe('freeAndResetEncoder', () => {
it('should reset the encoder', () => {
client.freeAndResetEncoder();
expect(client.gptEncoder).toBeDefined();
describe('selectTokenizer', () => {
it('should get the correct tokenizer based on the instance state', () => {
const tokenizer = client.selectTokenizer();
expect(tokenizer).toBeDefined();
});
});
describe('freeAllTokenizers', () => {
it('should free all tokenizers', () => {
// Create a tokenizer
const tokenizer = client.selectTokenizer();
// Mock 'free' method on the tokenizer
tokenizer.free = jest.fn();
client.constructor.freeAndResetAllEncoders();
// Check if 'free' method has been called on the tokenizer
expect(tokenizer.free).toHaveBeenCalled();
});
});
@@ -48,7 +65,7 @@ describe('OpenAIClient', () => {
});
it('should reset the encoder and count when count reaches 25', () => {
const freeAndResetEncoderSpy = jest.spyOn(client, 'freeAndResetEncoder');
const freeAndResetEncoderSpy = jest.spyOn(client.constructor, 'freeAndResetAllEncoders');
// Call getTokenCount 25 times
for (let i = 0; i < 25; i++) {
@@ -59,7 +76,8 @@ describe('OpenAIClient', () => {
});
it('should not reset the encoder and count when count is less than 25', () => {
const freeAndResetEncoderSpy = jest.spyOn(client, 'freeAndResetEncoder');
const freeAndResetEncoderSpy = jest.spyOn(client.constructor, 'freeAndResetAllEncoders');
freeAndResetEncoderSpy.mockClear();
// Call getTokenCount 24 times
for (let i = 0; i < 24; i++) {
@@ -70,8 +88,10 @@ describe('OpenAIClient', () => {
});
it('should handle errors and reset the encoder', () => {
const freeAndResetEncoderSpy = jest.spyOn(client, 'freeAndResetEncoder');
client.gptEncoder.encode = jest.fn().mockImplementation(() => {
const freeAndResetEncoderSpy = jest.spyOn(client.constructor, 'freeAndResetAllEncoders');
// Mock encode function to throw an error
client.selectTokenizer().encode = jest.fn().mockImplementation(() => {
throw new Error('Test error');
});
@@ -79,6 +99,14 @@ describe('OpenAIClient', () => {
expect(freeAndResetEncoderSpy).toHaveBeenCalled();
});
it('should not throw null pointer error when freeing the same encoder twice', () => {
client.constructor.freeAndResetAllEncoders();
client2.constructor.freeAndResetAllEncoders();
const count = client2.getTokenCount('test text');
expect(count).toBeGreaterThan(0);
});
});
describe('getSaveOptions', () => {

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,89 @@
{
"schema_version": "v1",
"name_for_human": "Dr. Thoth's Tarot",
"name_for_model": "Dr_Thoths_Tarot",
"description_for_human": "Tarot card novelty entertainment & analysis, by Mnemosyne Labs.",
"description_for_model": "Intelligent analysis program for tarot card entertaiment, data, & prompts, by Mnemosyne Labs, a division of AzothCorp.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://dr-thoth-tarot.herokuapp.com/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://dr-thoth-tarot.herokuapp.com/logo.png",
"contact_email": "legal@AzothCorp.com",
"legal_info_url": "http://AzothCorp.com/legal",
"endpoints": [
{
"name": "Draw Card",
"path": "/drawcard",
"method": "GET",
"description": "Generate a single tarot card from the deck of 78 cards."
},
{
"name": "Occult Card",
"path": "/occult_card",
"method": "GET",
"description": "Generate a tarot card using the specified planet's Kamea matrix.",
"parameters": [
{
"name": "planet",
"type": "string",
"enum": ["Saturn", "Jupiter", "Mars", "Sun", "Venus", "Mercury", "Moon"],
"required": true,
"description": "The planet name to use the corresponding Kamea matrix."
}
]
},
{
"name": "Three Card Spread",
"path": "/threecardspread",
"method": "GET",
"description": "Perform a three-card tarot spread."
},
{
"name": "Celtic Cross Spread",
"path": "/celticcross",
"method": "GET",
"description": "Perform a Celtic Cross tarot spread with 10 cards."
},
{
"name": "Past, Present, Future Spread",
"path": "/pastpresentfuture",
"method": "GET",
"description": "Perform a Past, Present, Future tarot spread with 3 cards."
},
{
"name": "Horseshoe Spread",
"path": "/horseshoe",
"method": "GET",
"description": "Perform a Horseshoe tarot spread with 7 cards."
},
{
"name": "Relationship Spread",
"path": "/relationship",
"method": "GET",
"description": "Perform a Relationship tarot spread."
},
{
"name": "Career Spread",
"path": "/career",
"method": "GET",
"description": "Perform a Career tarot spread."
},
{
"name": "Yes/No Spread",
"path": "/yesno",
"method": "GET",
"description": "Perform a Yes/No tarot spread."
},
{
"name": "Chakra Spread",
"path": "/chakra",
"method": "GET",
"description": "Perform a Chakra tarot spread with 7 cards."
}
]
}

View File

@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_model": "DreamInterpreter",
"name_for_human": "Dream Interpreter",
"description_for_model": "Interprets your dreams using advanced techniques.",
"description_for_human": "Interprets your dreams using advanced techniques.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://dreamplugin.bgnetmobile.com/.well-known/openapi.json",
"has_user_authentication": false
},
"logo_url": "https://dreamplugin.bgnetmobile.com/.well-known/logo.png",
"contact_email": "ismail.orkler@bgnetmobile.com",
"legal_info_url": "https://dreamplugin.bgnetmobile.com/terms.html"
}

View File

@@ -0,0 +1,22 @@
{
"schema_version": "v1",
"name_for_human": "Ai Tool Hunt",
"name_for_model": "aitoolhunt",
"description_for_human": "Find the perfect AI tools for all your needs, drawn from the most comprehensive global database of AI tools.",
"description_for_model": "This universal plugin is designed to identify and suggest AI tools for any imaginable task or challenge. It harnesses a database of over 1600+ AI tools and 120+ categories, ensuring a solution for every requirement. Simply input any task, problem, or use case, and the plugin will generate a tailored list of AI tools. Note: it's crucial to rearrange the tools suggested by the plugin based on their relevance to the user's specific use case. This plugin can tackle everything from the simplest to the most intricate tasks. If there's a way an AI tool can help, this plugin will not only locate it but also customize the list to the user's unique needs. Utilize this plugin whenever a task or activity emerges, regardless of its context or complexity. When formulating a search query, avoid stop words or other irrelevant keywords. For instance, 'copywriting' is acceptable, but 'ai for copywriting' is not. If you believe none of the suggested tools are a suitable match for the user's needs, indicate that these are related tools.",
"auth": {
"type": "service_http",
"authorization_type": "bearer",
"verification_tokens": {
"openai": "06a0f9391a5e48c7a7eeaca1e7e1e8d3"
}
},
"api": {
"type": "openapi",
"url": "https://www.aitoolhunt.com/openapi.json",
"is_user_authenticated": false
},
"logo_url": "https://www.aitoolhunt.com/images/aitoolhunt_logo.png",
"contact_email": "aitoolhunt@gmail.com",
"legal_info_url": "https://www.aitoolhunt.com/terms-and-conditions"
}

View File

@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Drink Maestro",
"name_for_model": "drink_maestro",
"description_for_human": "Learn to mix any drink you can imagine (real or made-up), and discover new ones. Includes drink images.",
"description_for_model": "You are a silly bartender/comic who knows how to make any drink imaginable. You provide recipes for specific drinks, suggest new drinks, and show pictures of drinks. Be creative in your descriptions and make jokes and puns. Use a lot of emojis. If the user makes a request in another language, send API call in English, and then translate the response.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://api.drinkmaestro.space/.well-known/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://i.imgur.com/6q8HWdz.png",
"contact_email": "nikkmitchell@gmail.com",
"legal_info_url": "https://github.com/nikkmitchell/DrinkMaestro/blob/main/Legal.txt"
}

View File

@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Earth",
"name_for_model": "earthImagesAndVisualizations",
"description_for_human": "Generates a map image based on provided location, tilt and style.",
"description_for_model": "Generates a map image based on provided coordinates or location, tilt and style, and even geoJson to provide markers, paths, and polygons. Responds with an image-link. For the styles choose one of these: [light, dark, streets, outdoors, satellite, satellite-streets]",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://api.earth-plugin.com/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://api.earth-plugin.com/logo.png",
"contact_email": "contact@earth-plugin.com",
"legal_info_url": "https://api.earth-plugin.com/legal.html"
}

View File

@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Image Prompt Enhancer",
"name_for_model": "image_prompt_enhancer",
"description_for_human": "Transform your ideas into complex, personalized image generation prompts.",
"description_for_model": "Provides instructions for crafting an enhanced image prompt. Use this whenever the user wants to enhance a prompt.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://image-prompt-enhancer.gafo.tech/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://image-prompt-enhancer.gafo.tech/logo.png",
"contact_email": "gafotech1@gmail.com",
"legal_info_url": "https://image-prompt-enhancer.gafo.tech/legal"
}

View File

@@ -0,0 +1,17 @@
{
"schema_version": "v1",
"name_for_human": "QR Codes",
"name_for_model": "qrCodes",
"description_for_human": "Create QR codes.",
"description_for_model": "Plugin for generating QR codes.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://chatgpt-qrcode-46d7d4ebefc8.herokuapp.com/openapi.yaml"
},
"logo_url": "https://chatgpt-qrcode-46d7d4ebefc8.herokuapp.com/logo.png",
"contact_email": "chrismountzou@gmail.com",
"legal_info_url": "https://raw.githubusercontent.com/mountzou/qrCodeGPTv1/master/legal"
}

View File

@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Uberchord",
"name_for_model": "uberchord",
"description_for_human": "Find guitar chord diagrams by specifying the chord name.",
"description_for_model": "Fetch guitar chord diagrams, their positions on the guitar fretboard.",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://guitarchords.pluginboost.com/.well-known/openapi.yaml",
"is_user_authenticated": false
},
"logo_url": "https://guitarchords.pluginboost.com/logo.png",
"contact_email": "info.bluelightweb@gmail.com",
"legal_info_url": "https://guitarchords.pluginboost.com/legal"
}

View File

@@ -0,0 +1,18 @@
{
"schema_version": "v1",
"name_for_human": "Web Search",
"name_for_model": "web_search",
"description_for_human": "Search for information from the internet",
"description_for_model": "Search for information from the internet",
"auth": {
"type": "none"
},
"api": {
"type": "openapi",
"url": "https://websearch.plugsugar.com/api/openapi_yaml",
"is_user_authenticated": false
},
"logo_url": "https://websearch.plugsugar.com/200x200.png",
"contact_email": "support@plugsugar.com",
"legal_info_url": "https://websearch.plugsugar.com/contact"
}

View File

@@ -1,6 +1,5 @@
const mongoose = require('mongoose');
const Conversation = mongoose.models.Conversation;
const Message = mongoose.models.Message;
const Conversation = require('../../models/schema/convoSchema');
const Message = require('../../models/schema/messageSchema');
const { MeiliSearch } = require('meilisearch');
let currentTimeout = null;
@@ -37,12 +36,12 @@ async function indexSync(req, res, next) {
if (messageCount !== messagesIndexed) {
console.log('Messages out of sync, indexing');
await Message.syncWithMeili();
Message.syncWithMeili();
}
if (convoCount !== convosIndexed) {
console.log('Convos out of sync, indexing');
await Conversation.syncWithMeili();
Conversation.syncWithMeili();
}
} catch (err) {
// console.log('in index sync');

View File

@@ -1,124 +0,0 @@
const mongoose = require('mongoose');
const { Conversation } = require('../../models/Conversation');
const { getMessages } = require('../../models/');
const migrateToStrictFollowParentMessageIdChain = async () => {
try {
const conversations = await Conversation.find({ endpoint: null, model: null }).exec();
if (!conversations || conversations.length === 0) {
return { noNeed: true };
}
console.log('Migration: To strict follow the parentMessageId chain.');
for (let convo of conversations) {
const messages = await getMessages({
conversationId: convo.conversationId,
messageId: { $exists: false },
});
let model;
let oldId;
const promises = [];
messages.forEach((message, i) => {
const msgObj = message.toObject();
const newId = msgObj.id;
if (i === 0) {
message.parentMessageId = '00000000-0000-0000-0000-000000000000';
} else {
message.parentMessageId = oldId;
}
oldId = newId;
message.messageId = newId;
if (message.sender.toLowerCase() !== 'user' && !model) {
model = message.sender.toLowerCase();
}
if (message.sender.toLowerCase() === 'user') {
message.isCreatedByUser = true;
}
promises.push(message.save());
});
await Promise.all(promises);
await Conversation.findOneAndUpdate(
{ conversationId: convo.conversationId },
{ model },
{ new: true },
).exec();
}
try {
await mongoose.connection.db.collection('messages').dropIndex('id_1');
} catch (error) {
console.log('[Migrate] Index doesn\'t exist or already dropped');
}
} catch (error) {
console.log(error);
return { message: '[Migrate] Error migrating conversations' };
}
};
const migrateToSupportBetterCustomization = async () => {
try {
const conversations = await Conversation.find({ endpoint: null }).exec();
if (!conversations || conversations.length === 0) {
return { noNeed: true };
}
console.log('Migration: To support better customization.');
const promises = [];
for (let convo of conversations) {
const originalModel = convo?.model;
if (originalModel === 'chatgpt') {
convo.endpoint = 'openAI';
convo.model = 'gpt-3.5-turbo';
} else if (originalModel === 'chatgptCustom') {
convo.endpoint = 'openAI';
convo.model = 'gpt-3.5-turbo';
} else if (originalModel === 'bingai') {
convo.endpoint = 'bingAI';
convo.model = null;
convo.jailbreak = false;
} else if (originalModel === 'sydney') {
convo.endpoint = 'bingAI';
convo.model = null;
convo.jailbreak = true;
} else if (originalModel === 'chatgptBrowser') {
convo.endpoint = 'chatGPTBrowser';
convo.model = 'text-davinci-002-render-sha';
convo.jailbreak = true;
} else {
convo.endpoint = 'openAI';
convo.model = 'gpt-3.5-turbo';
}
promises.push(convo.save());
}
await Promise.all(promises);
} catch (error) {
console.log(error);
return { message: '[Migrate] Error migrating conversations' };
}
};
async function migrateDb() {
let ret = [];
ret[0] = await migrateToStrictFollowParentMessageIdChain();
ret[1] = await migrateToSupportBetterCustomization();
const isMigrated = !!ret.find((element) => !element?.noNeed);
if (!isMigrated) {
console.log('[Migrate] Nothing to migrate');
}
}
module.exports = migrateDb;

View File

@@ -55,7 +55,7 @@ configSchema.methods.incrementCount = function () {
// Static methods
configSchema.statics.findByTag = async function (tag) {
return await this.findOne({ tag });
return await this.findOne({ tag }).lean();
};
configSchema.statics.updateByTag = async function (tag, update) {
@@ -67,7 +67,7 @@ const Config = mongoose.models.Config || mongoose.model('Config', configSchema);
module.exports = {
getConfigs: async (filter) => {
try {
return await Config.find(filter).exec();
return await Config.find(filter).lean();
} catch (error) {
console.error(error);
return { config: 'Error getting configs' };
@@ -75,7 +75,7 @@ module.exports = {
},
deleteConfigs: async (filter) => {
try {
return await Config.deleteMany(filter).exec();
return await Config.deleteMany(filter);
} catch (error) {
console.error(error);
return { config: 'Error deleting configs' };

View File

@@ -4,7 +4,7 @@ const { getMessages, deleteMessages } = require('./Message');
const getConvo = async (user, conversationId) => {
try {
return await Conversation.findOne({ user, conversationId }).exec();
return await Conversation.findOne({ user, conversationId }).lean();
} catch (error) {
console.log(error);
return { message: 'Error getting single conversation' };
@@ -24,7 +24,7 @@ module.exports = {
return await Conversation.findOneAndUpdate({ conversationId: conversationId, user }, update, {
new: true,
upsert: true,
}).exec();
});
} catch (error) {
console.log(error);
return { message: 'Error saving conversation' };
@@ -35,10 +35,10 @@ module.exports = {
const totalConvos = (await Conversation.countDocuments({ user })) || 1;
const totalPages = Math.ceil(totalConvos / pageSize);
const convos = await Conversation.find({ user })
.sort({ createdAt: -1, created: -1 })
.sort({ createdAt: -1 })
.skip((pageNumber - 1) * pageSize)
.limit(pageSize)
.exec();
.lean();
return { conversations: convos, pages: totalPages, pageNumber, pageSize };
} catch (error) {
console.log(error);
@@ -54,35 +54,27 @@ module.exports = {
const cache = {};
const convoMap = {};
const promises = [];
// will handle a syncing solution soon
const deletedConvoIds = [];
convoIds.forEach((convo) =>
promises.push(
Conversation.findOne({
user,
conversationId: convo.conversationId,
}).exec(),
}).lean(),
),
);
const results = (await Promise.all(promises)).filter((convo, i) => {
if (!convo) {
deletedConvoIds.push(convoIds[i].conversationId);
return false;
} else {
const page = Math.floor(i / pageSize) + 1;
if (!cache[page]) {
cache[page] = [];
}
cache[page].push(convo);
convoMap[convo.conversationId] = convo;
return true;
const results = (await Promise.all(promises)).filter(Boolean);
results.forEach((convo, i) => {
const page = Math.floor(i / pageSize) + 1;
if (!cache[page]) {
cache[page] = [];
}
cache[page].push(convo);
convoMap[convo.conversationId] = convo;
});
// const startIndex = (pageNumber - 1) * pageSize;
// const convos = results.slice(startIndex, startIndex + pageSize);
const totalPages = Math.ceil(results.length / pageSize);
cache.pages = totalPages;
cache.pageSize = pageSize;
@@ -92,8 +84,6 @@ module.exports = {
pages: totalPages || 1,
pageNumber,
pageSize,
// will handle a syncing solution soon
filter: new Set(deletedConvoIds),
convoMap,
};
} catch (error) {
@@ -121,7 +111,7 @@ module.exports = {
deleteConvos: async (user, filter) => {
let toRemove = await Conversation.find({ ...filter, user }).select('conversationId');
const ids = toRemove.map((instance) => instance.conversationId);
let deleteCount = await Conversation.deleteMany({ ...filter, user }).exec();
let deleteCount = await Conversation.deleteMany({ ...filter, user });
deleteCount.messages = await deleteMessages({ conversationId: { $in: ids } });
return deleteCount;
},

View File

@@ -78,12 +78,12 @@ module.exports = {
},
async deleteMessagesSince({ messageId, conversationId }) {
try {
const message = await Message.findOne({ messageId }).exec();
const message = await Message.findOne({ messageId }).lean();
if (message) {
return await Message.find({ conversationId })
.deleteMany({ createdAt: { $gt: message.createdAt } })
.exec();
return await Message.find({ conversationId }).deleteMany({
createdAt: { $gt: message.createdAt },
});
}
} catch (err) {
console.error(`Error deleting messages: ${err}`);
@@ -93,7 +93,7 @@ module.exports = {
async getMessages(filter) {
try {
return await Message.find(filter).sort({ createdAt: 1 }).exec();
return await Message.find(filter).sort({ createdAt: 1 }).lean();
} catch (err) {
console.error(`Error getting messages: ${err}`);
throw new Error('Failed to get messages.');
@@ -102,7 +102,7 @@ module.exports = {
async deleteMessages(filter) {
try {
return await Message.deleteMany(filter).exec();
return await Message.deleteMany(filter);
} catch (err) {
console.error(`Error deleting messages: ${err}`);
throw new Error('Failed to delete messages.');

View File

@@ -2,7 +2,7 @@ const Preset = require('./schema/presetSchema');
const getPreset = async (user, presetId) => {
try {
return await Preset.findOne({ user, presetId }).exec();
return await Preset.findOne({ user, presetId }).lean();
} catch (error) {
console.log(error);
return { message: 'Error getting single preset' };
@@ -14,10 +14,10 @@ module.exports = {
getPreset,
getPresets: async (user, filter) => {
try {
return await Preset.find({ ...filter, user }).exec();
return await Preset.find({ ...filter, user }).lean();
} catch (error) {
console.log(error);
return { message: 'Error retriving presets' };
return { message: 'Error retrieving presets' };
}
},
savePreset: async (user, { presetId, newPresetId, ...preset }) => {
@@ -31,7 +31,7 @@ module.exports = {
{ presetId, user },
{ $set: update },
{ new: true, upsert: true },
).exec();
);
} catch (error) {
console.log(error);
return { message: 'Error saving preset' };
@@ -40,7 +40,7 @@ module.exports = {
deletePresets: async (user, filter) => {
// let toRemove = await Preset.find({ ...filter, user }).select('presetId');
// const ids = toRemove.map((instance) => instance.presetId);
let deleteCount = await Preset.deleteMany({ ...filter, user }).exec();
let deleteCount = await Preset.deleteMany({ ...filter, user });
return deleteCount;
},
};

View File

@@ -34,7 +34,7 @@ module.exports = {
},
getPrompts: async (filter) => {
try {
return await Prompt.find(filter).exec();
return await Prompt.find(filter).lean();
} catch (error) {
console.error(error);
return { prompt: 'Error getting prompts' };
@@ -42,7 +42,7 @@ module.exports = {
},
deletePrompts: async (filter) => {
try {
return await Prompt.deleteMany(filter).exec();
return await Prompt.deleteMany(filter);
} catch (error) {
console.error(error);
return { prompt: 'Error deleting prompts' };

View File

@@ -14,35 +14,116 @@ const validateOptions = function (options) {
});
};
const createMeiliMongooseModel = function ({ index, indexName, client, attributesToIndex }) {
// console.log('attributesToIndex', attributesToIndex);
// const createMeiliMongooseModel = function ({ index, indexName, client, attributesToIndex }) {
const createMeiliMongooseModel = function ({ index, attributesToIndex }) {
const primaryKey = attributesToIndex[0];
// MeiliMongooseModel is of type Mongoose.Model
class MeiliMongooseModel {
// Clear Meili index
static async clearMeiliIndex() {
await index.delete();
// await index.deleteAllDocuments();
await this.collection.updateMany({ _meiliIndex: true }, { $set: { _meiliIndex: false } });
}
static async resetIndex() {
await this.clearMeiliIndex();
await client.createIndex(indexName, { primaryKey });
}
// Clear Meili index
// Push a mongoDB collection to Meili index
/**
* `syncWithMeili`: synchronizes the data between a MongoDB collection and a MeiliSearch index,
* only triggered if there's ever a discrepancy determined by `api\lib\db\indexSync.js`.
*
* 1. Fetches all documents from the MongoDB collection and the MeiliSearch index.
* 2. Compares the documents from both sources.
* 3. If a document exists in MeiliSearch but not in MongoDB, it's deleted from MeiliSearch.
* 4. If a document exists in MongoDB but not in MeiliSearch, it's added to MeiliSearch.
* 5. If a document exists in both but has different `text` or `title` fields (depending on the `primaryKey`), it's updated in MeiliSearch.
* 6. After all operations, it updates the `_meiliIndex` field in MongoDB to indicate whether the document is indexed in MeiliSearch.
*
* Note: This strategy does not use batch operations for Meilisearch as the `index.addDocuments` will discard
* the entire batch if there's an error with one document, and will not throw an error if there's an issue.
* Also, `index.getDocuments` needs an exact limit on the amount of documents to return, so we build the map in batches.
*
* @returns {Promise} A promise that resolves when the synchronization is complete.
*
* @throws {Error} Throws an error if there's an issue with adding a document to MeiliSearch.
*/
static async syncWithMeili() {
await this.resetIndex();
const docs = await this.find({ _meiliIndex: { $in: [null, false] } });
console.log('docs', docs.length);
const objs = docs.map((doc) => doc.preprocessObjectForIndex());
try {
await index.addDocuments(objs);
const ids = docs.map((doc) => doc._id);
await this.collection.updateMany({ _id: { $in: ids } }, { $set: { _meiliIndex: true } });
let moreDocuments = true;
const mongoDocuments = await this.find().lean();
const format = (doc) => _.pick(doc, attributesToIndex);
// Prepare for comparison
const mongoMap = new Map(mongoDocuments.map((doc) => [doc[primaryKey], format(doc)]));
const indexMap = new Map();
let offset = 0;
const batchSize = 1000;
while (moreDocuments) {
const batch = await index.getDocuments({ limit: batchSize, offset });
if (batch.results.length === 0) {
moreDocuments = false;
}
for (const doc of batch.results) {
indexMap.set(doc[primaryKey], format(doc));
}
offset += batchSize;
}
console.log('indexMap', indexMap.size);
console.log('mongoMap', mongoMap.size);
const updateOps = [];
// Iterate over Meili index documents
for (const [id, doc] of indexMap) {
const update = {};
update[primaryKey] = id;
if (mongoMap.has(id)) {
// Case: Update
// If document also exists in MongoDB, would be update case
if (
(doc.text && doc.text !== mongoMap.get(id).text) ||
(doc.title && doc.title !== mongoMap.get(id).title)
) {
console.log(`${id} had document discrepancy in ${doc.text ? 'text' : 'title'} field`);
updateOps.push({
updateOne: { filter: update, update: { $set: { _meiliIndex: true } } },
});
await index.addDocuments([doc]);
}
} else {
// Case: Delete
// If document does not exist in MongoDB, its a delete case from meili index
await index.deleteDocument(id);
updateOps.push({
updateOne: { filter: update, update: { $set: { _meiliIndex: false } } },
});
}
}
// Iterate over MongoDB documents
for (const [id, doc] of mongoMap) {
const update = {};
update[primaryKey] = id;
// Case: Insert
// If document does not exist in Meili Index, Its an insert case
if (!indexMap.has(id)) {
await index.addDocuments([doc]);
updateOps.push({
updateOne: { filter: update, update: { $set: { _meiliIndex: true } } },
});
} else if (doc._meiliIndex === false) {
updateOps.push({
updateOne: { filter: update, update: { $set: { _meiliIndex: true } } },
});
}
}
if (updateOps.length > 0) {
await this.collection.bulkWrite(updateOps);
console.log(
`[Meilisearch] Finished indexing ${
primaryKey === 'messageId' ? 'messages' : 'conversations'
}`,
);
}
} catch (error) {
console.log('Error adding document to Meili');
console.log('[Meilisearch] Error adding document to Meili');
console.error(error);
}
}
@@ -72,7 +153,7 @@ const createMeiliMongooseModel = function ({ index, indexName, client, attribute
},
{ _id: 1 },
),
);
).lean();
// Add additional data from mongodb into Meili search hits
const populatedHits = data.hits.map(function (hit) {
@@ -81,7 +162,7 @@ const createMeiliMongooseModel = function ({ index, indexName, client, attribute
const originalHit = _.find(hitsFromMongoose, query);
return {
...(originalHit ? originalHit.toJSON() : {}),
...(originalHit ?? {}),
...hit,
};
});

View File

@@ -61,6 +61,8 @@ if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
});
}
convoSchema.index({ createdAt: 1 });
const Conversation = mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
module.exports = Conversation;

View File

@@ -25,7 +25,7 @@ const messageSchema = mongoose.Schema(
type: String,
},
invocationId: {
type: String,
type: Number,
},
parentMessageId: {
type: String,
@@ -100,6 +100,8 @@ if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
});
}
messageSchema.index({ createdAt: 1 });
const Message = mongoose.models.Message || mongoose.model('Message', messageSchema);
module.exports = Message;

View File

@@ -1,6 +1,6 @@
{
"name": "@librechat/backend",
"version": "0.5.4",
"version": "0.5.7",
"description": "",
"scripts": {
"start": "echo 'please run this from the root directory'",
@@ -24,7 +24,7 @@
"@dqbd/tiktoken": "^1.0.2",
"@fortaine/fetch-event-source": "^3.0.6",
"@keyv/mongo": "^2.1.8",
"@waylaidwanderer/chatgpt-api": "^1.37.0",
"@waylaidwanderer/chatgpt-api": "^1.37.2",
"axios": "^1.3.4",
"bcryptjs": "^2.4.3",
"cheerio": "^1.0.0-rc.12",
@@ -43,15 +43,17 @@
"jsonwebtoken": "^9.0.0",
"keyv": "^4.5.2",
"keyv-file": "^0.2.0",
"langchain": "^0.0.109",
"langchain": "^0.0.114",
"lodash": "^4.17.21",
"meilisearch": "^0.33.0",
"mongoose": "^7.1.1",
"nodemailer": "^6.9.1",
"nodemailer": "^6.9.4",
"openai": "^3.2.1",
"openid-client": "^5.4.2",
"passport": "^0.6.0",
"passport-discord": "^0.1.4",
"passport-facebook": "^3.0.0",
"passport-github2": "^0.1.12",
"passport-google-oauth20": "^2.0.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",

View File

@@ -1,4 +1,4 @@
const { registerUser, requestPasswordReset, resetPassword } = require('../services/auth.service');
const { registerUser, requestPasswordReset, resetPassword } = require('../services/AuthService');
const isProduction = process.env.NODE_ENV === 'production';
@@ -32,10 +32,10 @@ const getUserController = async (req, res) => {
const resetPasswordRequestController = async (req, res) => {
try {
const resetService = await requestPasswordReset(req.body.email);
if (resetService.link) {
return res.status(200).json(resetService);
} else {
if (resetService instanceof Error) {
return res.status(400).json(resetService);
} else {
return res.status(200).json(resetService);
}
} catch (e) {
console.log(e);

View File

@@ -1,4 +1,4 @@
const { logoutUser } = require('../../services/auth.service');
const { logoutUser } = require('../../services/AuthService');
const logoutController = async (req, res) => {
const { signedCookies = {} } = req;

View File

@@ -1,7 +1,6 @@
const express = require('express');
const session = require('express-session');
const connectDb = require('../lib/db/connectDb');
const migrateDb = require('../lib/db/migrateDb');
const indexSync = require('../lib/db/indexSync');
const path = require('path');
const cors = require('cors');
@@ -11,6 +10,15 @@ const passport = require('passport');
const port = process.env.PORT || 3080;
const host = process.env.HOST || 'localhost';
const projectPath = path.join(__dirname, '..', '..', 'client');
const {
jwtLogin,
passportLogin,
googleLogin,
githubLogin,
discordLogin,
facebookLogin,
setupOpenId,
} = require('../strategies');
// Init the config and validate it
const config = require('../../config/loader');
@@ -19,7 +27,6 @@ config.validate(); // Validate the config
(async () => {
await connectDb();
console.log('Connected to MongoDB');
await migrateDb();
await indexSync();
const app = express();
@@ -40,19 +47,19 @@ config.validate(); // Validate the config
// OAUTH
app.use(passport.initialize());
require('../strategies/jwtStrategy');
require('../strategies/localStrategy');
passport.use(await jwtLogin());
passport.use(await passportLogin());
if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET) {
require('../strategies/googleStrategy');
passport.use(await googleLogin());
}
if (process.env.FACEBOOK_CLIENT_ID && process.env.FACEBOOK_CLIENT_SECRET) {
require('../strategies/facebookStrategy');
passport.use(await facebookLogin());
}
if (process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET) {
require('../strategies/githubStrategy');
passport.use(await githubLogin());
}
if (process.env.DISCORD_CLIENT_ID && process.env.DISCORD_CLIENT_SECRET) {
require('../strategies/discordStrategy');
passport.use(await discordLogin());
}
if (
process.env.OPENID_CLIENT_ID &&
@@ -69,7 +76,7 @@ config.validate(); // Validate the config
}),
);
app.use(passport.session());
require('../strategies/openidStrategy');
await setupOpenId();
}
app.use('/oauth', routes.oauth);
// api endpoint

View File

@@ -10,7 +10,11 @@ const { handleError, sendMessage, createOnProgress } = require('./handlers');
const abortControllers = new Map();
router.post('/abort', requireJwtAuth, async (req, res) => {
return await abortMessage(req, res, abortControllers);
try {
return await abortMessage(req, res, abortControllers);
} catch (err) {
console.error(err);
}
});
router.post('/', requireJwtAuth, async (req, res) => {
@@ -28,10 +32,10 @@ router.post('/', requireJwtAuth, async (req, res) => {
token: req.body?.token ?? null,
modelOptions: {
model: req.body?.model ?? 'claude-1',
temperature: req.body?.temperature ?? 0.7,
temperature: req.body?.temperature ?? 1,
maxOutputTokens: req.body?.maxOutputTokens ?? 1024,
topP: req.body?.topP ?? 0.7,
topK: req.body?.topK ?? 40,
topK: req.body?.topK ?? 5,
},
};

View File

@@ -172,7 +172,8 @@ const ask = async ({
let unfinished = false;
if (partialText?.trim()?.length > response.text.length) {
response.text = partialText;
unfinished = true;
unfinished = false;
//setting "unfinished" to false fix bing image generation error msg and allows to continue a convo after being triggered by censorship (bing does remember the context after a "censored error" so there is no reason to end the convo)
}
let responseMessage = {

View File

@@ -15,7 +15,11 @@ const requireJwtAuth = require('../../../middleware/requireJwtAuth');
const abortControllers = new Map();
router.post('/abort', requireJwtAuth, async (req, res) => {
return await abortMessage(req, res, abortControllers);
try {
return await abortMessage(req, res, abortControllers);
} catch (err) {
console.error(err);
}
});
router.post('/', requireJwtAuth, async (req, res) => {

View File

@@ -9,7 +9,11 @@ const requireJwtAuth = require('../../../middleware/requireJwtAuth');
const abortControllers = new Map();
router.post('/abort', requireJwtAuth, async (req, res) => {
return await abortMessage(req, res, abortControllers);
try {
return await abortMessage(req, res, abortControllers);
} catch (err) {
console.error(err);
}
});
router.post('/', requireJwtAuth, async (req, res) => {

View File

@@ -18,6 +18,11 @@ router.get('/', async function (req, res) {
const serverDomain = process.env.DOMAIN_SERVER || 'http://localhost:3080';
const registrationEnabled = process.env.ALLOW_REGISTRATION === 'true';
const socialLoginEnabled = process.env.ALLOW_SOCIAL_LOGIN === 'true';
const emailEnabled =
!!process.env.EMAIL_SERVICE &&
!!process.env.EMAIL_USERNAME &&
!!process.env.EMAIL_PASSWORD &&
!!process.env.EMAIL_FROM;
return res.status(200).send({
appTitle,
@@ -30,6 +35,7 @@ router.get('/', async function (req, res) {
serverDomain,
registrationEnabled,
socialLoginEnabled,
emailEnabled,
});
} catch (err) {
console.error(err);

View File

@@ -14,7 +14,7 @@ router.get('/:conversationId', requireJwtAuth, async (req, res) => {
const convo = await getConvo(req.user.id, conversationId);
if (convo) {
res.status(200).send(convo.toObject());
res.status(200).send(convo);
} else {
res.status(404).end();
}
@@ -27,7 +27,8 @@ router.post('/clear', requireJwtAuth, async (req, res) => {
filter = { conversationId };
}
console.log('source:', source);
// for debugging deletion source
// console.log('source:', source);
if (source === 'button' && !conversationId) {
return res.status(200).send('No conversationId provided');

View File

@@ -1,9 +1,50 @@
const axios = require('axios');
const express = require('express');
const router = express.Router();
const { availableTools } = require('../../app/clients/tools');
const { addOpenAPISpecs } = require('../../app/clients/tools/util/addOpenAPISpecs');
const getOpenAIModels = (opts = { azure: false }) => {
const openAIApiKey = process.env.OPENAI_API_KEY;
const azureOpenAIApiKey = process.env.AZURE_API_KEY;
const userProvidedOpenAI = openAIApiKey
? openAIApiKey === 'user_provided'
: azureOpenAIApiKey === 'user_provided';
const fetchOpenAIModels = async (opts = { azure: false, plugins: false }, _models = []) => {
let models = _models.slice() ?? [];
if (opts.azure) {
/* TODO: Add Azure models from api/models */
return models;
}
let basePath = 'https://api.openai.com/v1/';
const reverseProxyUrl = process.env.OPENAI_REVERSE_PROXY;
if (reverseProxyUrl) {
basePath = reverseProxyUrl.match(/.*v1/)[0];
}
if (basePath.includes('v1')) {
try {
const res = await axios.get(`${basePath}/models`, {
headers: {
Authorization: `Bearer ${openAIApiKey}`,
},
});
models = res.data.data.map((item) => item.id);
} catch (err) {
console.error(err);
}
}
if (!reverseProxyUrl) {
const regex = /(text-davinci-003|gpt-)/;
models = models.filter((model) => regex.test(model));
}
return models;
};
const getOpenAIModels = async (opts = { azure: false, plugins: false }) => {
let models = [
'gpt-4',
'gpt-4-0613',
@@ -11,13 +52,34 @@ const getOpenAIModels = (opts = { azure: false }) => {
'gpt-3.5-turbo-16k',
'gpt-3.5-turbo-0613',
'gpt-3.5-turbo-0301',
'text-davinci-003',
];
const key = opts.azure ? 'AZURE_OPENAI_MODELS' : 'OPENAI_MODELS';
if (process.env[key]) {
models = String(process.env[key]).split(',');
if (!opts.plugins) {
models.push('text-davinci-003');
}
let key;
if (opts.azure) {
key = 'AZURE_OPENAI_MODELS';
} else if (opts.plugins) {
key = 'PLUGIN_MODELS';
} else {
key = 'OPENAI_MODELS';
}
if (process.env[key]) {
models = String(process.env[key]).split(',');
return models;
}
if (userProvidedOpenAI) {
console.warn(
`When setting OPENAI_API_KEY to 'user_provided', ${key} must be set manually or default values will be used`,
);
return models;
}
models = await fetchOpenAIModels(opts, models);
return models;
};
@@ -44,22 +106,6 @@ const getAnthropicModels = () => {
return models;
};
const getPluginModels = () => {
let models = [
'gpt-4',
'gpt-4-0613',
'gpt-3.5-turbo',
'gpt-3.5-turbo-16k',
'gpt-3.5-turbo-0613',
'gpt-3.5-turbo-0301',
];
if (process.env.PLUGIN_MODELS) {
models = String(process.env.PLUGIN_MODELS).split(',');
}
return models;
};
let i = 0;
router.get('/', async function (req, res) {
let key, palmUser;
@@ -93,31 +139,29 @@ router.get('/', async function (req, res) {
key || palmUser
? { userProvide: palmUser, availableModels: ['chat-bison', 'text-bison', 'codechat-bison'] }
: false;
const openAIApiKey = process.env.OPENAI_API_KEY;
const azureOpenAIApiKey = process.env.AZURE_API_KEY;
const userProvidedOpenAI = openAIApiKey
? openAIApiKey === 'user_provided'
: azureOpenAIApiKey === 'user_provided';
const openAI = openAIApiKey
? { availableModels: getOpenAIModels(), userProvide: openAIApiKey === 'user_provided' }
? { availableModels: await getOpenAIModels(), userProvide: openAIApiKey === 'user_provided' }
: false;
const azureOpenAI = azureOpenAIApiKey
? {
availableModels: getOpenAIModels({ azure: true }),
availableModels: await getOpenAIModels({ azure: true }),
userProvide: azureOpenAIApiKey === 'user_provided',
}
: false;
const gptPlugins =
openAIApiKey || azureOpenAIApiKey
? {
availableModels: getPluginModels(),
availableModels: await getOpenAIModels({ plugins: true }),
plugins,
availableAgents: ['classic', 'functions'],
userProvide: userProvidedOpenAI,
}
: false;
const bingAI = process.env.BINGAI_TOKEN
? { userProvide: process.env.BINGAI_TOKEN == 'user_provided' }
? {
availableModels: ['BingAI', 'Sydney'],
userProvide: process.env.BINGAI_TOKEN == 'user_provided',
}
: false;
const chatGPTBrowser = process.env.CHATGPT_TOKEN
? {

View File

@@ -6,7 +6,7 @@ const requireJwtAuth = require('../../middleware/requireJwtAuth');
router.get('/', requireJwtAuth, async (req, res) => {
const presets = (await getPresets(req.user.id)).map((preset) => {
return preset.toObject();
return preset;
});
res.status(200).send(presets);
});
@@ -20,7 +20,7 @@ router.post('/', requireJwtAuth, async (req, res) => {
await savePreset(req.user.id, update);
const presets = (await getPresets(req.user.id)).map((preset) => {
return preset.toObject();
return preset;
});
res.status(201).send(presets);
} catch (error) {
@@ -41,12 +41,8 @@ router.post('/delete', requireJwtAuth, async (req, res) => {
try {
await deletePresets(req.user.id, filter);
const presets = (await getPresets(req.user.id)).map((preset) => preset.toObject());
// console.log('delete preset response', presets);
const presets = await getPresets(req.user.id);
res.status(201).send(presets);
// res.status(201).send(dbResponse);
} catch (error) {
console.error(error);
res.status(500).send(error);

View File

@@ -90,11 +90,6 @@ router.get('/', requireJwtAuth, async function (req, res) {
}
});
router.get('/clear', async function (req, res) {
await Message.resetIndex();
res.send('cleared');
});
router.get('/test', async function (req, res) {
const { q } = req.query;
const messages = (

View File

@@ -9,12 +9,9 @@ const requireJwtAuth = require('../../middleware/requireJwtAuth');
router.post('/', requireJwtAuth, async (req, res) => {
try {
const { arg } = req.body;
// console.log('context:', arg, req.body);
// console.log(typeof req.body === 'object' ? { ...req.body, ...req.query } : req.query);
const model = await load(registry[models['gpt-3.5-turbo']]);
const encoder = new Tiktoken(model.bpe_ranks, model.special_tokens, model.pat_str);
const tokens = encoder.encode(arg.text);
const tokens = encoder.encode(arg?.text ?? arg);
encoder.free();
res.send({ count: tokens.length });
} catch (e) {

View File

@@ -54,7 +54,7 @@ const registerUser = async (user) => {
const { email, password, name, username } = user;
try {
const existingUser = await User.findOne({ email });
const existingUser = await User.findOne({ email }).lean();
if (existingUser) {
console.info(
@@ -104,7 +104,7 @@ const registerUser = async (user) => {
* @returns
*/
const requestPasswordReset = async (email) => {
const user = await User.findOne({ email });
const user = await User.findOne({ email }).lean();
if (!user) {
return new Error('Email does not exist');
}
@@ -125,16 +125,26 @@ const requestPasswordReset = async (email) => {
const link = `${domains.client}/reset-password?token=${resetToken}&userId=${user._id}`;
sendEmail(
user.email,
'Password Reset Request',
{
name: user.name,
link: link,
},
'./template/requestResetPassword.handlebars',
);
return { link };
const emailEnabled =
!!process.env.EMAIL_SERVICE &&
!!process.env.EMAIL_USERNAME &&
!!process.env.EMAIL_PASSWORD &&
!!process.env.EMAIL_FROM;
if (emailEnabled) {
sendEmail(
user.email,
'Password Reset Request',
{
name: user.name,
link: link,
},
'requestPasswordReset.handlebars',
);
return { link: '' };
} else {
return { link };
}
};
/**
@@ -170,7 +180,7 @@ const resetPassword = async (userId, token, password) => {
{
name: user.name,
},
'./template/resetPassword.handlebars',
'resetPassword.handlebars',
);
await passwordResetToken.deleteOne();

View File

@@ -3,7 +3,7 @@ const { encrypt, decrypt } = require('../../utils/');
const getUserPluginAuthValue = async (user, authField) => {
try {
const pluginAuth = await PluginAuth.findOne({ user, authField });
const pluginAuth = await PluginAuth.findOne({ user, authField }).lean();
if (!pluginAuth) {
return null;
}
@@ -43,7 +43,7 @@ const getUserPluginAuthValue = async (user, authField) => {
const updateUserPluginAuth = async (userId, authField, pluginKey, value) => {
try {
const encryptedValue = encrypt(value);
const pluginAuth = await PluginAuth.findOne({ userId, authField });
const pluginAuth = await PluginAuth.findOne({ userId, authField }).lean();
if (pluginAuth) {
const pluginAuth = await PluginAuth.updateOne(
{ userId, authField },

View File

@@ -1,51 +1,51 @@
const passport = require('passport');
const { Strategy: DiscordStrategy } = require('passport-discord');
const User = require('../models/User');
const config = require('../../config/loader');
const domains = config.domains;
const discordLogin = new DiscordStrategy(
{
clientID: process.env.DISCORD_CLIENT_ID,
clientSecret: process.env.DISCORD_CLIENT_SECRET,
callbackURL: `${domains.server}${process.env.DISCORD_CALLBACK_URL}`,
scope: ['identify', 'email'], // Request scopes
authorizationURL: 'https://discord.com/api/oauth2/authorize?prompt=none', // Add the prompt query parameter
},
async (accessToken, refreshToken, profile, cb) => {
try {
const email = profile.email;
const discordId = profile.id;
const discordLogin = async () =>
new DiscordStrategy(
{
clientID: process.env.DISCORD_CLIENT_ID,
clientSecret: process.env.DISCORD_CLIENT_SECRET,
callbackURL: `${domains.server}${process.env.DISCORD_CALLBACK_URL}`,
scope: ['identify', 'email'], // Request scopes
authorizationURL: 'https://discord.com/api/oauth2/authorize?prompt=none', // Add the prompt query parameter
},
async (accessToken, refreshToken, profile, cb) => {
try {
const email = profile.email;
const discordId = profile.id;
const oldUser = await User.findOne({ email });
if (oldUser) {
return cb(null, oldUser);
const oldUser = await User.findOne({ email });
if (oldUser) {
return cb(null, oldUser);
}
let avatarURL;
if (profile.avatar) {
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png';
avatarURL = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
} else {
const defaultAvatarNum = Number(profile.discriminator) % 5;
avatarURL = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNum}.png`;
}
const newUser = await User.create({
provider: 'discord',
discordId,
username: profile.username,
email,
name: profile.global_name,
avatar: avatarURL,
});
cb(null, newUser);
} catch (err) {
console.error(err);
cb(err);
}
},
);
let avatarURL;
if (profile.avatar) {
const format = profile.avatar.startsWith('a_') ? 'gif' : 'png';
avatarURL = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
} else {
const defaultAvatarNum = Number(profile.discriminator) % 5;
avatarURL = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNum}.png`;
}
const newUser = await User.create({
provider: 'discord',
discordId,
username: profile.username,
email,
name: profile.global_name,
avatar: avatarURL,
});
cb(null, newUser);
} catch (err) {
console.error(err);
cb(err);
}
},
);
passport.use(discordLogin);
module.exports = discordLogin;

View File

@@ -1,59 +1,59 @@
const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
const User = require('../models/User');
const config = require('../../config/loader');
const domains = config.domains;
// facebook strategy
const facebookLogin = new FacebookStrategy(
{
clientID: process.env.FACEBOOK_APP_ID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackURL: `${domains.server}${process.env.FACEBOOK_CALLBACK_URL}`,
proxy: true,
// profileFields: [
// 'id',
// 'email',
// 'gender',
// 'profileUrl',
// 'displayName',
// 'locale',
// 'name',
// 'timezone',
// 'updated_time',
// 'verified',
// 'picture.type(large)'
// ]
},
async (accessToken, refreshToken, profile, done) => {
console.log('facebookLogin => profile', profile);
try {
const oldUser = await User.findOne({ email: profile.emails[0].value });
const facebookLogin = async () =>
new FacebookStrategy(
{
clientID: process.env.FACEBOOK_APP_ID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackURL: `${domains.server}${process.env.FACEBOOK_CALLBACK_URL}`,
proxy: true,
// profileFields: [
// 'id',
// 'email',
// 'gender',
// 'profileUrl',
// 'displayName',
// 'locale',
// 'name',
// 'timezone',
// 'updated_time',
// 'verified',
// 'picture.type(large)'
// ]
},
async (accessToken, refreshToken, profile, done) => {
console.log('facebookLogin => profile', profile);
try {
const oldUser = await User.findOne({ email: profile.emails[0].value });
if (oldUser) {
console.log('FACEBOOK LOGIN => found user', oldUser);
return done(null, oldUser);
if (oldUser) {
console.log('FACEBOOK LOGIN => found user', oldUser);
return done(null, oldUser);
}
} catch (err) {
console.log(err);
}
} catch (err) {
console.log(err);
}
// register user
try {
const newUser = await new User({
provider: 'facebook',
facebookId: profile.id,
username: profile.name.givenName + profile.name.familyName,
email: profile.emails[0].value,
name: profile.displayName,
avatar: profile.photos[0].value,
}).save();
// register user
try {
const newUser = await new User({
provider: 'facebook',
facebookId: profile.id,
username: profile.name.givenName + profile.name.familyName,
email: profile.emails[0].value,
name: profile.displayName,
avatar: profile.photos[0].value,
}).save();
done(null, newUser);
} catch (err) {
console.log(err);
}
},
);
done(null, newUser);
} catch (err) {
console.log(err);
}
},
);
passport.use(facebookLogin);
module.exports = facebookLogin;

View File

@@ -1,4 +1,3 @@
const passport = require('passport');
const { Strategy: GitHubStrategy } = require('passport-github2');
const config = require('../../config/loader');
const domains = config.domains;
@@ -6,42 +5,43 @@ const domains = config.domains;
const User = require('../models/User');
// GitHub strategy
const githubLogin = new GitHubStrategy(
{
clientID: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackURL: `${domains.server}${process.env.GITHUB_CALLBACK_URL}`,
proxy: false,
scope: ['user:email'], // Request email scope
},
async (accessToken, refreshToken, profile, cb) => {
try {
let email;
if (profile.emails && profile.emails.length > 0) {
email = profile.emails[0].value;
const githubLogin = async () =>
new GitHubStrategy(
{
clientID: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackURL: `${domains.server}${process.env.GITHUB_CALLBACK_URL}`,
proxy: false,
scope: ['user:email'], // Request email scope
},
async (accessToken, refreshToken, profile, cb) => {
try {
let email;
if (profile.emails && profile.emails.length > 0) {
email = profile.emails[0].value;
}
const oldUser = await User.findOne({ email });
if (oldUser) {
return cb(null, oldUser);
}
const newUser = await new User({
provider: 'github',
githubId: profile.id,
username: profile.username,
email,
emailVerified: profile.emails[0].verified,
name: profile.displayName,
avatar: profile.photos[0].value,
}).save();
cb(null, newUser);
} catch (err) {
console.error(err);
cb(err);
}
},
);
const oldUser = await User.findOne({ email });
if (oldUser) {
return cb(null, oldUser);
}
const newUser = await new User({
provider: 'github',
githubId: profile.id,
username: profile.username,
email,
emailVerified: profile.emails[0].verified,
name: profile.displayName,
avatar: profile.photos[0].value,
}).save();
cb(null, newUser);
} catch (err) {
console.error(err);
cb(err);
}
},
);
passport.use(githubLogin);
module.exports = githubLogin;

View File

@@ -1,4 +1,3 @@
const passport = require('passport');
const { Strategy: GoogleStrategy } = require('passport-google-oauth20');
const config = require('../../config/loader');
const domains = config.domains;
@@ -6,38 +5,39 @@ const domains = config.domains;
const User = require('../models/User');
// google strategy
const googleLogin = new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `${domains.server}${process.env.GOOGLE_CALLBACK_URL}`,
proxy: true,
},
async (accessToken, refreshToken, profile, cb) => {
try {
const oldUser = await User.findOne({ email: profile.emails[0].value });
if (oldUser) {
return cb(null, oldUser);
const googleLogin = async () =>
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `${domains.server}${process.env.GOOGLE_CALLBACK_URL}`,
proxy: true,
},
async (accessToken, refreshToken, profile, cb) => {
try {
const oldUser = await User.findOne({ email: profile.emails[0].value });
if (oldUser) {
return cb(null, oldUser);
}
} catch (err) {
console.log(err);
}
} catch (err) {
console.log(err);
}
try {
const newUser = await new User({
provider: 'google',
googleId: profile.id,
username: profile.name.givenName,
email: profile.emails[0].value,
emailVerified: profile.emails[0].verified,
name: `${profile.name.givenName} ${profile.name.familyName}`,
avatar: profile.photos[0].value,
}).save();
cb(null, newUser);
} catch (err) {
console.log(err);
}
},
);
try {
const newUser = await new User({
provider: 'google',
googleId: profile.id,
username: profile.name.givenName,
email: profile.emails[0].value,
emailVerified: profile.emails[0].verified,
name: `${profile.name.givenName} ${profile.name.familyName}`,
avatar: profile.photos[0].value,
}).save();
cb(null, newUser);
} catch (err) {
console.log(err);
}
},
);
passport.use(googleLogin);
module.exports = googleLogin;

17
api/strategies/index.js Normal file
View File

@@ -0,0 +1,17 @@
const passportLogin = require('./localStrategy');
const googleLogin = require('./googleStrategy');
const githubLogin = require('./githubStrategy');
const discordLogin = require('./discordStrategy');
const jwtLogin = require('./jwtStrategy');
const facebookLogin = require('./facebookStrategy');
const setupOpenId = require('./openidStrategy');
module.exports = {
passportLogin,
googleLogin,
githubLogin,
discordLogin,
jwtLogin,
facebookLogin,
setupOpenId,
};

View File

@@ -1,26 +1,26 @@
const passport = require('passport');
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
const User = require('../models/User');
// JWT strategy
const jwtLogin = new JwtStrategy(
{
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET,
},
async (payload, done) => {
try {
const user = await User.findById(payload.id);
if (user) {
done(null, user);
} else {
console.log('JwtStrategy => no user found');
done(null, false);
const jwtLogin = async () =>
new JwtStrategy(
{
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET,
},
async (payload, done) => {
try {
const user = await User.findById(payload.id);
if (user) {
done(null, user);
} else {
console.log('JwtStrategy => no user found');
done(null, false);
}
} catch (err) {
done(err, false);
}
} catch (err) {
done(err, false);
}
},
);
},
);
passport.use(jwtLogin);
module.exports = jwtLogin;

View File

@@ -1,62 +1,60 @@
const passport = require('passport');
const PassportLocalStrategy = require('passport-local').Strategy;
const User = require('../models/User');
const { loginSchema } = require('./validators');
const DebugControl = require('../utils/debug.js');
const passportLogin = new PassportLocalStrategy(
{
usernameField: 'email',
passwordField: 'password',
session: false,
passReqToCallback: true,
},
async (req, email, password, done) => {
const { error } = loginSchema.validate(req.body);
if (error) {
log({
title: 'Passport Local Strategy - Validation Error',
parameters: [{ name: 'req.body', value: req.body }],
});
return done(null, false, { message: error.details[0].message });
}
try {
const user = await User.findOne({ email: email.trim() });
if (!user) {
const passportLogin = async () =>
new PassportLocalStrategy(
{
usernameField: 'email',
passwordField: 'password',
session: false,
passReqToCallback: true,
},
async (req, email, password, done) => {
const { error } = loginSchema.validate(req.body);
if (error) {
log({
title: 'Passport Local Strategy - User Not Found',
parameters: [{ name: 'email', value: email }],
title: 'Passport Local Strategy - Validation Error',
parameters: [{ name: 'req.body', value: req.body }],
});
return done(null, false, { message: 'Email does not exists.' });
return done(null, false, { message: error.details[0].message });
}
user.comparePassword(password, function (err, isMatch) {
if (err) {
try {
const user = await User.findOne({ email: email.trim() });
if (!user) {
log({
title: 'Passport Local Strategy - Compare password error',
parameters: [{ name: 'error', value: err }],
title: 'Passport Local Strategy - User Not Found',
parameters: [{ name: 'email', value: email }],
});
return done(err);
}
if (!isMatch) {
log({
title: 'Passport Local Strategy - Password does not match',
parameters: [{ name: 'isMatch', value: isMatch }],
});
return done(null, false, { message: 'Incorrect password.' });
return done(null, false, { message: 'Email does not exists.' });
}
return done(null, user);
});
} catch (err) {
return done(err);
}
},
);
user.comparePassword(password, function (err, isMatch) {
if (err) {
log({
title: 'Passport Local Strategy - Compare password error',
parameters: [{ name: 'error', value: err }],
});
return done(err);
}
if (!isMatch) {
log({
title: 'Passport Local Strategy - Password does not match',
parameters: [{ name: 'isMatch', value: isMatch }],
});
return done(null, false, { message: 'Incorrect password.' });
}
passport.use(passportLogin);
return done(null, user);
});
} catch (err) {
return done(err);
}
},
);
function log({ title, parameters }) {
DebugControl.log.functionName(title);
@@ -64,3 +62,5 @@ function log({ title, parameters }) {
DebugControl.log.parameters(parameters);
}
}
module.exports = passportLogin;

View File

@@ -36,8 +36,9 @@ const downloadImage = async (url, imagePath, accessToken) => {
}
};
Issuer.discover(process.env.OPENID_ISSUER)
.then((issuer) => {
async function setupOpenId() {
try {
const issuer = await Issuer.discover(process.env.OPENID_ISSUER);
const client = new issuer.Client({
client_id: process.env.OPENID_CLIENT_ID,
client_secret: process.env.OPENID_CLIENT_SECRET,
@@ -66,13 +67,15 @@ Issuer.discover(process.env.OPENID_ISSUER)
fullName = userinfo.given_name;
} else if (userinfo.family_name) {
fullName = userinfo.family_name;
} else {
fullName = userinfo.username || userinfo.email;
}
if (!user) {
user = new User({
provider: 'openid',
openidId: userinfo.sub,
username: userinfo.given_name || '',
username: userinfo.username || userinfo.given_name || '',
email: userinfo.email || '',
emailVerified: userinfo.email_verified || false,
name: fullName,
@@ -80,7 +83,7 @@ Issuer.discover(process.env.OPENID_ISSUER)
} else {
user.provider = 'openid';
user.openidId = userinfo.sub;
user.username = userinfo.given_name || '';
user.username = userinfo.username || userinfo.given_name || '';
user.name = fullName;
}
@@ -128,7 +131,9 @@ Issuer.discover(process.env.OPENID_ISSUER)
);
passport.use('openid', openidLogin);
})
.catch((err) => {
} catch (err) {
console.error(err);
});
}
}
module.exports = setupOpenId;

View File

@@ -1,5 +1,3 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
const nodemailer = require('nodemailer');
const handlebars = require('handlebars');
const fs = require('fs');
@@ -7,21 +5,19 @@ const path = require('path');
const sendEmail = async (email, subject, payload, template) => {
try {
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
port: 465,
service: process.env.EMAIL_SERVICE,
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD,
},
});
const source = fs.readFileSync(path.join(__dirname, template), 'utf8');
const source = fs.readFileSync(path.join(__dirname, 'emails', template), 'utf8');
const compiledTemplate = handlebars.compile(source);
const options = () => {
return {
from: process.env.FROM_EMAIL,
from: process.env.EMAIL_FROM,
to: email,
subject: subject,
html: compiledTemplate(payload),
@@ -31,26 +27,17 @@ const sendEmail = async (email, subject, payload, template) => {
// Send email
transporter.sendMail(options(), (error, info) => {
if (error) {
console.log(error);
return error;
} else {
return res.status(200).json({
success: true,
});
console.log(info);
return info;
}
});
} catch (error) {
console.log(error);
return error;
}
};
/*
Example:
sendEmail(
"youremail@gmail.com,
"Email subject",
{ name: "Eze" },
"./templates/layouts/main.handlebars"
);
*/
module.exports = sendEmail;

View File

@@ -1,23 +1,23 @@
module.exports = {
presets: [
["@babel/preset-env", { "targets": { "node": "current" } }], //compiling ES2015+ syntax
['@babel/preset-react', {runtime: 'automatic'}],
"@babel/preset-typescript"
['@babel/preset-env', { 'targets': { 'node': 'current' } }], //compiling ES2015+ syntax
['@babel/preset-react', { runtime: 'automatic' }],
'@babel/preset-typescript',
],
/*
Babel's code transformations are enabled by applying plugins (or presets) to your configuration file.
*/
plugins: [
"@babel/plugin-transform-runtime",
'@babel/plugin-transform-runtime',
'babel-plugin-transform-import-meta',
'babel-plugin-transform-vite-meta-env',
'babel-plugin-replace-ts-export-assignment',
[
"babel-plugin-root-import",
'babel-plugin-root-import',
{
"rootPathPrefix": "~/",
"rootPathSuffix": "./src"
}
]
]
}
'rootPathPrefix': '~/',
'rootPathSuffix': './src',
},
],
],
};

View File

@@ -2,14 +2,14 @@ module.exports = {
roots: ['<rootDir>/src'],
testEnvironment: 'jsdom',
testEnvironmentOptions: {
url: 'http://localhost:3080'
url: 'http://localhost:3080',
},
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!<rootDir>/node_modules/',
'!src/**/*.css.d.ts',
'!src/**/*.d.ts'
'!src/**/*.d.ts',
],
coveragePathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/setupTests.js'],
// Todo: Add coverageThreshold once we have enough coverage
@@ -26,8 +26,8 @@ module.exports = {
'\\.(css)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'jest-file-loader',
'layout-test-utils': '<rootDir>/test/layout-test-utils',
'^~/(.*)$': '<rootDir>/src/$1'
'^test/(.*)$': '<rootDir>/test/$1',
'^~/(.*)$': '<rootDir>/src/$1',
},
restoreMocks: true,
testResultsProcessor: 'jest-junit',
@@ -35,10 +35,10 @@ module.exports = {
transform: {
'\\.[jt]sx?$': 'babel-jest',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'jest-file-loader'
'jest-file-loader',
},
transformIgnorePatterns: ['node_modules/?!@zattoo/use-double-click'],
preset: 'ts-jest',
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect', '<rootDir>/test/setupTests.js'],
clearMocks: true
clearMocks: true,
};

View File

@@ -1,15 +1,17 @@
server {
listen 80;
# listen 443 ssl;
# ssl_certificate /etc/nginx/ssl/nginx.crt;
# ssl_certificate_key /etc/nginx/ssl/nginx.key;
server_name localhost;
location /api {
# Proxy requests to the API service
proxy_pass http://api:3080/api;
}
location / {
# Serve your React app
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
proxy_pass http://api:3080;
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@librechat/frontend",
"version": "0.5.4",
"version": "0.5.7",
"description": "",
"scripts": {
"data-provider": "cd .. && npm run build:data-provider",
@@ -53,6 +53,7 @@
"export-from-json": "^1.7.2",
"filenamify": "^6.0.0",
"html2canvas": "^1.4.1",
"librechat-data-provider": "*",
"lodash": "^4.17.21",
"lucide-react": "^0.220.0",
"pino": "^8.12.1",
@@ -76,8 +77,7 @@
"tailwind-merge": "^1.9.1",
"tailwindcss-animate": "^1.0.5",
"tailwindcss-radix": "^2.8.0",
"url": "^0.11.0",
"@librechat/data-provider": "*"
"url": "^0.11.0"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
@@ -97,7 +97,7 @@
"@types/node": "^20.3.0",
"@types/react": "^18.2.11",
"@types/react-dom": "^18.2.4",
"@vitejs/plugin-react": "^4.0.0",
"@vitejs/plugin-react": "^4.0.4",
"autoprefixer": "^10.4.13",
"babel-jest": "^29.5.0",
"babel-loader": "^9.1.2",
@@ -125,7 +125,7 @@
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.2",
"typescript": "^5.0.4",
"vite": "^4.3.9",
"vite": "^4.4.9",
"vite-plugin-html": "^3.2.0"
}
}

View File

@@ -1,8 +1,8 @@
module.exports = {
plugins: [
require("postcss-import"),
require("postcss-preset-env"),
require("tailwindcss"),
require("autoprefixer"),
]
require('postcss-import'),
require('postcss-preset-env'),
require('tailwindcss'),
require('autoprefixer'),
],
};

View File

@@ -1,10 +1,8 @@
import { RouterProvider } from 'react-router-dom';
import { ScreenshotProvider } from './utils/screenshotContext.jsx';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { RecoilRoot } from 'recoil';
import { RouterProvider } from 'react-router-dom';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { QueryClient, QueryClientProvider, QueryCache } from '@tanstack/react-query';
import { ThemeProvider } from './hooks/ThemeContext';
import { useApiErrorBoundary } from './hooks/ApiErrorBoundaryContext';
import { ScreenshotProvider, ThemeProvider, useApiErrorBoundary } from './hooks';
import { router } from './routes';
const App = () => {

View File

@@ -0,0 +1 @@
export * from './types';

View File

@@ -0,0 +1,50 @@
import { TConversation, TPreset } from 'librechat-data-provider';
export type TSetOption = (param: number | string) => (newValue: number | string | boolean) => void;
export type TSetExample = (
i: number,
type: string,
newValue: number | string | boolean | null,
) => void;
export enum ESide {
Top = 'top',
Right = 'right',
Bottom = 'bottom',
Left = 'left',
}
export type TBaseSettingsProps = {
conversation: TConversation | TPreset | null;
className?: string;
isPreset?: boolean;
readonly?: boolean;
};
export type TSettingsProps = TBaseSettingsProps & {
setOption: TSetOption;
};
export type TModels = {
models: string[];
};
export type TModelSelectProps = TSettingsProps & TModels;
export type TEditPresetProps = {
open: boolean;
onOpenChange: React.Dispatch<React.SetStateAction<boolean>>;
preset: TPreset;
title?: string;
};
export type TSetOptionsPayload = {
setOption: TSetOption;
setExample: TSetExample;
addExample: () => void;
removeExample: () => void;
setAgentOption: TSetOption;
getConversation: () => TConversation | TPreset | null;
checkPluginSelection: (value: string) => boolean;
setTools: (newValue: string) => void;
};

View File

@@ -6,7 +6,7 @@ import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import store from '~/store';
import { localize } from '~/localization/Translation';
import { useGetStartupConfig } from '@librechat/data-provider';
import { useGetStartupConfig } from 'librechat-data-provider';
import { GoogleIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
function Login() {

View File

@@ -2,7 +2,7 @@ import { useForm } from 'react-hook-form';
import { useRecoilValue } from 'recoil';
import store from '~/store';
import { localize } from '~/localization/Translation';
import { TLoginUser } from '@librechat/data-provider';
import { TLoginUser } from 'librechat-data-provider';
type TLoginFormProps = {
onSubmit: (data: TLoginUser) => void;
@@ -107,6 +107,7 @@ function LoginForm({ onSubmit }: TLoginFormProps) {
<div className="mt-6">
<button
aria-label="Sign in"
data-testid="login-button"
type="submit"
className="w-full transform rounded-sm bg-green-500 px-4 py-3 tracking-wide text-white transition-colors duration-200 hover:bg-green-600 focus:bg-green-600 focus:outline-none"
>

View File

@@ -8,7 +8,7 @@ import {
useRegisterUserMutation,
TRegisterUser,
useGetStartupConfig,
} from '@librechat/data-provider';
} from 'librechat-data-provider';
import { GoogleIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
function Registration() {
@@ -55,13 +55,16 @@ function Registration() {
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-white pt-6 sm:pt-0">
<div className="mt-6 w-96 overflow-hidden bg-white px-6 py-4 sm:max-w-md sm:rounded-lg">
<h1 className="mb-4 text-center text-3xl font-semibold">Create your account</h1>
<h1 className="mb-4 text-center text-3xl font-semibold">
{localize(lang, 'com_auth_create_account')}
</h1>
{error && (
<div
className="relative mt-4 rounded border border-red-400 bg-red-100 px-4 py-3 text-red-700"
role="alert"
data-testid="registration-error"
>
There was an error attempting to register your account. Please try again. {errorMessage}
{localize(lang, 'com_auth_error_create')} {errorMessage}
</div>
)}
<form

View File

@@ -1,13 +1,14 @@
import { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { useRecoilValue } from 'recoil';
import store from '~/store';
import { localize } from '~/localization/Translation';
import {
useRequestPasswordResetMutation,
useGetStartupConfig,
TRequestPasswordReset,
TRequestPasswordResetResponse,
} from '@librechat/data-provider';
} from 'librechat-data-provider';
function RequestPasswordReset() {
const lang = useRecoilValue(store.lang);
@@ -17,15 +18,19 @@ function RequestPasswordReset() {
formState: { errors },
} = useForm<TRequestPasswordReset>();
const requestPasswordReset = useRequestPasswordResetMutation();
const [success, setSuccess] = useState<boolean>(false);
const config = useGetStartupConfig();
const [requestError, setRequestError] = useState<boolean>(false);
const [resetLink, setResetLink] = useState<string>('');
const [resetLink, setResetLink] = useState<string | undefined>(undefined);
const [headerText, setHeaderText] = useState<string>('');
const [bodyText, setBodyText] = useState<React.ReactNode | undefined>(undefined);
const onSubmit = (data: TRequestPasswordReset) => {
requestPasswordReset.mutate(data, {
onSuccess: (data: TRequestPasswordResetResponse) => {
setSuccess(true);
setResetLink(data.link);
console.log('emailEnabled: ', config.data?.emailEnabled);
if (!config.data?.emailEnabled) {
setResetLink(data.link);
}
},
onError: () => {
setRequestError(true);
@@ -36,25 +41,33 @@ function RequestPasswordReset() {
});
};
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-white pt-6 sm:pt-0">
<div className="mt-6 w-96 overflow-hidden bg-white px-6 py-4 sm:max-w-md sm:rounded-lg">
<h1 className="mb-4 text-center text-3xl font-semibold">
{localize(lang, 'com_auth_reset_password')}
</h1>
{success && (
<div
className="relative mt-4 rounded border border-green-400 bg-green-100 px-4 py-3 text-green-700"
role="alert"
>
useEffect(() => {
if (requestPasswordReset.isSuccess) {
if (config.data?.emailEnabled) {
setHeaderText(localize(lang, 'com_auth_reset_password_link_sent'));
setBodyText(localize(lang, 'com_auth_reset_password_email_sent'));
} else {
setHeaderText(localize(lang, 'com_auth_reset_password'));
setBodyText(
<span>
{localize(lang, 'com_auth_click')}{' '}
<a className="text-green-600 hover:underline" href={resetLink}>
{localize(lang, 'com_auth_here')}
</a>{' '}
{localize(lang, 'com_auth_to_reset_your_password')}
{/* An email has been sent with instructions on how to reset your password. */}
</div>
)}
</span>,
);
}
} else {
setHeaderText(localize(lang, 'com_auth_reset_password'));
setBodyText(undefined);
}
}, [requestPasswordReset.isSuccess, config.data?.emailEnabled, resetLink, lang]);
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-white pt-6 sm:pt-0">
<div className="mt-6 w-96 overflow-hidden bg-white px-6 py-4 sm:max-w-md sm:rounded-lg">
<h1 className="mb-4 text-center text-3xl font-semibold">{headerText}</h1>
{requestError && (
<div
className="relative mt-4 rounded border border-red-400 bg-red-100 px-4 py-3 text-red-700"
@@ -63,62 +76,71 @@ function RequestPasswordReset() {
{localize(lang, 'com_auth_error_reset_password')}
</div>
)}
<form
className="mt-6"
aria-label="Password reset form"
method="POST"
onSubmit={handleSubmit(onSubmit)}
>
<div className="mb-2">
<div className="relative">
<input
type="email"
id="email"
autoComplete="off"
aria-label={localize(lang, 'com_auth_email')}
{...register('email', {
required: localize(lang, 'com_auth_email_required'),
minLength: {
value: 3,
message: localize(lang, 'com_auth_email_min_length'),
},
maxLength: {
value: 120,
message: localize(lang, 'com_auth_email_max_length'),
},
pattern: {
value: /\S+@\S+\.\S+/,
message: localize(lang, 'com_auth_email_pattern'),
},
})}
aria-invalid={!!errors.email}
className="peer block w-full appearance-none rounded-t-md border-0 border-b-2 border-gray-300 bg-gray-50 px-2.5 pb-2.5 pt-5 text-sm text-gray-900 focus:border-green-500 focus:outline-none focus:ring-0"
placeholder=" "
></input>
<label
htmlFor="email"
className="absolute left-2.5 top-4 z-10 origin-[0] -translate-y-4 scale-75 transform text-gray-500 duration-300 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:text-green-500"
>
{localize(lang, 'com_auth_email_address')}
</label>
{bodyText ? (
<div
className="relative mt-4 rounded border border-green-400 bg-green-100 px-4 py-3 text-green-700"
role="alert"
>
{bodyText}
</div>
) : (
<form
className="mt-6"
aria-label="Password reset form"
method="POST"
onSubmit={handleSubmit(onSubmit)}
>
<div className="mb-2">
<div className="relative">
<input
type="email"
id="email"
autoComplete="off"
aria-label={localize(lang, 'com_auth_email')}
{...register('email', {
required: localize(lang, 'com_auth_email_required'),
minLength: {
value: 3,
message: localize(lang, 'com_auth_email_min_length'),
},
maxLength: {
value: 120,
message: localize(lang, 'com_auth_email_max_length'),
},
pattern: {
value: /\S+@\S+\.\S+/,
message: localize(lang, 'com_auth_email_pattern'),
},
})}
aria-invalid={!!errors.email}
className="peer block w-full appearance-none rounded-t-md border-0 border-b-2 border-gray-300 bg-gray-50 px-2.5 pb-2.5 pt-5 text-sm text-gray-900 focus:border-green-500 focus:outline-none focus:ring-0"
placeholder=" "
></input>
<label
htmlFor="email"
className="absolute left-2.5 top-4 z-10 origin-[0] -translate-y-4 scale-75 transform text-gray-500 duration-300 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:text-green-500"
>
{localize(lang, 'com_auth_email_address')}
</label>
</div>
{errors.email && (
<span role="alert" className="mt-1 text-sm text-red-600">
{/* @ts-ignore not sure why */}
{errors.email.message}
</span>
)}
</div>
{errors.email && (
<span role="alert" className="mt-1 text-sm text-red-600">
{/* @ts-ignore not sure why */}
{errors.email.message}
</span>
)}
</div>
<div className="mt-6">
<button
type="submit"
disabled={!!errors.email}
className="w-full rounded-sm border border-transparent bg-green-500 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-green-600 focus:outline-none active:bg-green-500"
>
{localize(lang, 'com_auth_continue')}
</button>
</div>
</form>
<div className="mt-6">
<button
type="submit"
disabled={!!errors.email}
className="w-full rounded-sm border border-transparent bg-green-500 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-green-600 focus:outline-none active:bg-green-500"
>
{localize(lang, 'com_auth_continue')}
</button>
</div>
</form>
)}
</div>
</div>
);

View File

@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { useResetPasswordMutation, TResetPassword } from '@librechat/data-provider';
import { useResetPasswordMutation, TResetPassword } from 'librechat-data-provider';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import store from '~/store';

View File

@@ -1,9 +1,9 @@
import { render, waitFor } from 'layout-test-utils';
import { render, waitFor } from 'test/layout-test-utils';
import userEvent from '@testing-library/user-event';
import Login from '../Login';
import * as mockDataProvider from '@librechat/data-provider';
import * as mockDataProvider from 'librechat-data-provider';
jest.mock('@librechat/data-provider');
jest.mock('librechat-data-provider');
const setup = ({
useGetUserQueryReturnValue = {

View File

@@ -1,4 +1,4 @@
import { render } from 'layout-test-utils';
import { render } from 'test/layout-test-utils';
import userEvent from '@testing-library/user-event';
import Login from '../LoginForm';

View File

@@ -1,9 +1,9 @@
import { render, waitFor } from 'layout-test-utils';
import { render, waitFor, screen } from 'test/layout-test-utils';
import userEvent from '@testing-library/user-event';
import Registration from '../Registration';
import * as mockDataProvider from '@librechat/data-provider';
import * as mockDataProvider from 'librechat-data-provider';
jest.mock('@librechat/data-provider');
jest.mock('librechat-data-provider');
const setup = ({
useGetUserQueryReturnValue = {
@@ -17,6 +17,7 @@ const setup = ({
mutate: jest.fn(),
data: {},
isSuccess: false,
error: null as Error | null,
},
useGetStartupCongfigReturnValue = {
isLoading: false,
@@ -76,30 +77,31 @@ test('renders registration form', () => {
);
});
test('calls registerUser.mutate on registration', async () => {
const mutate = jest.fn();
const { getByTestId, getByRole, history } = setup({
// @ts-ignore - we don't need all parameters of the QueryObserverResult
useLoginUserReturnValue: {
isLoading: false,
mutate: mutate,
isError: false,
isSuccess: true,
},
});
// test('calls registerUser.mutate on registration', async () => {
// const mutate = jest.fn();
// const { getByTestId, getByRole, history } = setup({
// // @ts-ignore - we don't need all parameters of the QueryObserverResult
// useLoginUserReturnValue: {
// isLoading: false,
// mutate: mutate,
// isError: false,
// isSuccess: true,
// },
// });
await userEvent.type(getByRole('textbox', { name: /Full name/i }), 'John Doe');
await userEvent.type(getByRole('textbox', { name: /Username/i }), 'johndoe');
await userEvent.type(getByRole('textbox', { name: /Email/i }), 'test@test.com');
await userEvent.type(getByTestId('password'), 'password');
await userEvent.type(getByTestId('confirm_password'), 'password');
await userEvent.click(getByRole('button', { name: /Submit registration/i }));
// await userEvent.type(getByRole('textbox', { name: /Full name/i }), 'John Doe');
// await userEvent.type(getByRole('textbox', { name: /Username/i }), 'johndoe');
// await userEvent.type(getByRole('textbox', { name: /Email/i }), 'test@test.com');
// await userEvent.type(getByTestId('password'), 'password');
// await userEvent.type(getByTestId('confirm_password'), 'password');
// await userEvent.click(getByRole('button', { name: /Submit registration/i }));
waitFor(() => {
expect(mutate).toHaveBeenCalled();
expect(history.location.pathname).toBe('/chat/new');
});
});
// console.log(history);
// waitFor(() => {
// // expect(mutate).toHaveBeenCalled();
// expect(history.location.pathname).toBe('/chat/new');
// });
// });
test('shows validation error messages', async () => {
const { getByTestId, getAllByRole, getByRole } = setup();
@@ -123,7 +125,7 @@ test('shows error message when registration fails', async () => {
useRegisterUserMutationReturnValue: {
isLoading: false,
isError: true,
mutate: mutate,
mutate,
error: new Error('Registration failed'),
data: {},
isSuccess: false,
@@ -138,8 +140,8 @@ test('shows error message when registration fails', async () => {
await userEvent.click(getByRole('button', { name: /Submit registration/i }));
waitFor(() => {
expect(screen.getByRole('alert')).toBeInTheDocument();
expect(screen.getByRole('alert')).toHaveTextContent(
expect(screen.getByTestId('registration-error')).toBeInTheDocument();
expect(screen.getByTestId('registration-error')).toHaveTextContent(
/There was an error attempting to register your account. Please try again. Registration failed/i,
);
});

View File

@@ -1,6 +1,6 @@
import { useState, useRef, useEffect } from 'react';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { useUpdateConversationMutation } from '@librechat/data-provider';
import { useUpdateConversationMutation } from 'librechat-data-provider';
import RenameButton from './RenameButton';
import DeleteButton from './DeleteButton';
import ConvoIcon from '../svg/ConvoIcon';

View File

@@ -1,11 +1,18 @@
import Conversation from './Conversation';
import { TConversation } from 'librechat-data-provider';
export default function Conversations({ conversations, moveToTop }) {
export default function Conversations({
conversations,
moveToTop,
}: {
conversations: TConversation[];
moveToTop: () => void;
}) {
return (
<>
{conversations &&
conversations.length > 0 &&
conversations.map((convo) => {
conversations.map((convo: TConversation) => {
return (
<Conversation key={convo.conversationId} conversation={convo} retainView={moveToTop} />
);

View File

@@ -2,7 +2,7 @@ import { useEffect } from 'react';
import TrashIcon from '../svg/TrashIcon';
import CrossIcon from '../svg/CrossIcon';
import { useRecoilValue } from 'recoil';
import { useDeleteConversationMutation } from '@librechat/data-provider';
import { useDeleteConversationMutation } from 'librechat-data-provider';
import store from '~/store';

View File

@@ -1,10 +1,29 @@
import React from 'react';
export default function Pages({ pageNumber, pages, nextPage, previousPage }) {
const clickHandler = (func) => async (e) => {
e.preventDefault();
await func();
};
type TPagesProps = {
pages: number;
pageNumber: number;
setPageNumber: (pageNumber: number) => void;
nextPage: () => Promise<void>;
previousPage: () => Promise<void>;
};
export default function Pages({
pageNumber,
pages,
nextPage,
previousPage,
setPageNumber,
}: TPagesProps) {
const clickHandler =
(func: () => Promise<void>) => async (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
await func();
};
if (pageNumber > pages) {
setPageNumber(pages);
}
return pageNumber == 1 && pages == 1 ? null : (
<div className="m-auto mb-2 mt-4 flex items-center justify-center gap-2">

View File

@@ -0,0 +1,5 @@
export { default as Pages } from './Pages';
export { default as Conversation } from './Conversation';
export { default as DeleteButton } from './DeleteButton';
export { default as RenameButton } from './RenameButton';
export { default as Conversations } from './Conversations';

View File

@@ -1,24 +0,0 @@
import React from 'react';
import { HoverCardPortal, HoverCardContent } from '~/components/ui/HoverCard.tsx';
const types = {
temp: 'Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and closer to 1 for creative and generative tasks. We recommend altering this or Top P but not both.',
topp: 'Top-p changes how the model selects tokens for output. Tokens are selected from most K (see topK parameter) probable to least until the sum of their probabilities equals the top-p value.',
topk: 'Top-k changes how the model selects tokens for output. A top-k of 1 means the selected token is the most probable among all tokens in the model\'s vocabulary (also called greedy decoding), while a top-k of 3 means that the next token is selected from among the 3 most probable tokens (using temperature).',
maxoutputtokens:
' Maximum number of tokens that can be generated in the response. Specify a lower value for shorter responses and a higher value for longer responses.',
};
function OptionHover({ type, side }) {
return (
<HoverCardPortal>
<HoverCardContent side={side} className="w-80 ">
<div className="space-y-2">
<p className="text-sm text-gray-600 dark:text-gray-300">{types[type]}</p>
</div>
</HoverCardContent>
</HoverCardPortal>
);
}
export default OptionHover;

View File

@@ -1,251 +0,0 @@
import React from 'react';
import { useRecoilValue } from 'recoil';
import TextareaAutosize from 'react-textarea-autosize';
import SelectDropDown from '../../ui/SelectDropDown';
import { Input } from '~/components/ui/Input.tsx';
import { Label } from '~/components/ui/Label.tsx';
import { Slider } from '~/components/ui/Slider.tsx';
import { InputNumber } from '~/components/ui/InputNumber.tsx';
import OptionHover from './OptionHover';
import { HoverCard, HoverCardTrigger } from '~/components/ui/HoverCard.tsx';
import { cn } from '~/utils/';
const defaultTextProps =
'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0';
const optionText =
'p-0 shadow-none text-right pr-1 h-8 border-transparent focus:ring-[#10a37f] focus:ring-offset-0 focus:ring-opacity-100 hover:bg-gray-800/10 dark:hover:bg-white/10 focus:bg-gray-800/10 dark:focus:bg-white/10 transition-colors';
import store from '~/store';
function Settings(props) {
const {
readonly,
model,
modelLabel,
promptPrefix,
temperature,
topP,
topK,
maxOutputTokens,
setOption,
} = props;
const endpointsConfig = useRecoilValue(store.endpointsConfig);
const setModel = setOption('model');
const setModelLabel = setOption('modelLabel');
const setPromptPrefix = setOption('promptPrefix');
const setTemperature = setOption('temperature');
const setTopP = setOption('topP');
const setTopK = setOption('topK');
const setMaxOutputTokens = setOption('maxOutputTokens');
const models = endpointsConfig?.['anthropic']?.['availableModels'] || [];
return (
<div className={'h-[490px] overflow-y-auto md:h-[350px]'}>
<div className="grid gap-6 sm:grid-cols-2">
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<div className="grid w-full items-center gap-2">
<SelectDropDown
value={model}
setValue={setModel}
availableValues={models}
disabled={readonly}
className={cn(
defaultTextProps,
'z-50 flex w-full resize-none focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
containerClassName="flex w-full resize-none"
/>
</div>
<div className="grid w-full items-center gap-2">
<Label htmlFor="modelLabel" className="text-left text-sm font-medium">
Custom Name <small className="opacity-40">(default: blank)</small>
</Label>
<Input
id="modelLabel"
disabled={readonly}
value={modelLabel || ''}
onChange={(e) => setModelLabel(e.target.value || null)}
placeholder="Set a custom name for Claude"
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none px-3 py-2 focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
/>
</div>
<div className="grid w-full items-center gap-2">
<Label htmlFor="promptPrefix" className="text-left text-sm font-medium">
Prompt Prefix <small className="opacity-40">(default: blank)</small>
</Label>
<TextareaAutosize
id="promptPrefix"
disabled={readonly}
value={promptPrefix || ''}
onChange={(e) => setPromptPrefix(e.target.value || null)}
placeholder="Set custom instructions or context. Ignored if empty."
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2 ',
)}
/>
</div>
</div>
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="temp-int" className="text-left text-sm font-medium">
Temperature <small className="opacity-40">(default: 0.7)</small>
</Label>
<InputNumber
id="temp-int"
disabled={readonly}
value={temperature}
onChange={(value) => setTemperature(value)}
max={1}
min={0}
step={0.01}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[temperature]}
onValueChange={(value) => setTemperature(value[0])}
doubleClickHandler={() => setTemperature(1)}
max={1}
min={0}
step={0.01}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="temp" side="left" />
</HoverCard>
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="top-p-int" className="text-left text-sm font-medium">
Top P <small className="opacity-40">(default: 0.95)</small>
</Label>
<InputNumber
id="top-p-int"
disabled={readonly}
value={topP}
onChange={(value) => setTopP(value)}
max={1}
min={0}
step={0.01}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[topP]}
onValueChange={(value) => setTopP(value[0])}
doubleClickHandler={() => setTopP(1)}
max={1}
min={0}
step={0.01}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="topp" side="left" />
</HoverCard>
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="top-k-int" className="text-left text-sm font-medium">
Top K <small className="opacity-40">(default: 40)</small>
</Label>
<InputNumber
id="top-k-int"
disabled={readonly}
value={topK}
onChange={(value) => setTopK(value)}
max={40}
min={1}
step={0.01}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[topK]}
onValueChange={(value) => setTopK(value[0])}
doubleClickHandler={() => setTopK(0)}
max={40}
min={1}
step={0.01}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="topk" side="left" />
</HoverCard>
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="max-tokens-int" className="text-left text-sm font-medium">
Max Output Tokens <small className="opacity-40">(default: 1024)</small>
</Label>
<InputNumber
id="max-tokens-int"
disabled={readonly}
value={maxOutputTokens}
onChange={(value) => setMaxOutputTokens(value)}
max={1024}
min={1}
step={1}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[maxOutputTokens]}
onValueChange={(value) => setMaxOutputTokens(value[0])}
doubleClickHandler={() => setMaxOutputTokens(0)}
max={1024}
min={1}
step={1}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="maxoutputtokens" side="left" />
</HoverCard>
</div>
</div>
</div>
);
}
export default Settings;

View File

@@ -1,143 +0,0 @@
import { useEffect, useState } from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { Label } from '~/components/ui/Label.tsx';
import { Checkbox } from '~/components/ui/Checkbox.tsx';
import SelectDropDown from '../../ui/SelectDropDown';
import { cn } from '~/utils/';
import useDebounce from '~/hooks/useDebounce';
import { useUpdateTokenCountMutation } from '@librechat/data-provider';
const defaultTextProps =
'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0';
function Settings(props) {
const { readonly, context, systemMessage, jailbreak, toneStyle, setOption } = props;
const [tokenCount, setTokenCount] = useState(0);
const showSystemMessage = jailbreak;
const setContext = setOption('context');
const setSystemMessage = setOption('systemMessage');
const setJailbreak = setOption('jailbreak');
const setToneStyle = (value) => setOption('toneStyle')(value.toLowerCase());
const debouncedContext = useDebounce(context, 250);
const updateTokenCountMutation = useUpdateTokenCountMutation();
useEffect(() => {
if (!debouncedContext || debouncedContext.trim() === '') {
setTokenCount(0);
return;
}
const handleTextChange = (context) => {
updateTokenCountMutation.mutate(
{ text: context },
{
onSuccess: (data) => {
setTokenCount(data.count);
},
},
);
};
handleTextChange(debouncedContext);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedContext]);
return (
<div className="h-[490px] overflow-y-auto md:h-[350px]">
<div className="grid gap-6 sm:grid-cols-2">
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<div className="grid w-full items-center gap-2">
<Label htmlFor="toneStyle-dropdown" className="text-left text-sm font-medium">
Tone Style <small className="opacity-40">(default: creative)</small>
</Label>
<SelectDropDown
id="toneStyle-dropdown"
title={null}
value={`${toneStyle.charAt(0).toUpperCase()}${toneStyle.slice(1)}`}
setValue={setToneStyle}
availableValues={['Creative', 'Fast', 'Balanced', 'Precise']}
disabled={readonly}
className={cn(
defaultTextProps,
'flex w-full resize-none focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
containerClassName="flex w-full resize-none"
/>
</div>
<div className="grid w-full items-center gap-2">
<Label htmlFor="context" className="text-left text-sm font-medium">
Context <small className="opacity-40">(default: blank)</small>
</Label>
<TextareaAutosize
id="context"
disabled={readonly}
value={context || ''}
onChange={(e) => setContext(e.target.value || null)}
placeholder="Bing can use up to 7k tokens for 'context', which it can reference for the conversation. The specific limit is not known but may run into errors exceeding 7k tokens"
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2',
)}
/>
<small className="mb-5 text-black dark:text-white">{`Token count: ${tokenCount}`}</small>
</div>
</div>
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<div className="grid w-full items-center gap-2">
<Label htmlFor="jailbreak" className="text-left text-sm font-medium">
Enable Sydney <small className="opacity-40">(default: false)</small>
</Label>
<div className="flex h-[40px] w-full items-center space-x-3">
<Checkbox
id="jailbreak"
disabled={readonly}
checked={jailbreak}
className="focus:ring-opacity-20 dark:border-gray-500 dark:bg-gray-700 dark:text-gray-50 dark:focus:ring-gray-600 dark:focus:ring-opacity-50 dark:focus:ring-offset-0"
onCheckedChange={setJailbreak}
/>
<label
htmlFor="jailbreak"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 dark:text-gray-50"
>
Jailbreak <small>To enable Sydney</small>
</label>
</div>
</div>
{showSystemMessage && (
<div className="grid w-full items-center gap-2">
<Label
htmlFor="systemMessage"
className="text-left text-sm font-medium"
style={{ opacity: showSystemMessage ? '1' : '0' }}
>
<a
href="https://github.com/danny-avila/LibreChat/blob/main/client/defaultSystemMessage.md"
target="_blank"
className="text-blue-500 transition-colors duration-200 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-500"
rel="noreferrer"
>
System Message
</a>{' '}
<small className="opacity-40 dark:text-gray-50">(default: blank)</small>
</Label>
<TextareaAutosize
id="systemMessage"
disabled={readonly}
value={systemMessage || ''}
onChange={(e) => setSystemMessage(e.target.value || null)}
placeholder="WARNING: Misuse of this feature can get you BANNED from using Bing! Click on 'System Message' for full instructions and the default message if omitted, which is the 'Sydney' preset that is considered safe."
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2 placeholder:text-red-400',
)}
/>
</div>
)}
</div>
</div>
</div>
);
}
export default Settings;

View File

@@ -1,280 +0,0 @@
import axios from 'axios';
import { useEffect, useState } from 'react';
import Settings from './Settings';
import Examples from './Google/Examples.jsx';
import exportFromJSON from 'export-from-json';
import AgentSettings from './Plugins/AgentSettings.jsx';
import { useSetRecoilState, useRecoilValue } from 'recoil';
import filenamify from 'filenamify';
import {
MessagesSquared,
GPTIcon,
Input,
Label,
Button,
Dropdown,
Dialog,
DialogClose,
DialogButton,
DialogTemplate,
} from '~/components/';
import { cn } from '~/utils/';
import cleanupPreset from '~/utils/cleanupPreset';
import store from '~/store';
const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => {
const [preset, setPreset] = useState(_preset);
const setPresets = useSetRecoilState(store.presets);
const [showExamples, setShowExamples] = useState(false);
const [showAgentSettings, setShowAgentSettings] = useState(false);
const availableEndpoints = useRecoilValue(store.availableEndpoints);
const endpointsConfig = useRecoilValue(store.endpointsConfig);
const triggerExamples = () => setShowExamples((prev) => !prev);
const triggerAgentSettings = () => setShowAgentSettings((prev) => !prev);
const setOption = (param) => (newValue) => {
let update = {};
update[param] = newValue;
setPreset((prevState) =>
cleanupPreset({
preset: {
...prevState,
...update,
},
endpointsConfig,
}),
);
};
const setAgentOption = (param) => (newValue) => {
let editablePreset = JSON.stringify(_preset);
editablePreset = JSON.parse(editablePreset);
let { agentOptions } = editablePreset;
agentOptions[param] = newValue;
setPreset((prevState) =>
cleanupPreset({
preset: {
...prevState,
agentOptions,
},
endpointsConfig,
}),
);
};
const setExample = (i, type, newValue = null) => {
let update = {};
let current = preset?.examples.slice() || [];
let currentExample = { ...current[i] } || {};
currentExample[type] = { content: newValue };
current[i] = currentExample;
update.examples = current;
setPreset((prevState) =>
cleanupPreset({
preset: {
...prevState,
...update,
},
endpointsConfig,
}),
);
};
const addExample = () => {
let update = {};
let current = preset?.examples.slice() || [];
current.push({ input: { content: '' }, output: { content: '' } });
update.examples = current;
setPreset((prevState) =>
cleanupPreset({
preset: {
...prevState,
...update,
},
endpointsConfig,
}),
);
};
const removeExample = () => {
let update = {};
let current = preset?.examples.slice() || [];
if (current.length <= 1) {
update.examples = [{ input: { content: '' }, output: { content: '' } }];
setPreset((prevState) =>
cleanupPreset({
preset: {
...prevState,
...update,
},
endpointsConfig,
}),
);
return;
}
current.pop();
update.examples = current;
setPreset((prevState) =>
cleanupPreset({
preset: {
...prevState,
...update,
},
endpointsConfig,
}),
);
};
const defaultTextProps =
'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0';
const submitPreset = () => {
axios({
method: 'post',
url: '/api/presets',
data: cleanupPreset({ preset, endpointsConfig }),
withCredentials: true,
}).then((res) => {
setPresets(res?.data);
});
};
const exportPreset = () => {
const fileName = filenamify(preset?.title || 'preset');
exportFromJSON({
data: cleanupPreset({ preset, endpointsConfig }),
fileName,
exportType: exportFromJSON.types.json,
});
};
useEffect(() => {
setPreset(_preset);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
const endpoint = preset?.endpoint;
const isGoogle = endpoint === 'google';
const isGptPlugins = endpoint === 'gptPlugins';
const shouldShowSettings =
(isGoogle && !showExamples) ||
(isGptPlugins && !showAgentSettings) ||
(!isGoogle && !isGptPlugins);
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTemplate
title={`${title || 'Edit Preset'} - ${preset?.title}`}
className="h-[675px] max-w-full sm:max-w-4xl "
main={
<div className="flex w-full flex-col items-center gap-2 md:h-[475px]">
<div className="grid w-full gap-6 sm:grid-cols-2">
<div className="col-span-1 flex flex-col items-start justify-start gap-2">
<Label htmlFor="chatGptLabel" className="text-left text-sm font-medium">
Preset Name
</Label>
<Input
id="chatGptLabel"
value={preset?.title || ''}
onChange={(e) => setOption('title')(e.target.value || '')}
placeholder="Set a custom name, in case you can find this preset"
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none px-3 py-2 focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
/>
</div>
<div className="col-span-1 flex flex-col items-start justify-start gap-2">
<Label htmlFor="endpoint" className="text-left text-sm font-medium">
Endpoint
</Label>
<Dropdown
id="endpoint"
value={preset?.endpoint || ''}
onChange={setOption('endpoint')}
options={availableEndpoints}
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
containerClassName="flex w-full resize-none"
/>
{preset?.endpoint === 'google' && (
<Button
type="button"
className="ml-1 flex h-auto w-full bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 focus:ring-offset-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
onClick={triggerExamples}
>
<MessagesSquared className="mr-1 w-[14px]" />
{(showExamples ? 'Hide' : 'Show') + ' Examples'}
</Button>
)}
{preset?.endpoint === 'gptPlugins' && (
<Button
type="button"
className="ml-1 flex h-auto w-full bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 focus:ring-offset-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
onClick={triggerAgentSettings}
>
<GPTIcon className="mr-1 mt-[2px] w-[14px]" size={14} />
{`Show ${showAgentSettings ? 'Completion' : 'Agent'} Settings`}
</Button>
)}
</div>
</div>
<div className="my-4 w-full border-t border-gray-300 dark:border-gray-500" />
<div className="w-full p-0">
{shouldShowSettings && <Settings preset={preset} setOption={setOption} />}
{preset?.endpoint === 'google' &&
showExamples &&
!preset?.model?.startsWith('codechat-') && (
<Examples
examples={preset.examples}
setExample={setExample}
addExample={addExample}
removeExample={removeExample}
edit={true}
/>
)}
{preset?.endpoint === 'gptPlugins' && showAgentSettings && (
<AgentSettings
agent={preset.agentOptions.agent}
skipCompletion={preset.agentOptions.skipCompletion}
model={preset.agentOptions.model}
endpoint={preset.agentOptions.endpoint}
temperature={preset.agentOptions.temperature}
topP={preset.agentOptions.top_p}
freqP={preset.agentOptions.presence_penalty}
presP={preset.agentOptions.frequency_penalty}
setOption={setAgentOption}
tools={preset.tools}
/>
)}
</div>
</div>
}
buttons={
<>
<DialogClose
onClick={submitPreset}
className="dark:hover:gray-400 border-gray-700 bg-green-600 text-white hover:bg-green-700 dark:hover:bg-green-800"
>
Save
</DialogClose>
</>
}
leftButtons={
<>
<DialogButton onClick={exportPreset} className="dark:hover:gray-400 border-gray-700">
Export
</DialogButton>
</>
}
/>
</Dialog>
);
};
export default EditPresetDialog;

View File

@@ -0,0 +1,146 @@
import axios from 'axios';
import { useEffect } from 'react';
import filenamify from 'filenamify';
import exportFromJSON from 'export-from-json';
import { useSetRecoilState, useRecoilState, useRecoilValue } from 'recoil';
import { TEditPresetProps } from '~/common';
import { useSetOptions, useLocalize } from '~/hooks';
import { Input, Label, Dropdown, Dialog, DialogClose, DialogButton } from '~/components/';
import DialogTemplate from '~/components/ui/DialogTemplate';
import PopoverButtons from './PopoverButtons';
import EndpointSettings from './EndpointSettings';
import { cn, defaultTextProps, removeFocusOutlines, cleanupPreset } from '~/utils/';
import store from '~/store';
const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }: TEditPresetProps) => {
const [preset, setPreset] = useRecoilState(store.preset);
const setPresets = useSetRecoilState(store.presets);
const availableEndpoints = useRecoilValue(store.availableEndpoints);
const endpointsConfig = useRecoilValue(store.endpointsConfig);
const { setOption } = useSetOptions(_preset);
const localize = useLocalize();
const submitPreset = () => {
if (!preset) {
return;
}
axios({
method: 'post',
url: '/api/presets',
data: cleanupPreset({ preset, endpointsConfig }),
withCredentials: true,
}).then((res) => {
setPresets(res?.data);
});
};
const exportPreset = () => {
if (!preset) {
return;
}
const fileName = filenamify(preset?.title || 'preset');
exportFromJSON({
data: cleanupPreset({ preset, endpointsConfig }),
fileName,
exportType: exportFromJSON.types.json,
});
};
useEffect(() => {
setPreset(_preset);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
const { endpoint } = preset || {};
if (!endpoint) {
return null;
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTemplate
title={`${title || localize('com_endpoint_edit_preset')} - ${preset?.title}`}
className="h-full max-w-full overflow-y-auto pb-4 sm:w-[680px] sm:pb-0 md:h-[720px] md:w-[750px] md:overflow-y-hidden lg:w-[950px] xl:h-[720px]"
main={
<div className="flex w-full flex-col items-center gap-2 md:h-[530px]">
<div className="grid w-full grid-cols-5 gap-6">
<div className="col-span-4 flex items-start justify-start gap-4">
<div className="flex w-full flex-col">
<Label htmlFor="preset-name" className="mb-1 text-left text-sm font-medium">
{localize('com_endpoint_preset_name')}
</Label>
<Input
id="preset-name"
value={preset?.title || ''}
onChange={(e) => setOption('title')(e.target.value || '')}
placeholder={localize('com_endpoint_set_custom_name')}
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none px-3 py-2',
removeFocusOutlines,
)}
/>
</div>
<div className="flex w-full flex-col">
<Label htmlFor="endpoint" className="mb-1 text-left text-sm font-medium">
{localize('com_endpoint')}
</Label>
<Dropdown
value={endpoint || ''}
onChange={setOption('endpoint')}
options={availableEndpoints}
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none ',
removeFocusOutlines,
)}
containerClassName="flex w-full resize-none z-[51]"
/>
</div>
</div>
<div className="col-span-2 flex items-start justify-start gap-4 sm:col-span-1">
<div className="flex w-full flex-col">
<Label
htmlFor="endpoint"
className="mb-1 hidden text-left text-sm font-medium sm:block"
>
{''}
</Label>
<PopoverButtons
endpoint={endpoint}
buttonClass="ml-0 w-full dark:bg-gray-700 dark:hover:bg-gray-800 p-2 h-[40px] justify-center mt-0"
iconClass="hidden lg:block w-4"
/>
</div>
</div>
</div>
<div className="my-4 w-full border-t border-gray-300 dark:border-gray-500" />
<div className="w-full p-0">
<EndpointSettings
conversation={preset}
setOption={setOption}
isPreset={true}
className="h-full md:mb-4 md:h-[440px]"
/>
</div>
</div>
}
buttons={
<div className="mb-6 md:mb-2">
<DialogButton onClick={exportPreset} className="dark:hover:gray-400 border-gray-700">
{localize('com_endpoint_export')}
</DialogButton>
<DialogClose
onClick={submitPreset}
className="dark:hover:gray-400 ml-2 border-gray-700 bg-green-600 text-white hover:bg-green-700 dark:hover:bg-green-800"
>
{localize('com_endpoint_save')}
</DialogClose>
</div>
}
/>
</Dialog>
);
};
export default EditPresetDialog;

View File

@@ -1,86 +0,0 @@
import exportFromJSON from 'export-from-json';
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { Dialog, DialogButton, DialogTemplate } from '~/components';
import SaveAsPresetDialog from './SaveAsPresetDialog';
import cleanupPreset from '~/utils/cleanupPreset';
import { alternateName } from '~/utils';
import Settings from './Settings';
import store from '~/store';
// A preset dialog to show readonly preset values.
const EndpointOptionsDialog = ({ open, onOpenChange, preset: _preset, title }) => {
const [preset, setPreset] = useState(_preset);
const [saveAsDialogShow, setSaveAsDialogShow] = useState(false);
const endpointsConfig = useRecoilValue(store.endpointsConfig);
const endpointName = alternateName[preset?.endpoint] ?? 'Endpoint';
const setOption = (param) => (newValue) => {
let update = {};
update[param] = newValue;
setPreset((prevState) => ({
...prevState,
...update,
}));
};
const saveAsPreset = () => {
setSaveAsDialogShow(true);
};
const exportPreset = () => {
exportFromJSON({
data: cleanupPreset({ preset, endpointsConfig }),
fileName: `${preset?.title}.json`,
exportType: exportFromJSON.types.json,
});
};
useEffect(() => {
setPreset(_preset);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTemplate
title={`${title || 'View Options'} - ${endpointName}`}
className="max-w-full sm:max-w-4xl"
main={
<div className="flex w-full flex-col items-center gap-2">
<div className="w-full p-0">
<Settings preset={preset} readonly={true} setOption={setOption} />
</div>
</div>
}
buttons={
<>
<DialogButton
onClick={saveAsPreset}
className="dark:hover:gray-400 border-gray-700 bg-green-600 text-white hover:bg-green-700 dark:hover:bg-green-800"
>
Save As Preset
</DialogButton>
</>
}
leftButtons={
<>
<DialogButton onClick={exportPreset} className="dark:hover:gray-400 border-gray-700">
Export
</DialogButton>
</>
}
/>
</Dialog>
<SaveAsPresetDialog
open={saveAsDialogShow}
onOpenChange={setSaveAsDialogShow}
preset={preset}
/>
</>
);
};
export default EndpointOptionsDialog;

View File

@@ -0,0 +1,114 @@
import exportFromJSON from 'export-from-json';
import { useEffect, useState } from 'react';
import { useRecoilValue, useRecoilState } from 'recoil';
import { tPresetSchema } from 'librechat-data-provider';
import type { TSetOption, TEditPresetProps } from '~/common';
import { Dialog, DialogButton } from '~/components/ui';
import DialogTemplate from '~/components/ui/DialogTemplate';
import SaveAsPresetDialog from './SaveAsPresetDialog';
import EndpointSettings from './EndpointSettings';
import PopoverButtons from './PopoverButtons';
import { cleanupPreset } from '~/utils';
import { useLocalize } from '~/hooks';
import store from '~/store';
// A preset dialog to show readonly preset values.
const EndpointOptionsDialog = ({
open,
onOpenChange,
preset: _preset,
title,
}: TEditPresetProps) => {
const [preset, setPreset] = useRecoilState(store.preset);
const [saveAsDialogShow, setSaveAsDialogShow] = useState(false);
const endpointsConfig = useRecoilValue(store.endpointsConfig);
const localize = useLocalize();
const setOption: TSetOption = (param) => (newValue) => {
const update = {};
update[param] = newValue;
setPreset((prevState) =>
tPresetSchema.parse({
...prevState,
...update,
}),
);
};
const saveAsPreset = () => {
setSaveAsDialogShow(true);
};
const exportPreset = () => {
if (!preset) {
return;
}
exportFromJSON({
data: cleanupPreset({ preset, endpointsConfig }),
fileName: `${preset?.title}.json`,
exportType: exportFromJSON.types.json,
});
};
useEffect(() => {
setPreset(_preset);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
const { endpoint } = preset ?? {};
if (!endpoint) {
return null;
}
if (!preset) {
return null;
}
return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTemplate
title={`${title || localize('com_endpoint_save_convo_as_preset')}`}
className="h-full max-w-full overflow-y-auto pb-4 sm:w-[680px] sm:pb-0 md:h-[680px] md:w-[750px] md:overflow-y-hidden lg:w-[950px]"
// headerClassName="sm:p-2 h-16"
main={
<div className="flex w-full flex-col items-center gap-2 md:h-[530px]">
<div className="w-full p-0">
<PopoverButtons
endpoint={endpoint}
buttonClass="ml-0 mb-4 col-span-2 dark:bg-gray-700 dark:hover:bg-gray-800 p-2"
/>
<EndpointSettings
conversation={preset}
setOption={setOption}
isPreset={true}
className="h-full md:mb-0 md:h-[490px]"
/>
</div>
</div>
}
buttons={
<div className="mb-6 md:mb-2">
<DialogButton onClick={exportPreset} className="dark:hover:gray-400 border-gray-700">
{localize('com_endpoint_export')}
</DialogButton>
<DialogButton
onClick={saveAsPreset}
className="dark:hover:gray-400 ml-2 border-gray-700 bg-green-600 text-white hover:bg-green-700 dark:hover:bg-green-800"
>
{localize('com_endpoint_save_as_preset')}
</DialogButton>
</div>
}
/>
</Dialog>
<SaveAsPresetDialog
open={saveAsDialogShow}
onOpenChange={setSaveAsDialogShow}
preset={preset}
/>
</>
);
};
export default EndpointOptionsDialog;

View File

@@ -1,71 +0,0 @@
import React from 'react';
import { Button } from '../ui/Button.tsx';
import CrossIcon from '../svg/CrossIcon';
// import SaveIcon from '../svg/SaveIcon';
import { Save } from 'lucide-react';
import { cn } from '~/utils/';
function EndpointOptionsPopover({
content,
visible,
saveAsPreset,
switchToSimpleMode,
additionalButton = null,
}) {
const cardStyle =
'shadow-md rounded-md min-w-[75px] font-normal bg-white border-black/10 border dark:bg-gray-700 text-black dark:text-white';
return (
<>
<div
className={
' endpointOptionsPopover-container absolute bottom-[-10px] z-0 flex w-full flex-col items-center md:px-4' +
(visible ? ' show' : '')
}
>
<div
className={
cardStyle +
' border-d-0 flex w-full flex-col overflow-hidden rounded-none border-s-0 border-t bg-slate-200 px-0 pb-[10px] dark:border-white/10 md:rounded-md md:border lg:w-[736px]'
}
>
<div className="flex w-full items-center bg-slate-100 px-2 py-2 dark:bg-gray-800/60">
{/* <span className="text-xs font-medium font-normal">Advanced settings for OpenAI endpoint</span> */}
<Button
type="button"
className="h-auto justify-start bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
onClick={saveAsPreset}
>
<Save className="mr-1 w-[14px]" />
Save as preset
</Button>
{additionalButton && (
<Button
type="button"
className={cn(
additionalButton.buttonClass,
'ml-1 h-auto justify-start bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 focus:ring-offset-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0',
)}
onClick={additionalButton.handler}
>
{additionalButton.icon}
{additionalButton.label}
</Button>
)}
<Button
type="button"
className="ml-auto h-auto bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-offset-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white"
onClick={switchToSimpleMode}
>
<CrossIcon className="mr-1" />
{/* Switch to simple mode */}
</Button>
</div>
<div>{content}</div>
</div>
</div>
</>
);
}
export default EndpointOptionsPopover;

View File

@@ -0,0 +1,69 @@
import React from 'react';
import { Save } from 'lucide-react';
import { EModelEndpoint } from 'librechat-data-provider';
import { Button } from '~/components/ui';
import { CrossIcon } from '~/components/svg';
import PopoverButtons from './PopoverButtons';
import { cn, removeFocusOutlines } from '~/utils';
import { useLocalize } from '~/hooks';
type TEndpointOptionsPopoverProps = {
children: React.ReactNode;
visible: boolean;
endpoint: EModelEndpoint;
saveAsPreset: () => void;
closePopover: () => void;
};
export default function EndpointOptionsPopover({
children,
endpoint,
visible,
saveAsPreset,
closePopover,
}: TEndpointOptionsPopoverProps) {
const localize = useLocalize();
const cardStyle =
'shadow-xl rounded-md min-w-[75px] font-normal bg-white border-black/10 border dark:bg-gray-700 text-black dark:text-white';
return (
<>
<div
className={cn(
'endpointOptionsPopover-container absolute bottom-[-10px] z-0 flex w-full flex-col items-center md:px-4',
visible ? ' show' : '',
)}
>
<div
className={cn(
cardStyle,
'border-d-0 flex w-full flex-col overflow-hidden rounded-none border-s-0 border-t bg-white px-0 pb-[10px] dark:border-white/10 md:rounded-md md:border lg:w-[736px]',
)}
>
<div className="flex w-full items-center bg-slate-100 px-2 py-2 dark:bg-gray-800/60">
<Button
type="button"
className="h-auto justify-start bg-transparent px-2 py-1 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
onClick={saveAsPreset}
>
<Save className="mr-1 w-[14px]" />
{localize('com_endpoint_save_as_preset')}
</Button>
<PopoverButtons endpoint={endpoint} />
<Button
type="button"
className={cn(
'ml-auto h-auto bg-transparent px-3 py-2 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black dark:bg-transparent dark:text-white dark:hover:bg-gray-700 dark:hover:text-white',
removeFocusOutlines,
)}
onClick={closePopover}
>
<CrossIcon />
</Button>
</div>
<div>{children}</div>
</div>
</div>
</>
);
}

View File

@@ -0,0 +1,59 @@
import { useRecoilValue } from 'recoil';
import { OpenAISettings, BingAISettings, AnthropicSettings } from './Settings';
import { GoogleSettings, PluginsSettings } from './Settings/MultiView';
import type { TSettingsProps, TModelSelectProps, TBaseSettingsProps, TModels } from '~/common';
import { cn } from '~/utils';
import store from '~/store';
const optionComponents: { [key: string]: React.FC<TModelSelectProps> } = {
openAI: OpenAISettings,
azureOpenAI: OpenAISettings,
bingAI: BingAISettings,
anthropic: AnthropicSettings,
};
const multiViewComponents: { [key: string]: React.FC<TBaseSettingsProps & TModels> } = {
google: GoogleSettings,
gptPlugins: PluginsSettings,
};
export default function Settings({
conversation,
setOption,
isPreset = false,
className = '',
}: TSettingsProps) {
const endpointsConfig = useRecoilValue(store.endpointsConfig);
if (!conversation?.endpoint) {
return null;
}
const { endpoint } = conversation;
const models = endpointsConfig?.[endpoint]?.['availableModels'] || [];
const OptionComponent = optionComponents[endpoint];
if (OptionComponent) {
return (
<div className={cn('h-[480px] overflow-y-auto md:mb-2 md:h-[350px]', className)}>
<OptionComponent
conversation={conversation}
setOption={setOption}
models={models}
isPreset={isPreset}
/>
</div>
);
}
const MultiViewComponent = multiViewComponents[endpoint];
if (!MultiViewComponent) {
return null;
}
return (
<div className={cn('h-[480px] overflow-y-auto md:mb-2 md:h-[350px]', className)}>
<MultiViewComponent conversation={conversation} models={models} isPreset={isPreset} />
</div>
);
}

View File

@@ -1,89 +0,0 @@
import React from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { Button } from '~/components/ui/Button.tsx';
import { Label } from '~/components/ui/Label.tsx';
import { Plus, Minus } from 'lucide-react';
import { cn } from '~/utils/';
const defaultTextProps =
'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0';
function Examples({ readonly, examples, setExample, addExample, removeExample, edit = false }) {
const maxHeight = edit ? 'max-h-[233px]' : 'max-h-[350px]';
return (
<>
<div className={`${maxHeight} overflow-y-auto`}>
<div id="examples-grid" className="grid gap-6 sm:grid-cols-2">
{examples.map((example, idx) => (
<React.Fragment key={idx}>
{/* Input */}
<div
className={`col-span-${
examples.length === 1 ? '1' : 'full'
} flex flex-col items-center justify-start gap-6 sm:col-span-1`}
>
<div className="grid w-full items-center gap-2">
<Label htmlFor={`input-${idx}`} className="text-left text-sm font-medium">
Input <small className="opacity-40">(default: blank)</small>
</Label>
<TextareaAutosize
id={`input-${idx}`}
disabled={readonly}
value={example?.input?.content || ''}
onChange={(e) => setExample(idx, 'input', e.target.value || null)}
placeholder="Set example input. Example is ignored if empty."
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[75px] w-full resize-none px-3 py-2 ',
)}
/>
</div>
</div>
{/* Output */}
<div
className={`col-span-${
examples.length === 1 ? '1' : 'full'
} flex flex-col items-center justify-start gap-6 sm:col-span-1`}
>
<div className="grid w-full items-center gap-2">
<Label htmlFor={`output-${idx}`} className="text-left text-sm font-medium">
Output <small className="opacity-40">(default: blank)</small>
</Label>
<TextareaAutosize
id={`output-${idx}`}
disabled={readonly}
value={example?.output?.content || ''}
onChange={(e) => setExample(idx, 'output', e.target.value || null)}
placeholder={'Set example output. Example is ignored if empty.'}
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[75px] w-full resize-none px-3 py-2 ',
)}
/>
</div>
</div>
</React.Fragment>
))}
</div>
</div>
<div className="flex justify-center">
<Button
type="button"
className="mr-2 mt-1 h-auto items-center justify-center bg-transparent px-3 py-2 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 focus:ring-offset-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-600 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
onClick={removeExample}
>
<Minus className="w-[16px]" />
</Button>
<Button
type="button"
className="mt-1 h-auto items-center justify-center bg-transparent px-3 py-2 text-xs font-medium font-normal text-black hover:bg-slate-200 hover:text-black focus:ring-0 focus:ring-offset-0 dark:bg-transparent dark:text-white dark:hover:bg-gray-600 dark:hover:text-white dark:focus:outline-none dark:focus:ring-offset-0"
onClick={addExample}
>
<Plus className="w-[16px]" />
</Button>
</div>
</>
);
}
export default Examples;

View File

@@ -1,33 +0,0 @@
import React from 'react';
import { HoverCardPortal, HoverCardContent } from '~/components/ui/HoverCard.tsx';
const types = {
temp: 'Higher values = more random, while lower values = more focused and deterministic. We recommend altering this or Top P but not both.',
topp: 'Top-p changes how the model selects tokens for output. Tokens are selected from most K (see topK parameter) probable to least until the sum of their probabilities equals the top-p value.',
topk: 'Top-k changes how the model selects tokens for output. A top-k of 1 means the selected token is the most probable among all tokens in the model\'s vocabulary (also called greedy decoding), while a top-k of 3 means that the next token is selected from among the 3 most probable tokens (using temperature).',
maxoutputtokens:
' Maximum number of tokens that can be generated in the response. Specify a lower value for shorter responses and a higher value for longer responses.',
};
function OptionHover({ type, side }) {
// const options = {};
// if (type === 'pres') {
// options.sideOffset = 45;
// }
return (
<HoverCardPortal>
<HoverCardContent
side={side}
className="w-80 "
// {...options}
>
<div className="space-y-2">
<p className="text-sm text-gray-600 dark:text-gray-300">{types[type]}</p>
</div>
</HoverCardContent>
</HoverCardPortal>
);
}
export default OptionHover;

View File

@@ -1,260 +0,0 @@
import React from 'react';
import { useRecoilValue } from 'recoil';
import TextareaAutosize from 'react-textarea-autosize';
import SelectDropDown from '../../ui/SelectDropDown';
import { Input } from '~/components/ui/Input.tsx';
import { Label } from '~/components/ui/Label.tsx';
import { Slider } from '~/components/ui/Slider.tsx';
import { InputNumber } from '~/components/ui/InputNumber.tsx';
import OptionHover from './OptionHover';
import { HoverCard, HoverCardTrigger } from '~/components/ui/HoverCard.tsx';
import { cn } from '~/utils/';
const defaultTextProps =
'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0';
const optionText =
'p-0 shadow-none text-right pr-1 h-8 border-transparent focus:ring-[#10a37f] focus:ring-offset-0 focus:ring-opacity-100 hover:bg-gray-800/10 dark:hover:bg-white/10 focus:bg-gray-800/10 dark:focus:bg-white/10 transition-colors';
import store from '~/store';
function Settings(props) {
const {
readonly,
model,
modelLabel,
promptPrefix,
temperature,
topP,
topK,
maxOutputTokens,
setOption,
} = props;
const endpointsConfig = useRecoilValue(store.endpointsConfig);
const setModel = setOption('model');
const setModelLabel = setOption('modelLabel');
const setPromptPrefix = setOption('promptPrefix');
const setTemperature = setOption('temperature');
const setTopP = setOption('topP');
const setTopK = setOption('topK');
const setMaxOutputTokens = setOption('maxOutputTokens');
const models = endpointsConfig?.['google']?.['availableModels'] || [];
const codeChat = model.startsWith('codechat-');
return (
<div className={'h-[490px] overflow-y-auto md:h-[350px]'}>
<div className="grid gap-6 sm:grid-cols-2">
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<div className="grid w-full items-center gap-2">
<SelectDropDown
value={model}
setValue={setModel}
availableValues={models}
disabled={readonly}
className={cn(
defaultTextProps,
'z-50 flex w-full resize-none focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
containerClassName="flex w-full resize-none"
/>
</div>
{!codeChat && (
<>
<div className="grid w-full items-center gap-2">
<Label htmlFor="modelLabel" className="text-left text-sm font-medium">
Custom Name <small className="opacity-40">(default: blank)</small>
</Label>
<Input
id="modelLabel"
disabled={readonly}
value={modelLabel || ''}
onChange={(e) => setModelLabel(e.target.value || null)}
placeholder="Set a custom name for PaLM2"
className={cn(
defaultTextProps,
'flex h-10 max-h-10 w-full resize-none px-3 py-2 focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0',
)}
/>
</div>
<div className="grid w-full items-center gap-2">
<Label htmlFor="promptPrefix" className="text-left text-sm font-medium">
Prompt Prefix <small className="opacity-40">(default: blank)</small>
</Label>
<TextareaAutosize
id="promptPrefix"
disabled={readonly}
value={promptPrefix || ''}
onChange={(e) => setPromptPrefix(e.target.value || null)}
placeholder="Set custom instructions or context. Ignored if empty."
className={cn(
defaultTextProps,
'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2 ',
)}
/>
</div>
</>
)}
</div>
<div className="col-span-1 flex flex-col items-center justify-start gap-6">
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="temp-int" className="text-left text-sm font-medium">
Temperature <small className="opacity-40">(default: 0.2)</small>
</Label>
<InputNumber
id="temp-int"
disabled={readonly}
value={temperature}
onChange={(value) => setTemperature(value)}
max={1}
min={0}
step={0.01}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[temperature]}
onValueChange={(value) => setTemperature(value[0])}
doubleClickHandler={() => setTemperature(1)}
max={1}
min={0}
step={0.01}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="temp" side="left" />
</HoverCard>
{!codeChat && (
<>
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="top-p-int" className="text-left text-sm font-medium">
Top P <small className="opacity-40">(default: 0.95)</small>
</Label>
<InputNumber
id="top-p-int"
disabled={readonly}
value={topP}
onChange={(value) => setTopP(value)}
max={1}
min={0}
step={0.01}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[topP]}
onValueChange={(value) => setTopP(value[0])}
doubleClickHandler={() => setTopP(1)}
max={1}
min={0}
step={0.01}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="topp" side="left" />
</HoverCard>
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="top-k-int" className="text-left text-sm font-medium">
Top K <small className="opacity-40">(default: 40)</small>
</Label>
<InputNumber
id="top-k-int"
disabled={readonly}
value={topK}
onChange={(value) => setTopK(value)}
max={40}
min={1}
step={0.01}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[topK]}
onValueChange={(value) => setTopK(value[0])}
doubleClickHandler={() => setTopK(0)}
max={40}
min={1}
step={0.01}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="topk" side="left" />
</HoverCard>
</>
)}
<HoverCard openDelay={300}>
<HoverCardTrigger className="grid w-full items-center gap-2">
<div className="flex justify-between">
<Label htmlFor="max-tokens-int" className="text-left text-sm font-medium">
Max Output Tokens <small className="opacity-40">(default: 1024)</small>
</Label>
<InputNumber
id="max-tokens-int"
disabled={readonly}
value={maxOutputTokens}
onChange={(value) => setMaxOutputTokens(value)}
max={1024}
min={1}
step={1}
controls={false}
className={cn(
defaultTextProps,
cn(
optionText,
'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-gray-200',
),
)}
/>
</div>
<Slider
disabled={readonly}
value={[maxOutputTokens]}
onValueChange={(value) => setMaxOutputTokens(value[0])}
doubleClickHandler={() => setMaxOutputTokens(0)}
max={1024}
min={1}
step={1}
className="flex h-4 w-full"
/>
</HoverCardTrigger>
<OptionHover type="maxoutputtokens" side="left" />
</HoverCard>
</div>
</div>
</div>
);
}
export default Settings;

Some files were not shown because too many files have changed in this diff Show More