2023-05-18 11:09:31 -07:00
|
|
|
module.exports = {
|
|
|
|
env: {
|
|
|
|
browser: true,
|
|
|
|
es2021: true,
|
|
|
|
node: true,
|
|
|
|
commonjs: true,
|
2023-07-14 09:36:49 -04:00
|
|
|
es6: true,
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
extends: [
|
|
|
|
'eslint:recommended',
|
|
|
|
'plugin:react/recommended',
|
|
|
|
'plugin:react-hooks/recommended',
|
2023-07-06 11:41:08 -04:00
|
|
|
'plugin:jest/recommended',
|
2023-07-14 09:36:49 -04:00
|
|
|
'prettier',
|
2023-05-18 11:09:31 -07:00
|
|
|
],
|
2023-07-14 09:36:49 -04:00
|
|
|
// ignorePatterns: ['packages/data-provider/types/**/*'],
|
2023-07-12 11:37:27 -04:00
|
|
|
ignorePatterns: [
|
2023-07-14 09:36:49 -04:00
|
|
|
'client/dist/**/*',
|
|
|
|
'client/public/**/*',
|
|
|
|
'e2e/playwright-report/**/*',
|
2023-07-12 11:37:27 -04:00
|
|
|
'packages/data-provider/types/**/*',
|
2023-07-14 09:36:49 -04:00
|
|
|
'packages/data-provider/dist/**/*',
|
2023-07-12 11:37:27 -04:00
|
|
|
],
|
2023-05-18 11:09:31 -07:00
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
parserOptions: {
|
|
|
|
ecmaVersion: 'latest',
|
|
|
|
sourceType: 'module',
|
|
|
|
ecmaFeatures: {
|
2023-07-14 09:36:49 -04:00
|
|
|
jsx: true,
|
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
plugins: ['react', 'react-hooks', '@typescript-eslint'],
|
|
|
|
rules: {
|
2023-05-18 12:12:19 -07:00
|
|
|
'react/react-in-jsx-scope': 'off',
|
2023-07-04 12:47:41 -07:00
|
|
|
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow' }],
|
2023-05-18 11:09:31 -07:00
|
|
|
indent: ['error', 2, { SwitchCase: 1 }],
|
|
|
|
'max-len': [
|
|
|
|
'error',
|
|
|
|
{
|
2023-07-06 11:41:08 -04:00
|
|
|
code: 120,
|
2023-05-18 11:09:31 -07:00
|
|
|
ignoreStrings: true,
|
|
|
|
ignoreTemplateLiterals: true,
|
2023-07-14 09:36:49 -04:00
|
|
|
ignoreComments: true,
|
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
],
|
|
|
|
'linebreak-style': 0,
|
2023-07-06 21:03:31 -04:00
|
|
|
'object-curly-spacing': ['error', 'always'],
|
refactor: Client Classes & Azure OpenAI as a separate Endpoint (#532)
* refactor: start new client classes, test localAi support
* feat: create base class, extend chatgpt from base
* refactor(BaseClient.js): change userId parameter to user
refactor(BaseClient.js): change userId parameter to user
feat(OpenAIClient.js): add sendMessage method
refactor(OpenAIClient.js): change getConversation method to use user parameter instead of userId
refactor(OpenAIClient.js): change saveMessageToDatabase method to use user parameter instead of userId
refactor(OpenAIClient.js): change buildPrompt method to use messages parameter instead of orderedMessages
feat(index.js): export client classes
refactor(askGPTPlugins.js): use req.body.token or process.env.OPENAI_API_KEY as OpenAI API key
refactor(index.js): comment out askOpenAI route
feat(index.js): add openAI route
feat(openAI.js): add new route for OpenAI API requests with support for progress updates and aborting requests.
* refactor(BaseClient.js): use optional chaining operator to access messageId property
refactor(OpenAIClient.js): use orderedMessages instead of messages to build prompt
refactor(OpenAIClient.js): use optional chaining operator to access messageId property
refactor(fetch-polyfill.js): remove fetch polyfill
refactor(openAI.js): comment out debug option in clientOptions
* refactor: update import statements and remove unused imports in several files
feat: add getAzureCredentials function to azureUtils module
docs: update comments in azureUtils module
* refactor(utils): rename migrateConversations to migrateDataToFirstUser for clarity and consistency
* feat(chatgpt-client.js): add getAzureCredentials function to retrieve Azure credentials
feat(chatgpt-client.js): use getAzureCredentials function to generate reverseProxyUrl
feat(OpenAIClient.js): add isChatCompletion property to determine if chat completion model is used
feat(OpenAIClient.js): add saveOptions parameter to sendMessage and buildPrompt methods
feat(OpenAIClient.js): modify buildPrompt method to handle chat completion model
feat(openAI.js): modify endpointOption to include modelOptions instead of individual options
refactor(OpenAIClient.js): modify getDelta property to use isChatCompletion property instead of isChatGptModel property
refactor(OpenAIClient.js): modify sendMessage method to use saveOptions parameter instead of modelOptions parameter
refactor(OpenAIClient.js): modify buildPrompt method to use saveOptions parameter instead of modelOptions parameter
refactor(OpenAIClient.js): modify ask method to include endpointOption parameter
* chore: delete draft file
* refactor(OpenAIClient.js): extract sendCompletion method from sendMessage method for reusability
* refactor(BaseClient.js): move sendMessage method to BaseClient class
feat(OpenAIClient.js): inherit from BaseClient class and implement necessary methods and properties for OpenAIClient class.
* refactor(BaseClient.js): rename getBuildPromptOptions to getBuildMessagesOptions
feat(BaseClient.js): add buildMessages method to BaseClient class
fix(ChatGPTClient.js): use message.text instead of message.message
refactor(ChatGPTClient.js): rename buildPromptBody to buildMessagesBody
refactor(ChatGPTClient.js): remove console.debug statement and add debug log for prompt variable
refactor(OpenAIClient.js): move setOptions method to the bottom of the class
feat(OpenAIClient.js): add support for cl100k_base encoding
feat(OpenAIClient.js): add support for unofficial chat GPT models
feat(OpenAIClient.js): add support for custom modelOptions
feat(OpenAIClient.js): add caching for tokenizers
feat(OpenAIClient.js): add freeAndInitializeEncoder method to free and reinitialize tokenizers
refactor(OpenAIClient.js): rename getBuildPromptOptions to getBuildMessagesOptions
refactor(OpenAIClient.js): rename buildPrompt to buildMessages
refactor(OpenAIClient.js): remove endpointOption from ask function arguments in openAI.js
* refactor(ChatGPTClient.js, OpenAIClient.js): improve code readability and consistency
- In ChatGPTClient.js, update the roleLabel and messageString variables to handle cases where the message object does not have an isCreatedByUser property or a role property with a value of 'user'.
- In OpenAIClient.js, rename the freeAndInitializeEncoder method to freeAndResetEncoder to better reflect its functionality. Also, update the method calls to reflect the new name. Additionally, update the getTokenCount method to handle errors by calling the freeAndResetEncoder method instead of the now-renamed freeAndInitializeEncoder method.
* refactor(OpenAIClient.js): extract instructions object to a separate variable and add it to payload after formatted messages
fix(OpenAIClient.js): handle cases where progressMessage.choices is undefined or empty
* refactor(BaseClient.js): extract addInstructions method from sendMessage method
feat(OpenAIClient.js): add maxTokensMap object to map maximum tokens for each model
refactor(OpenAIClient.js): use addInstructions method in buildMessages method instead of manually building the payload list
* refactor(OpenAIClient.js): remove unnecessary condition for modelOptions.model property in buildMessages method
* feat(BaseClient.js): add support for token count tracking and context strategy
feat(OpenAIClient.js): add support for token count tracking and context strategy
feat(Message.js): add tokenCount field to Message schema and updateMessage function
* refactor(BaseClient.js): add support for refining messages based on token limit
feat(OpenAIClient.js): add support for context refinement strategy
refactor(OpenAIClient.js): use context refinement strategy in message sending
refactor(server/index.js): improve code readability by breaking long lines
* refactor(BaseClient.js): change `remainingContext` to `remainingContextTokens` for clarity
feat(BaseClient.js): add `refinePrompt` and `refinePromptTemplate` to handle message refinement
feat(BaseClient.js): add `refineMessages` method to refine messages
feat(BaseClient.js): add `handleContextStrategy` method to handle context strategy
feat(OpenAIClient.js): add `abortController` to `buildPrompt` method options
refactor(OpenAIClient.js): change `payload` and `tokenCountMap` to let variables in `handleContextStrategy` method
refactor(BaseClient.js): change `remainingContext` to `remainingContextTokens` in `handleContextStrategy` method for consistency
refactor(BaseClient.js): change `remainingContext` to `remainingContextTokens` in `getMessagesWithinTokenLimit` method for consistency
refactor(BaseClient.js): change `remainingContext` to `remainingContext
* chore(openAI.js): comment out contextStrategy option in clientOptions
* chore(openAI.js): comment out debug option in clientOptions object
* test: BaseClient tests in progress
* test: Complete OpenAIClient & BaseClient tests
* fix(OpenAIClient.js): remove unnecessary whitespace
fix(OpenAIClient.js): remove unused variables and comments
fix(OpenAIClient.test.js): combine getTokenCount and freeAndResetEncoder tests
* chore(.eslintrc.js): add rule for maximum of 1 empty line
feat(ask/openAI.js): add abortMessage utility function
fix(ask/openAI.js): handle error and abort message if partial text is less than 2 characters
feat(utils/index.js): export abortMessage utility function
* test: complete additional tests
* feat: Azure OpenAI as a separate endpoint
* chore: remove extraneous console logs
* fix(azureOpenAI): use chatCompletion endpoint
* chore(initializeClient.js): delete initializeClient.js file
chore(askOpenAI.js): delete old OpenAI route handler
chore(handlers.js): remove trailing whitespace in thought variable assignment
* chore(chatgpt-client.js): remove unused chatgpt-client.js file
refactor(index.js): remove askClient import and export from index.js
* chore(chatgpt-client.tokens.js): update test script for memory usage and encoding performance
The test script in `chatgpt-client.tokens.js` has been updated to measure the memory usage and encoding performance of the client. The script now includes information about the initial memory usage, peak memory usage, final memory usage, and memory usage after a timeout. It also provides insights into the number of encoding requests that can be processed per second.
The script has been modified to use the `OpenAIClient` class instead of the `ChatGPTClient` class. Additionally, the number of iterations for the encoding loop has been reduced to 10,000.
A timeout function has been added to simulate a delay of 15 seconds. After the timeout, the memory usage is measured again.
The script now handles uncaught exceptions and logs any errors that occur, except for errors related to failed fetch requests.
Note: This is a test script and should not be used in production
* feat(FakeClient.js): add a new class `FakeClient` that extends `BaseClient` and implements methods for a fake client
feat(FakeClient.js): implement the `setOptions` method to handle options for the fake client
feat(FakeClient.js): implement the `initializeFakeClient` function to initialize a fake client with options and fake messages
fix(OpenAIClient.js): remove duplicate `maxTokensMap` import and use the one from utils
feat(BaseClient): return promptTokens and completionTokens
* refactor(gptPlugins): refactor ChatAgent to PluginsClient, which extends OpenAIClient
* refactor: client paths
* chore(jest.config.js): remove jest.config.js file
* fix(PluginController.js): update file path to manifest.json
feat(gptPlugins.js): add support for aborting messages
refactor(ask/index.js): rename askGPTPlugins to gptPlugins for consistency
* fix(BaseClient.js): fix spacing in generateTextStream function signature
refactor(BaseClient.js): remove unnecessary push to currentMessages in generateUserMessage function
refactor(BaseClient.js): remove unnecessary push to currentMessages in handleStartMethods function
refactor(PluginsClient.js): remove unused variables and date formatting in constructor
refactor(PluginsClient.js): simplify mapping of pastMessages in getCompletionPayload function
* refactor(GoogleClient): GoogleClient now extends BaseClient
* chore(.env.example): add AZURE_OPENAI_MODELS variable
fix(api/routes/ask/gptPlugins.js): enable Azure integration if PLUGINS_USE_AZURE is true
fix(api/routes/endpoints.js): getOpenAIModels function now accepts options, use AZURE_OPENAI_MODELS if PLUGINS_USE_AZURE is true
fix(client/components/Endpoints/OpenAI/Settings.jsx): remove console.log statement
docs(features/azure.md): add documentation for Azure OpenAI integration and environment variables
* fix(e2e:popup): includes the icon + endpoint names in role, name property
2023-07-03 16:51:12 -04:00
|
|
|
'no-trailing-spaces': 'error',
|
2023-07-14 09:36:49 -04:00
|
|
|
'no-multiple-empty-lines': ['error', { max: 1 }],
|
|
|
|
'comma-dangle': ['error', 'always-multiline'],
|
2023-05-18 11:09:31 -07:00
|
|
|
// "arrow-parens": [2, "as-needed", { requireForBlockBody: true }],
|
|
|
|
// 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
|
|
|
|
'no-console': 'off',
|
|
|
|
'import/extensions': 'off',
|
|
|
|
'no-promise-executor-return': 'off',
|
|
|
|
'no-param-reassign': 'off',
|
|
|
|
'no-continue': 'off',
|
|
|
|
'no-restricted-syntax': 'off',
|
|
|
|
'react/prop-types': ['off'],
|
2023-07-06 11:41:08 -04:00
|
|
|
'react/display-name': ['off'],
|
2023-07-14 09:36:49 -04:00
|
|
|
quotes: ['error', 'single'],
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
files: ['**/*.ts', '**/*.tsx'],
|
|
|
|
rules: {
|
|
|
|
'no-unused-vars': 'off', // off because it conflicts with '@typescript-eslint/no-unused-vars'
|
|
|
|
'react/display-name': 'off',
|
2023-07-14 09:36:49 -04:00
|
|
|
'@typescript-eslint/no-unused-vars': 'warn',
|
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['rollup.config.js', '.eslintrc.js', 'jest.config.js'],
|
|
|
|
env: {
|
2023-05-22 17:49:48 -07:00
|
|
|
node: true,
|
2023-07-14 09:36:49 -04:00
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
files: [
|
|
|
|
'**/*.test.js',
|
|
|
|
'**/*.test.jsx',
|
|
|
|
'**/*.test.ts',
|
|
|
|
'**/*.test.tsx',
|
|
|
|
'**/*.spec.js',
|
|
|
|
'**/*.spec.jsx',
|
|
|
|
'**/*.spec.ts',
|
|
|
|
'**/*.spec.tsx',
|
2023-07-14 09:36:49 -04:00
|
|
|
'setupTests.js',
|
2023-05-18 11:09:31 -07:00
|
|
|
],
|
|
|
|
env: {
|
|
|
|
jest: true,
|
2023-07-14 09:36:49 -04:00
|
|
|
node: true,
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
'react/display-name': 'off',
|
|
|
|
'react/prop-types': 'off',
|
2023-07-14 09:36:49 -04:00
|
|
|
'react/no-unescaped-entities': 'off',
|
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
files: '**/*.+(ts)',
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
parserOptions: {
|
2023-07-14 09:36:49 -04:00
|
|
|
project: './client/tsconfig.json',
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
2023-05-22 17:49:48 -07:00
|
|
|
plugins: ['@typescript-eslint/eslint-plugin', 'jest'],
|
2023-05-18 11:09:31 -07:00
|
|
|
extends: [
|
|
|
|
'plugin:@typescript-eslint/eslint-recommended',
|
2023-07-14 09:36:49 -04:00
|
|
|
'plugin:@typescript-eslint/recommended',
|
|
|
|
],
|
2023-07-04 12:47:41 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
files: './packages/data-provider/**/*.ts',
|
|
|
|
overrides: [
|
|
|
|
{
|
2023-07-06 11:41:08 -04:00
|
|
|
files: '**/*.ts',
|
|
|
|
parser: '@typescript-eslint/parser',
|
2023-07-04 12:47:41 -07:00
|
|
|
parserOptions: {
|
2023-07-14 09:36:49 -04:00
|
|
|
project: './packages/data-provider/tsconfig.json',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
],
|
|
|
|
settings: {
|
|
|
|
react: {
|
|
|
|
createClass: 'createReactClass', // Regex for Component Factory to use,
|
|
|
|
// default to "createReactClass"
|
|
|
|
pragma: 'React', // Pragma to use, default to "React"
|
|
|
|
fragment: 'Fragment', // Fragment to use (may be a property of <pragma>), default to "Fragment"
|
2023-07-14 09:36:49 -04:00
|
|
|
version: 'detect', // React version. "detect" automatically picks the version you have installed.
|
|
|
|
},
|
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
};
|