diff --git a/api/app/langchain/ChatAgent.js b/api/app/langchain/ChatAgent.js index 2ddfb8ec5b..bf2149664d 100644 --- a/api/app/langchain/ChatAgent.js +++ b/api/app/langchain/ChatAgent.js @@ -6,7 +6,7 @@ const { } = require('@dqbd/tiktoken'); const { fetchEventSource } = require('@waylaidwanderer/fetch-event-source'); const { Agent, ProxyAgent } = require('undici'); -// const TextStream = require('../stream'); +const TextStream = require('../stream'); const { ChatOpenAI } = require('langchain/chat_models/openai'); const { CallbackManager } = require('langchain/callbacks'); const { HumanChatMessage, AIChatMessage } = require('langchain/schema'); @@ -687,13 +687,14 @@ Only respond with your conversational reply to the following User Message: return { ...responseMessage, ...this.result }; } - // if (!this.agentIsGpt3 && this.result.output) { - // responseMessage.text = this.result.output; - // await this.saveMessageToDatabase(responseMessage, user); - // const textStream = new TextStream(this.result.output); - // await textStream.processTextStream(opts.onProgress); - // return { ...responseMessage, ...this.result }; - // } + if (!completionMode && this.agentOptions.skipCompletion && this.result.output) { + responseMessage.text = this.result.output; + this.addImages(this.result.intermediateSteps, responseMessage); + await this.saveMessageToDatabase(responseMessage, user); + const textStream = new TextStream(this.result.output); + await textStream.processTextStream(opts.onProgress); + return { ...responseMessage, ...this.result }; + } if (this.options.debug) { console.debug('this.result', this.result); @@ -714,6 +715,26 @@ Only respond with your conversational reply to the following User Message: return { ...responseMessage, ...this.result }; } + addImages(intermediateSteps, responseMessage) { + if (!intermediateSteps || !responseMessage) { + return; + } + + intermediateSteps.forEach(step => { + const { observation } = step; + if (!observation || !observation.includes('![')) { + return; + } + + if (!responseMessage.text.includes(observation)) { + responseMessage.text += '\n' + observation; + if (this.options.debug) { + console.debug('added image from intermediateSteps'); + } + } + }); + } + async buildPrompt({ messages, promptPrefix: _promptPrefix, completionMode = false, isChatGptModel = true }) { if (this.options.debug) { console.debug('buildPrompt messages', messages); diff --git a/api/server/routes/ask/askGPTPlugins.js b/api/server/routes/ask/askGPTPlugins.js index f15d585656..45b5c735e3 100644 --- a/api/server/routes/ask/askGPTPlugins.js +++ b/api/server/routes/ask/askGPTPlugins.js @@ -40,6 +40,7 @@ router.post('/', requireJwtAuth, async (req, res) => { const agentOptions = req.body?.agentOptions ?? { agent: 'classic', + skipCompletion: false, model: 'gpt-3.5-turbo', temperature: 0, // top_p: 1, diff --git a/client/package.json b/client/package.json index cf50e110d0..18ff134a58 100644 --- a/client/package.json +++ b/client/package.json @@ -36,6 +36,7 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.0.0", "@radix-ui/react-slider": "^1.1.1", + "@radix-ui/react-switch": "^1.0.3", "@radix-ui/react-tabs": "^1.0.3", "@tailwindcss/forms": "^0.5.3", "@tanstack/react-query": "^4.28.0", diff --git a/client/src/components/Endpoints/EditPresetDialog.jsx b/client/src/components/Endpoints/EditPresetDialog.jsx index cdce621ac7..7e02c321c6 100644 --- a/client/src/components/Endpoints/EditPresetDialog.jsx +++ b/client/src/components/Endpoints/EditPresetDialog.jsx @@ -239,6 +239,7 @@ const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => { {preset?.endpoint === 'gptPlugins' && showAgentSettings && ( { + setAgent(checked ? 'functions' : 'classic'); + }; + + const onCheckedChangeSkip = (checked) => { + setSkipCompletion(checked); + }; + - // const toolsSelected = tools?.length > 0; const models = endpointsConfig?.[endpoint]?.['availableModels'] || []; - const agents = endpointsConfig?.[endpoint]?.['availableAgents'] || []; return (
@@ -60,19 +63,31 @@ function Settings(props) { containerClassName="flex w-full resize-none" />
-
- +
+ + + + + + + + + + + + + +
diff --git a/client/src/components/Input/PluginsOptions/index.jsx b/client/src/components/Input/PluginsOptions/index.jsx index 897699a225..62408db8ae 100644 --- a/client/src/components/Input/PluginsOptions/index.jsx +++ b/client/src/components/Input/PluginsOptions/index.jsx @@ -188,6 +188,7 @@ function PluginsOptions() { {showAgentSettings ? ( , + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +Switch.displayName = SwitchPrimitives.Root.displayName + +export { Switch } \ No newline at end of file diff --git a/client/src/components/ui/index.ts b/client/src/components/ui/index.ts index e8d818d252..d2279fe1b4 100644 --- a/client/src/components/ui/index.ts +++ b/client/src/components/ui/index.ts @@ -11,6 +11,7 @@ export * from './Landing'; export * from './ModelSelect'; export * from './Prompt'; export * from './Slider'; +export * from './Switch'; export * from './Tabs'; export * from './Templates'; export * from './Textarea'; diff --git a/client/src/utils/cleanupPreset.js b/client/src/utils/cleanupPreset.js index 12db3a6906..d9011aead8 100644 --- a/client/src/utils/cleanupPreset.js +++ b/client/src/utils/cleanupPreset.js @@ -52,6 +52,7 @@ const cleanupPreset = ({ preset: _preset, endpointsConfig = {} }) => { } else if (endpoint === 'gptPlugins') { const agentOptions = _preset?.agentOptions ?? { agent: 'classic', + skipCompletion: false, model: 'gpt-3.5-turbo', temperature: 0, // top_p: 1, diff --git a/client/src/utils/getDefaultConversation.js b/client/src/utils/getDefaultConversation.js index 5f99254e4b..91344fb01f 100644 --- a/client/src/utils/getDefaultConversation.js +++ b/client/src/utils/getDefaultConversation.js @@ -68,6 +68,7 @@ const buildDefaultConversation = ({ } else if (endpoint === 'gptPlugins') { const agentOptions = lastConversationSetup?.agentOptions ?? { agent: 'classic', + skipCompletion: false, model: 'gpt-3.5-turbo', temperature: 0, // top_p: 1, diff --git a/client/src/utils/handleSubmit.js b/client/src/utils/handleSubmit.js index ffc14507b6..a8319136bd 100644 --- a/client/src/utils/handleSubmit.js +++ b/client/src/utils/handleSubmit.js @@ -89,6 +89,7 @@ const useMessageHandler = () => { } else if (endpoint === 'gptPlugins') { const agentOptions = currentConversation?.agentOptions ?? { agent: 'classic', + skipCompletion: false, model: 'gpt-3.5-turbo', temperature: 0, // top_p: 1, diff --git a/package-lock.json b/package-lock.json index 798c2885a9..3c22017375 100644 --- a/package-lock.json +++ b/package-lock.json @@ -369,6 +369,7 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.0.0", "@radix-ui/react-slider": "^1.1.1", + "@radix-ui/react-switch": "^1.0.3", "@radix-ui/react-tabs": "^1.0.3", "@tailwindcss/forms": "^0.5.3", "@tanstack/react-query": "^4.28.0", @@ -6506,6 +6507,35 @@ } } }, + "node_modules/@radix-ui/react-switch": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.0.3.tgz", + "integrity": "sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==", + "dependencies": { + "@babel/runtime": "^7.13.10", + "@radix-ui/primitive": "1.0.1", + "@radix-ui/react-compose-refs": "1.0.1", + "@radix-ui/react-context": "1.0.1", + "@radix-ui/react-primitive": "1.0.3", + "@radix-ui/react-use-controllable-state": "1.0.1", + "@radix-ui/react-use-previous": "1.0.1", + "@radix-ui/react-use-size": "1.0.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0", + "react-dom": "^16.8 || ^17.0 || ^18.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-tabs": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.0.4.tgz", @@ -29519,7 +29549,7 @@ "jsonwebtoken": "^9.0.0", "keyv": "^4.5.2", "keyv-file": "^0.2.0", - "langchain": "0.0.94", + "langchain": "^0.0.94", "lodash": "^4.17.21", "meilisearch": "^0.33.0", "mongoose": "^7.1.1", @@ -29614,6 +29644,7 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.0.0", "@radix-ui/react-slider": "^1.1.1", + "@radix-ui/react-switch": "*", "@radix-ui/react-tabs": "^1.0.3", "@tailwindcss/forms": "^0.5.3", "@tanstack/react-query": "^4.28.0", @@ -30152,6 +30183,21 @@ "@radix-ui/react-compose-refs": "1.0.1" } }, + "@radix-ui/react-switch": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.0.3.tgz", + "integrity": "sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==", + "requires": { + "@babel/runtime": "^7.13.10", + "@radix-ui/primitive": "1.0.1", + "@radix-ui/react-compose-refs": "1.0.1", + "@radix-ui/react-context": "1.0.1", + "@radix-ui/react-primitive": "1.0.3", + "@radix-ui/react-use-controllable-state": "1.0.1", + "@radix-ui/react-use-previous": "1.0.1", + "@radix-ui/react-use-size": "1.0.1" + } + }, "@radix-ui/react-tabs": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.0.4.tgz", diff --git a/package.json b/package.json index d4074b820a..a46b34e2a5 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "nodemonConfig": { "ignore": [ "api/data/", - "data" + "data", + "client/" ] } }