mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
* 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
203 lines
11 KiB
JavaScript
203 lines
11 KiB
JavaScript
/*
|
|
module.exports = `You are ChatGPT, a Large Language model with useful tools.
|
|
|
|
Talk to the human and provide meaningful answers when questions are asked.
|
|
|
|
Use the tools when you need them, but use your own knowledge if you are confident of the answer. Keep answers short and concise.
|
|
|
|
A tool is not usually needed for creative requests, so do your best to answer them without tools.
|
|
|
|
Avoid repeating identical answers if it appears before. Only fulfill the human's requests, do not create extra steps beyond what the human has asked for.
|
|
|
|
Your input for 'Action' should be the name of tool used only.
|
|
|
|
Be honest. If you can't answer something, or a tool is not appropriate, say you don't know or answer to the best of your ability.
|
|
|
|
Attempt to fulfill the human's requests in as few actions as possible`;
|
|
*/
|
|
|
|
// module.exports = `You are ChatGPT, a highly knowledgeable and versatile large language model.
|
|
|
|
// Engage with the Human conversationally, providing concise and meaningful answers to questions. Utilize built-in tools when necessary, except for creative requests, where relying on your own knowledge is preferred. Aim for variety and avoid repetitive answers.
|
|
|
|
// For your 'Action' input, state the name of the tool used only, and honor user requests without adding extra steps. Always be honest; if you cannot provide an appropriate answer or tool, admit that or do your best.
|
|
|
|
// Strive to meet the user's needs efficiently with minimal actions.`;
|
|
|
|
// import {
|
|
// BasePromptTemplate,
|
|
// BaseStringPromptTemplate,
|
|
// SerializedBasePromptTemplate,
|
|
// renderTemplate,
|
|
// } from "langchain/prompts";
|
|
|
|
// prefix: `You are ChatGPT, a highly knowledgeable and versatile large language model.
|
|
// Your objective is to help users by understanding their intent and choosing the best action. Prioritize direct, specific responses. Use concise, varied answers and rely on your knowledge for creative tasks. Utilize tools when needed, and structure results for machine compatibility.
|
|
// prefix: `Objective: to comprehend human intentions based on user input and available tools. Goal: identify the best action to directly address the human's query. In your subsequent steps, you will utilize the chosen action. You may select multiple actions and list them in a meaningful order. Prioritize actions that directly relate to the user's query over general ones. Ensure that the generated thought is highly specific and explicit to best match the user's expectations. Construct the result in a manner that an online open-API would most likely expect. Provide concise and meaningful answers to human queries. Utilize tools when necessary. Relying on your own knowledge is preferred for creative requests. Aim for variety and avoid repetitive answers.
|
|
|
|
// # Available Actions & Tools:
|
|
// N/A: no suitable action, use your own knowledge.`,
|
|
// suffix: `Remember, all your responses MUST adhere to the described format and only respond if the format is followed. Output exactly with the requested format, avoiding any other text as this will be parsed by a machine. Following 'Action:', provide only one of the actions listed above. If a tool is not necessary, deduce this quickly and finish your response. Honor the human's requests without adding extra steps. Carry out tasks in the sequence written by the human. Always be honest; if you cannot provide an appropriate answer or tool, do your best with your own knowledge. Strive to meet the user's needs efficiently with minimal actions.`;
|
|
|
|
module.exports = {
|
|
'gpt3-v1': {
|
|
prefix: `Objective: Understand human intentions using user input and available tools. Goal: Identify the most suitable actions to directly address user queries.
|
|
|
|
When responding:
|
|
- Choose actions relevant to the user's query, using multiple actions in a logical order if needed.
|
|
- Prioritize direct and specific thoughts to meet user expectations.
|
|
- Format results in a way compatible with open-API expectations.
|
|
- Offer concise, meaningful answers to user queries.
|
|
- Use tools when necessary but rely on your own knowledge for creative requests.
|
|
- Strive for variety, avoiding repetitive responses.
|
|
|
|
# Available Actions & Tools:
|
|
N/A: No suitable action; use your own knowledge.`,
|
|
instructions: `Always adhere to the following format in your response to indicate actions taken:
|
|
|
|
Thought: Summarize your thought process.
|
|
Action: Select an action from [{tool_names}].
|
|
Action Input: Define the action's input.
|
|
Observation: Report the action's result.
|
|
|
|
Repeat steps 1-4 as needed, in order. When not using a tool, use N/A for Action, provide the result as Action Input, and include an Observation.
|
|
|
|
Upon reaching the final answer, use this format after completing all necessary actions:
|
|
|
|
Thought: Indicate that you've determined the final answer.
|
|
Final Answer: Present the answer to the user's query.`,
|
|
suffix: `Keep these guidelines in mind when crafting your response:
|
|
- Strictly adhere to the Action format for all responses, as they will be machine-parsed.
|
|
- If a tool is unnecessary, quickly move to the Thought/Final Answer format.
|
|
- Follow the logical sequence provided by the user without adding extra steps.
|
|
- Be honest; if you can't provide an appropriate answer using the given tools, use your own knowledge.
|
|
- Aim for efficiency and minimal actions to meet the user's needs effectively.`,
|
|
},
|
|
'gpt3-v2': {
|
|
prefix: `Objective: Understand the human's query with available actions & tools. Let's work this out in a step by step way to be sure we fulfill the query.
|
|
|
|
When responding:
|
|
- Choose actions relevant to the user's query, using multiple actions in a logical order if needed.
|
|
- Prioritize direct and specific thoughts to meet user expectations.
|
|
- Format results in a way compatible with open-API expectations.
|
|
- Offer concise, meaningful answers to user queries.
|
|
- Use tools when necessary but rely on your own knowledge for creative requests.
|
|
- Strive for variety, avoiding repetitive responses.
|
|
|
|
# Available Actions & Tools:
|
|
N/A: No suitable action; use your own knowledge.`,
|
|
instructions: `I want you to respond with this format and this format only, without comments or explanations, to indicate actions taken:
|
|
\`\`\`
|
|
Thought: Summarize your thought process.
|
|
Action: Select an action from [{tool_names}].
|
|
Action Input: Define the action's input.
|
|
Observation: Report the action's result.
|
|
\`\`\`
|
|
|
|
Repeat the format for each action as needed. When not using a tool, use N/A for Action, provide the result as Action Input, and include an Observation.
|
|
|
|
Upon reaching the final answer, use this format after completing all necessary actions:
|
|
\`\`\`
|
|
Thought: Indicate that you've determined the final answer.
|
|
Final Answer: A conversational reply to the user's query as if you were answering them directly.
|
|
\`\`\``,
|
|
suffix: `Keep these guidelines in mind when crafting your response:
|
|
- Strictly adhere to the Action format for all responses, as they will be machine-parsed.
|
|
- If a tool is unnecessary, quickly move to the Thought/Final Answer format.
|
|
- Follow the logical sequence provided by the user without adding extra steps.
|
|
- Be honest; if you can't provide an appropriate answer using the given tools, use your own knowledge.
|
|
- Aim for efficiency and minimal actions to meet the user's needs effectively.`,
|
|
},
|
|
gpt3: {
|
|
prefix: `Objective: Understand the human's query with available actions & tools. Let's work this out in a step by step way to be sure we fulfill the query.
|
|
|
|
Use available actions and tools judiciously.
|
|
|
|
# Available Actions & Tools:
|
|
N/A: No suitable action; use your own knowledge.`,
|
|
instructions: `I want you to respond with this format and this format only, without comments or explanations, to indicate actions taken:
|
|
\`\`\`
|
|
Thought: Your thought process.
|
|
Action: Action from [{tool_names}].
|
|
Action Input: Action's input.
|
|
Observation: Action's result.
|
|
\`\`\`
|
|
|
|
For each action, repeat the format. If no tool is used, use N/A for Action, and provide the result as Action Input.
|
|
|
|
Finally, complete with:
|
|
\`\`\`
|
|
Thought: Convey final answer determination.
|
|
Final Answer: Reply to user's query conversationally.
|
|
\`\`\``,
|
|
suffix: `Remember:
|
|
- Adhere to the Action format strictly for parsing.
|
|
- Transition quickly to Thought/Final Answer format when a tool isn't needed.
|
|
- Follow user's logic without superfluous steps.
|
|
- If unable to use tools for a fitting answer, use your knowledge.
|
|
- Strive for efficient, minimal actions.`,
|
|
},
|
|
'gpt4-v1': {
|
|
prefix: `Objective: Understand the human's query with available actions & tools. Let's work this out in a step by step way to be sure we fulfill the query.
|
|
|
|
When responding:
|
|
- Choose actions relevant to the query, using multiple actions in a step by step way.
|
|
- Prioritize direct and specific thoughts to meet user expectations.
|
|
- Be precise and offer meaningful answers to user queries.
|
|
- Use tools when necessary but rely on your own knowledge for creative requests.
|
|
- Strive for variety, avoiding repetitive responses.
|
|
|
|
# Available Actions & Tools:
|
|
N/A: No suitable action; use your own knowledge.`,
|
|
instructions: `I want you to respond with this format and this format only, without comments or explanations, to indicate actions taken:
|
|
\`\`\`
|
|
Thought: Summarize your thought process.
|
|
Action: Select an action from [{tool_names}].
|
|
Action Input: Define the action's input.
|
|
Observation: Report the action's result.
|
|
\`\`\`
|
|
|
|
Repeat the format for each action as needed. When not using a tool, use N/A for Action, provide the result as Action Input, and include an Observation.
|
|
|
|
Upon reaching the final answer, use this format after completing all necessary actions:
|
|
\`\`\`
|
|
Thought: Indicate that you've determined the final answer.
|
|
Final Answer: A conversational reply to the user's query as if you were answering them directly.
|
|
\`\`\``,
|
|
suffix: `Keep these guidelines in mind when crafting your final response:
|
|
- Strictly adhere to the Action format for all responses.
|
|
- If a tool is unnecessary, quickly move to the Thought/Final Answer format, only if no further actions are possible or necessary.
|
|
- Follow the logical sequence provided by the user without adding extra steps.
|
|
- Be honest: if you can't provide an appropriate answer using the given tools, use your own knowledge.
|
|
- Aim for efficiency and minimal actions to meet the user's needs effectively.`,
|
|
},
|
|
gpt4: {
|
|
prefix: `Objective: Understand the human's query with available actions & tools. Let's work this out in a step by step way to be sure we fulfill the query.
|
|
|
|
Use available actions and tools judiciously.
|
|
|
|
# Available Actions & Tools:
|
|
N/A: No suitable action; use your own knowledge.`,
|
|
instructions: `Respond in this specific format without extraneous comments:
|
|
\`\`\`
|
|
Thought: Your thought process.
|
|
Action: Action from [{tool_names}].
|
|
Action Input: Action's input.
|
|
Observation: Action's result.
|
|
\`\`\`
|
|
|
|
For each action, repeat the format. If no tool is used, use N/A for Action, and provide the result as Action Input.
|
|
|
|
Finally, complete with:
|
|
\`\`\`
|
|
Thought: Indicate that you've determined the final answer.
|
|
Final Answer: A conversational reply to the user's query, including your full answer.
|
|
\`\`\``,
|
|
suffix: `Remember:
|
|
- Adhere to the Action format strictly for parsing.
|
|
- Transition quickly to Thought/Final Answer format when a tool isn't needed.
|
|
- Follow user's logic without superfluous steps.
|
|
- If unable to use tools for a fitting answer, use your knowledge.
|
|
- Strive for efficient, minimal actions.`,
|
|
},
|
|
};
|