()(
storage: createJSONStorage(() => localStorage),
partialize: (state) => ({
agentMode: state.agentMode,
- // isWebSearchEnabled: state.isWebSearchEnabled
+ // isWebSearchEnabled: state.isWebSearchEnabled,
}),
}
)
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index dfe92ef3..6cecbd78 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -303,6 +303,8 @@ const Home: NextPage = () => {
: undefined
}
scrollToBottom
+ displaySettings
+ openSorryDialog={() => setShowSorryDialog(true)}
/>
{tasks.length > 0 && }
From 239217dc8025c9895340200b9922c9c792f0992e Mon Sep 17 00:00:00 2001
From: Dogtiti <499960698@qq.com>
Date: Wed, 3 May 2023 14:44:24 +0800
Subject: [PATCH 4/9] fix: prompts
---
package-lock.json | 373 ++++++++++++++++------------------
src/components/ChatWindow.tsx | 2 +-
src/pages/index.tsx | 3 +-
src/utils/prompts.ts | 6 +-
tailwind.config.cjs | 2 +-
5 files changed, 186 insertions(+), 200 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index c7725676..a85ead0e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1954,186 +1954,6 @@
"glob": "7.1.7"
}
},
- "node_modules/@next/swc-android-arm-eabi": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.1.6.tgz",
- "integrity": "sha512-F3/6Z8LH/pGlPzR1AcjPFxx35mPqjE5xZcf+IL+KgbW9tMkp7CYi1y7qKrEWU7W4AumxX/8OINnDQWLiwLasLQ==",
- "cpu": [
- "arm"
- ],
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-android-arm64": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-13.1.6.tgz",
- "integrity": "sha512-cMwQjnB8vrYkWyK/H0Rf2c2pKIH4RGjpKUDvbjVAit6SbwPDpmaijLio0LWFV3/tOnY6kvzbL62lndVA0mkYpw==",
- "cpu": [
- "arm64"
- ],
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-darwin-arm64": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.1.6.tgz",
- "integrity": "sha512-KKRQH4DDE4kONXCvFMNBZGDb499Hs+xcFAwvj+rfSUssIDrZOlyfJNy55rH5t2Qxed1e4K80KEJgsxKQN1/fyw==",
- "cpu": [
- "arm64"
- ],
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-darwin-x64": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.1.6.tgz",
- "integrity": "sha512-/uOky5PaZDoaU99ohjtNcDTJ6ks/gZ5ykTQDvNZDjIoCxFe3+t06bxsTPY6tAO6uEAw5f6vVFX5H5KLwhrkZCA==",
- "cpu": [
- "x64"
- ],
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-freebsd-x64": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.1.6.tgz",
- "integrity": "sha512-qaEALZeV7to6weSXk3Br80wtFQ7cFTpos/q+m9XVRFggu+8Ib895XhMWdJBzew6aaOcMvYR6KQ6JmHA2/eMzWw==",
- "cpu": [
- "x64"
- ],
- "optional": true,
- "os": [
- "freebsd"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-linux-arm-gnueabihf": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.1.6.tgz",
- "integrity": "sha512-OybkbC58A1wJ+JrJSOjGDvZzrVEQA4sprJejGqMwiZyLqhr9Eo8FXF0y6HL+m1CPCpPhXEHz/2xKoYsl16kNqw==",
- "cpu": [
- "arm"
- ],
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-linux-arm64-gnu": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.1.6.tgz",
- "integrity": "sha512-yCH+yDr7/4FDuWv6+GiYrPI9kcTAO3y48UmaIbrKy8ZJpi7RehJe3vIBRUmLrLaNDH3rY1rwoHi471NvR5J5NQ==",
- "cpu": [
- "arm64"
- ],
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-linux-arm64-musl": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.1.6.tgz",
- "integrity": "sha512-ECagB8LGX25P9Mrmlc7Q/TQBb9rGScxHbv/kLqqIWs2fIXy6Y/EiBBiM72NTwuXUFCNrWR4sjUPSooVBJJ3ESQ==",
- "cpu": [
- "arm64"
- ],
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-linux-x64-gnu": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.1.6.tgz",
- "integrity": "sha512-GT5w2mruk90V/I5g6ScuueE7fqj/d8Bui2qxdw6lFxmuTgMeol5rnzAv4uAoVQgClOUO/MULilzlODg9Ib3Y4Q==",
- "cpu": [
- "x64"
- ],
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-linux-x64-musl": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.1.6.tgz",
- "integrity": "sha512-keFD6KvwOPzmat4TCnlnuxJCQepPN+8j3Nw876FtULxo8005Y9Ghcl7ACcR8GoiKoddAq8gxNBrpjoxjQRHeAQ==",
- "cpu": [
- "x64"
- ],
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-win32-arm64-msvc": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.1.6.tgz",
- "integrity": "sha512-OwertslIiGQluFvHyRDzBCIB07qJjqabAmINlXUYt7/sY7Q7QPE8xVi5beBxX/rxTGPIbtyIe3faBE6Z2KywhQ==",
- "cpu": [
- "arm64"
- ],
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
- "node_modules/@next/swc-win32-ia32-msvc": {
- "version": "13.1.6",
- "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.1.6.tgz",
- "integrity": "sha512-g8zowiuP8FxUR9zslPmlju7qYbs2XBtTLVSxVikPtUDQedhcls39uKYLvOOd1JZg0ehyhopobRoH1q+MHlIN/w==",
- "cpu": [
- "ia32"
- ],
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">= 10"
- }
- },
"node_modules/@next/swc-win32-x64-msvc": {
"version": "13.1.6",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.1.6.tgz",
@@ -6639,19 +6459,6 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
- "node_modules/fsevents": {
- "version": "2.3.2",
- "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
- "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
- "hasInstallScript": true,
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
- }
- },
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
@@ -14632,6 +14439,186 @@
"type": "github",
"url": "https://github.com/sponsors/wooorm"
}
+ },
+ "node_modules/@next/swc-android-arm-eabi": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.1.6.tgz",
+ "integrity": "sha512-F3/6Z8LH/pGlPzR1AcjPFxx35mPqjE5xZcf+IL+KgbW9tMkp7CYi1y7qKrEWU7W4AumxX/8OINnDQWLiwLasLQ==",
+ "cpu": [
+ "arm"
+ ],
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-android-arm64": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-android-arm64/-/swc-android-arm64-13.1.6.tgz",
+ "integrity": "sha512-cMwQjnB8vrYkWyK/H0Rf2c2pKIH4RGjpKUDvbjVAit6SbwPDpmaijLio0LWFV3/tOnY6kvzbL62lndVA0mkYpw==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-darwin-arm64": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.1.6.tgz",
+ "integrity": "sha512-KKRQH4DDE4kONXCvFMNBZGDb499Hs+xcFAwvj+rfSUssIDrZOlyfJNy55rH5t2Qxed1e4K80KEJgsxKQN1/fyw==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-darwin-x64": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.1.6.tgz",
+ "integrity": "sha512-/uOky5PaZDoaU99ohjtNcDTJ6ks/gZ5ykTQDvNZDjIoCxFe3+t06bxsTPY6tAO6uEAw5f6vVFX5H5KLwhrkZCA==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-freebsd-x64": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.1.6.tgz",
+ "integrity": "sha512-qaEALZeV7to6weSXk3Br80wtFQ7cFTpos/q+m9XVRFggu+8Ib895XhMWdJBzew6aaOcMvYR6KQ6JmHA2/eMzWw==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-linux-arm-gnueabihf": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.1.6.tgz",
+ "integrity": "sha512-OybkbC58A1wJ+JrJSOjGDvZzrVEQA4sprJejGqMwiZyLqhr9Eo8FXF0y6HL+m1CPCpPhXEHz/2xKoYsl16kNqw==",
+ "cpu": [
+ "arm"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-linux-arm64-gnu": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.1.6.tgz",
+ "integrity": "sha512-yCH+yDr7/4FDuWv6+GiYrPI9kcTAO3y48UmaIbrKy8ZJpi7RehJe3vIBRUmLrLaNDH3rY1rwoHi471NvR5J5NQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-linux-arm64-musl": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.1.6.tgz",
+ "integrity": "sha512-ECagB8LGX25P9Mrmlc7Q/TQBb9rGScxHbv/kLqqIWs2fIXy6Y/EiBBiM72NTwuXUFCNrWR4sjUPSooVBJJ3ESQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-linux-x64-gnu": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.1.6.tgz",
+ "integrity": "sha512-GT5w2mruk90V/I5g6ScuueE7fqj/d8Bui2qxdw6lFxmuTgMeol5rnzAv4uAoVQgClOUO/MULilzlODg9Ib3Y4Q==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-linux-x64-musl": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.1.6.tgz",
+ "integrity": "sha512-keFD6KvwOPzmat4TCnlnuxJCQepPN+8j3Nw876FtULxo8005Y9Ghcl7ACcR8GoiKoddAq8gxNBrpjoxjQRHeAQ==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-win32-arm64-msvc": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.1.6.tgz",
+ "integrity": "sha512-OwertslIiGQluFvHyRDzBCIB07qJjqabAmINlXUYt7/sY7Q7QPE8xVi5beBxX/rxTGPIbtyIe3faBE6Z2KywhQ==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
+ },
+ "node_modules/@next/swc-win32-ia32-msvc": {
+ "version": "13.1.6",
+ "resolved": "https://registry.npmmirror.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.1.6.tgz",
+ "integrity": "sha512-g8zowiuP8FxUR9zslPmlju7qYbs2XBtTLVSxVikPtUDQedhcls39uKYLvOOd1JZg0ehyhopobRoH1q+MHlIN/w==",
+ "cpu": [
+ "ia32"
+ ],
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">= 10"
+ }
}
}
}
diff --git a/src/components/ChatWindow.tsx b/src/components/ChatWindow.tsx
index 05dc5ff7..8faf56ae 100644
--- a/src/components/ChatWindow.tsx
+++ b/src/components/ChatWindow.tsx
@@ -83,7 +83,7 @@ const ChatWindow = ({
// Change this value when we can no longer support web search
const WEB_SEARCH_ALLOWED = env.NEXT_PUBLIC_WEB_SEARCH_ENABLED as boolean;
- if (WEB_SEARCH_ALLOWED === true) {
+ if (WEB_SEARCH_ALLOWED) {
setIsWebSearchEnabled(value);
} else {
openSorryDialog?.();
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 6cecbd78..9b03b980 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -127,8 +127,7 @@ const Home: NextPage = () => {
agent != null || isEmptyOrBlank(name) || isEmptyOrBlank(goalInput);
const handleNewGoal = () => {
- // Do not force login locally for people that don't have auth setup
- if (session === null && process.env.NODE_ENV === "production") {
+ if (session === null && process.env.NODE_ENV === "production"&&authEnabled) {
setShowSignInDialog(true);
return;
}
diff --git a/src/utils/prompts.ts b/src/utils/prompts.ts
index a87f7715..3a8862cd 100644
--- a/src/utils/prompts.ts
+++ b/src/utils/prompts.ts
@@ -38,7 +38,7 @@ export const createModel = (settings: ModelSettings) => {
};
export const startGoalPrompt = new PromptTemplate({
- template: `You are a task creation AI called AgentGPT. You must answer in {customLanguage}. You are not a part of any system or device. You have the following objective "{goal}". Create a list of zero to three tasks to be completed by your AI system such that this goal is more closely, or completely reached. You have access to google search for tasks that require current events or small searches. Return the response as a formatted ARRAY of strings that can be used in JSON.parse(). Example: ["Research new marketing designs", "Write a python script to create a campaign"].`,
+ template: `You are a task creation AI called AgentGPT. You must answer the "{customLanguage}" language. You are not a part of any system or device. You have the following objective "{goal}". Create a list of zero to three tasks to be completed by your AI system such that this goal is more closely, or completely reached. You have access to google search for tasks that require current events or small searches. Return the response as a formatted ARRAY of strings that can be used in JSON.parse(). Example: ["{{TASK-1}}", "{{TASK-2}}"].`,
inputVariables: ["goal", "customLanguage"],
});
@@ -49,13 +49,13 @@ export const analyzeTaskPrompt = new PromptTemplate({
export const executeTaskPrompt = new PromptTemplate({
template:
- "You are an AI agent called AgentGPT. You must answer in {customLanguage}. Given the following overall objective `{goal}` and the following sub-task, `{task}`. Perform the task.",
+ 'You are an AI agent called AgentGPT. You must answer in the "{customLanguage}" language. Given the following overall objective `{goal}` and the following sub-task, `{task}`. Perform the task.',
inputVariables: ["goal", "task", "customLanguage"],
});
export const createTasksPrompt = new PromptTemplate({
template:
- "You are an AI task creation agent. You must answer in {customLanguage}. You have the following objective `{goal}`. You have the following incomplete tasks `{tasks}` and have just executed the following task `{lastTask}` and received the following result `{result}`. Based on this, create a new task to be completed by your AI system ONLY IF NEEDED such that your goal is more closely reached or completely reached. Return the response as an array of strings that can be used in JSON.parse() and NOTHING ELSE.",
+ 'You are an AI task creation agent. You must answer in the "{customLanguage}" language. You have the following objective `{goal}`. You have the following incomplete tasks `{tasks}` and have just executed the following task `{lastTask}` and received the following result `{result}`. Based on this, create a new task to be completed by your AI system ONLY IF NEEDED such that your goal is more closely reached or completely reached. Return the response as an array of strings that can be used in JSON.parse() and NOTHING ELSE.',
inputVariables: ["goal", "tasks", "lastTask", "result", "customLanguage"],
});
diff --git a/tailwind.config.cjs b/tailwind.config.cjs
index 2b4031ba..d57adf2c 100644
--- a/tailwind.config.cjs
+++ b/tailwind.config.cjs
@@ -19,5 +19,5 @@ module.exports = {
},
},
},
- plugins: ["tailwindcss-radix"],
+ plugins: [require("tailwindcss-radix")],
};
From e19a201c03f304bbdd75ff27fe150dfdbf39f52d Mon Sep 17 00:00:00 2001
From: Dogtiti <499960698@qq.com>
Date: Wed, 3 May 2023 17:54:57 +0800
Subject: [PATCH 5/9] fix: message depth
---
src/components/AutonomousAgent.ts | 152 ++++++++------------------
src/components/ChatWindow.tsx | 51 ++++-----
src/components/stores/messageStore.ts | 30 +++--
src/pages/index.tsx | 31 ++----
src/types/agentTypes.ts | 3 +
5 files changed, 107 insertions(+), 160 deletions(-)
diff --git a/src/components/AutonomousAgent.ts b/src/components/AutonomousAgent.ts
index 3e98782d..f760d4d8 100644
--- a/src/components/AutonomousAgent.ts
+++ b/src/components/AutonomousAgent.ts
@@ -92,43 +92,31 @@ class AutonomousAgent {
this.stopAgent();
return;
}
-
- this.sendGoalMessage();
- this.sendThinkingMessage();
-
- // Initialize by getting tasks
- try {
- const taskValues = await this.getInitialTasks();
- for (const value of taskValues) {
- await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
- const task: Task = {
- taskId: v1().toString(),
- value,
- status: TASK_STATUS_STARTED,
- type: MESSAGE_TYPE_TASK,
- };
- this.sendMessage(task);
- this.tasks.push(task);
+ if (this.tasks.length === 0) {
+ this.sendGoalMessage();
+ this.sendThinkingMessage();
+
+ // Initialize by getting tasks
+ try {
+ const taskValues = await this.getInitialTasks();
+ for (const value of taskValues) {
+ await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
+ const task: Task = {
+ taskId: v1().toString(),
+ value,
+ status: TASK_STATUS_STARTED,
+ type: MESSAGE_TYPE_TASK,
+ };
+ this.sendMessage(task);
+ this.tasks.push(task);
+ }
+ } catch (e) {
+ console.log(e);
+ this.sendErrorMessage(getMessageFromError(e));
+ this.shutdown();
+ return;
}
- } catch (e) {
- console.log(e);
- this.sendErrorMessage(getMessageFromError(e));
- this.shutdown();
- return;
}
- // try {
- // const tasks = await this.getInitialTasks();
- // this.tasks = tasks.map((task) => ({ taskId: v4(), task }));
- // for (const task of this.tasks) {
- // await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
- // this.sendTaskMessage(task.task, task.taskId);
- // }
- // } catch (e) {
- // console.log(e);
- // this.sendErrorMessage(getMessageFromError(e));
- // this.shutdown();
- // return;
- // }
await this.loop();
if (this.mode === PAUSE_MODE && !this.isRunning) {
@@ -140,6 +128,8 @@ class AutonomousAgent {
console.log(`Loop ${this.numLoops}`);
console.log(this.tasks);
+ this.conditionalPause();
+
if (!this.isRunning) {
return;
}
@@ -163,7 +153,7 @@ class AutonomousAgent {
const currentTask = this.tasks.shift() as Task;
- this.sendThinkingMessage();
+ this.sendThinkingMessage(currentTask.taskId);
// Default to reasoning
let analysis: Analysis = { action: "reason", arg: "" };
@@ -190,19 +180,26 @@ class AutonomousAgent {
// Wait before adding tasks
await new Promise((r) => setTimeout(r, TIMEOUT_LONG));
- this.sendThinkingMessage();
+ this.sendThinkingMessage(currentTask.taskId);
// Add new tasks
try {
- const newTasks = await this.getAdditionalTasks(currentTask.value, result);
- for (const value of newTasks) {
- await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
+ const newTasks: Task[] = (
+ await this.getAdditionalTasks(currentTask.value, result)
+ ).map((value) => {
const task: Task = {
taskId: v1().toString(),
value,
status: TASK_STATUS_STARTED,
type: MESSAGE_TYPE_TASK,
+ parentTaskId: currentTask.taskId,
};
+ return task;
+ });
+ //FIXME
+ // this.tasks = newTasks.concat(this.tasks);
+ for (const task of newTasks) {
+ await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
this.tasks.push(task);
this.sendMessage(task);
}
@@ -216,41 +213,6 @@ class AutonomousAgent {
this.sendMessage({ ...currentTask, status: TASK_STATUS_FINAL });
}
- // // Execute first task
- // // Get and remove first task
- // this.completedTasks.push(this.tasks[0]?.task || "");
- // const { task: currentTask, taskId: currentTaskId } =
- // this.tasks.shift() as Task;
- // this.sendThinkingMessage(currentTaskId);
-
- // const result = await this.executeTask(currentTask as string);
- // this.sendExecutionMessage(currentTask as string, result, currentTaskId);
-
- // // Wait before adding tasks
- // await new Promise((r) => setTimeout(r, TIMEOUT_LONG));
- // this.sendThinkingMessage(currentTaskId);
-
- // // Add new tasks
- // try {
- // console.log("newTasks", currentTask, result);
- // const newTasks: Task[] = (
- // await this.getAdditionalTasks(currentTask as string, result)
- // ).map((task) => ({ parentTaskId: currentTaskId, taskId: v4(), task }));
- // this.tasks = newTasks.concat(this.tasks);
- // for (const task of newTasks) {
- // await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
- // this.sendTaskMessage(task.task, task.taskId, currentTaskId);
- // }
-
- // if (newTasks.length == 0) {
- // this.sendActionMessage("task-marked-as-complete", currentTaskId);
- // }
- // } catch (e) {
- // console.log(e);
- // this.sendErrorMessage(`errors.adding-additional-task`);
- // this.sendActionMessage("task-marked-as-complete", currentTaskId);
- // }
-
await this.loop();
}
@@ -417,8 +379,12 @@ class AutonomousAgent {
}
}
- sendGoalMessage() {
- this.sendMessage({ type: MESSAGE_TYPE_GOAL, value: this.goal });
+ sendGoalMessage(taskId?: string) {
+ this.sendMessage({
+ type: MESSAGE_TYPE_GOAL,
+ value: this.goal,
+ taskId,
+ });
}
sendLoopMessage() {
@@ -445,7 +411,7 @@ class AutonomousAgent {
});
}
- sendAnalysisMessage(analysis: Analysis) {
+ sendAnalysisMessage(analysis: Analysis, taskId?: string) {
// Hack to send message with generic test. Should use a different type in the future
let message = "🧠 Generating response...";
if (analysis.action == "search") {
@@ -455,6 +421,7 @@ class AutonomousAgent {
this.sendMessage({
type: MESSAGE_TYPE_SYSTEM,
value: message,
+ taskId,
});
}
@@ -462,7 +429,7 @@ class AutonomousAgent {
this.sendMessage({
type: MESSAGE_TYPE_THINKING,
value: "",
- // taskId
+ taskId: taskId,
});
}
@@ -470,32 +437,7 @@ class AutonomousAgent {
this.sendMessage({ type: MESSAGE_TYPE_SYSTEM, value: error });
}
- // sendTaskMessage(task: string, taskId: string, parentTaskId?: string) {
- // this.sendMessage({
- // type: "task",
- // value: task,
- // taskId,
- // parentTaskId
- // });
- // }
-
- // sendExecutionMessage(task: string, execution: string, taskId: string) {
- // this.sendMessage({
- // type: "action",
- // info: `Executing "${task}"`,
- // value: execution,
- // taskId,
- // });
- // }
-
- // sendActionMessage(message: string, taskId: string) {
- // this.sendMessage({
- // type: "action",
- // info: message,
- // value: "",
- // taskId,
- // });
- // }
+
}
const testConnection = async (modelSettings: ModelSettings) => {
diff --git a/src/components/ChatWindow.tsx b/src/components/ChatWindow.tsx
index 8faf56ae..003a92dd 100644
--- a/src/components/ChatWindow.tsx
+++ b/src/components/ChatWindow.tsx
@@ -91,30 +91,30 @@ const ChatWindow = ({
}
};
- // const messageDepth = (messages: Message[], message: Message, depth = 0) => {
- // if (depth > 5) {
- // return depth;
- // }
- // const index = messages.findLastIndex(
- // (i: Message) => i.parentTaskId && i.taskId === message.taskId
- // );
- // if (index > -1) {
- // const { parentTaskId } = messages[index] as Message;
- // if (parentTaskId) {
- // const parentIndex = messages.findLastIndex(
- // (i: Message) => i.taskId && i.taskId === parentTaskId
- // );
- // if (parentIndex > -1) {
- // return messageDepth(
- // messages,
- // messages[parentIndex] as Message,
- // depth + 1
- // );
- // }
- // }
- // }
- // return depth;
- // };
+ const messageDepth = (messages: Message[], message: Message, depth = 0) => {
+ if (depth > 5) {
+ return depth;
+ }
+ const index = messages.findLastIndex(
+ (i) => i.parentTaskId && i.taskId === message.taskId
+ );
+ if (index > -1) {
+ const { parentTaskId } = messages[index] as Message;
+ if (parentTaskId) {
+ const parentIndex = messages.findLastIndex(
+ (i: Message) => i.taskId && i.taskId === parentTaskId
+ );
+ if (parentIndex > -1) {
+ return messageDepth(
+ messages,
+ messages[parentIndex] as Message,
+ depth + 1
+ );
+ }
+ }
+ }
+ return depth;
+ };
return (
);
@@ -359,6 +359,7 @@ const ChatMessage = ({
className={`${getMessageContainerStyle(
message
)} mx-2 my-1 rounded-lg border-[2px] bg-white/20 p-1 font-mono text-sm hover:border-[#1E88E5]/40 sm:mx-4 sm:p-3 sm:text-base`}
+ style={{ marginLeft: `${depth * 40 + 20}px` }}
>
{message.type != MESSAGE_TYPE_SYSTEM && (
// Avoid for system messages as they do not have an icon and will cause a weird space
diff --git a/src/components/stores/messageStore.ts b/src/components/stores/messageStore.ts
index f3596f93..5c6dae68 100644
--- a/src/components/stores/messageStore.ts
+++ b/src/components/stores/messageStore.ts
@@ -38,14 +38,28 @@ const createMessageSlice: StateCreator<
addMessage: (newMessage) => {
const newTask = { ...newMessage };
newMessage = { ...newMessage };
- set((state) => ({
- ...state,
- messages: [...state.messages, newMessage],
- tasks:
- isTask(newTask) && !isExistingTask(newTask)
- ? [...state.tasks, newTask]
- : [...state.tasks],
- }));
+ set((state) => {
+ //FIXME
+ // const preMessages = state.messages;
+ // const index = preMessages.findLastIndex(
+ // (message) => message?.taskId === newMessage?.parentTaskId
+ // );
+ // const messagesCopy = [...preMessages];
+ // messagesCopy.splice(
+ // index > -1 ? index + 1 : messagesCopy.length,
+ // 0,
+ // newMessage
+ // );
+ return {
+ ...state,
+ // messages: messagesCopy,
+ messages: [...state.messages, newMessage],
+ tasks:
+ isTask(newTask) && !isExistingTask(newTask)
+ ? [...state.tasks, newTask]
+ : [...state.tasks],
+ };
+ });
},
};
};
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 9b03b980..01c8a988 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -90,29 +90,14 @@ const Home: NextPage = () => {
updateIsAgentStopped();
}, [agent, updateIsAgentStopped]);
- const handleAddMessage = (message: Message) => {
- if (isTask(message)) {
- updateTaskStatus(message);
+ const handleAddMessage = (newMessage: Message) => {
+ if (isTask(newMessage)) {
+ updateTaskStatus(newMessage);
}
- addMessage(message);
+ addMessage(newMessage);
};
- // const handleAddMessage = useCallback((newMessage: Message) => {
- // setMessages((preMessages) => {
- // const index = preMessages.findLastIndex(
- // (message) => message?.taskId === newMessage?.taskId
- // );
- // const messagesCopy = [...preMessages];
- // messagesCopy.splice(
- // index > -1 ? index + 1 : messagesCopy.length,
- // 0,
- // newMessage
- // );
- // return messagesCopy;
- // });
- // }, []);
-
const handlePause = (opts: {
agentPlaybackControl?: AgentPlaybackControl;
}) => {
@@ -121,13 +106,15 @@ const Home: NextPage = () => {
}
};
- // const tasks = messages.filter((message) => message.type === "task");
-
const disableDeployAgent =
agent != null || isEmptyOrBlank(name) || isEmptyOrBlank(goalInput);
const handleNewGoal = () => {
- if (session === null && process.env.NODE_ENV === "production"&&authEnabled) {
+ if (
+ session === null &&
+ process.env.NODE_ENV === "production" &&
+ authEnabled
+ ) {
setShowSignInDialog(true);
return;
}
diff --git a/src/types/agentTypes.ts b/src/types/agentTypes.ts
index 3b629da6..77f45fb7 100644
--- a/src/types/agentTypes.ts
+++ b/src/types/agentTypes.ts
@@ -48,10 +48,13 @@ export type TaskStatus = z.infer;
export const messageSchemaBase = z.object({
value: z.string(),
info: z.string().optional().nullable(),
+ parentTaskId: z.string().optional(),
+ taskId: z.string().optional(),
});
export const taskSchema = z
.object({
+ parentTaskId: z.string().optional(),
taskId: z.string().optional(),
type: z.literal(MESSAGE_TYPE_TASK),
status: TaskStatusSchema,
From 1c9fa78175ca1dc07b5f9246bfe28823530a8cc7 Mon Sep 17 00:00:00 2001
From: Dogtiti <499960698@qq.com>
Date: Wed, 3 May 2023 18:02:56 +0800
Subject: [PATCH 6/9] fix: test error
---
src/utils/types.ts | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 7a83cae7..bc6da750 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -1,8 +1,8 @@
export type ModelSettings = {
- customApiKey: string;
- customModelName: string;
- customTemperature: number;
- customMaxLoops: number;
+ customApiKey?: string;
+ customModelName?: string;
+ customTemperature?: number;
+ customMaxLoops?: number;
customEndPoint?: string;
customMaxTokens?: number;
customGuestKey?: string;
From d7784d71286c3a66d30736e9c146876cb4ef7996 Mon Sep 17 00:00:00 2001
From: Dogtiti <499960698@qq.com>
Date: Wed, 3 May 2023 18:16:11 +0800
Subject: [PATCH 7/9] chore: rename test file
---
__tests__/{create-model.ts => create-model.test.ts} | 0
__tests__/{remove-task-prefix.ts => remove-task-prefix.test.ts} | 0
2 files changed, 0 insertions(+), 0 deletions(-)
rename __tests__/{create-model.ts => create-model.test.ts} (100%)
rename __tests__/{remove-task-prefix.ts => remove-task-prefix.test.ts} (100%)
diff --git a/__tests__/create-model.ts b/__tests__/create-model.test.ts
similarity index 100%
rename from __tests__/create-model.ts
rename to __tests__/create-model.test.ts
diff --git a/__tests__/remove-task-prefix.ts b/__tests__/remove-task-prefix.test.ts
similarity index 100%
rename from __tests__/remove-task-prefix.ts
rename to __tests__/remove-task-prefix.test.ts
From 156366544e0b510885b287ef66e11eaffc9b8d6d Mon Sep 17 00:00:00 2001
From: Dogtiti <499960698@qq.com>
Date: Wed, 3 May 2023 20:38:48 +0800
Subject: [PATCH 8/9] fix: message depth
---
__tests__/create-model.test.ts | 6 +++---
src/components/AutonomousAgent.ts | 7 ++-----
src/components/ChatWindow.tsx | 2 +-
src/components/stores/messageStore.ts | 25 ++++++++++++-------------
4 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/__tests__/create-model.test.ts b/__tests__/create-model.test.ts
index fd3251fb..b15857df 100644
--- a/__tests__/create-model.test.ts
+++ b/__tests__/create-model.test.ts
@@ -8,21 +8,21 @@ describe("createModel", () => {
customApiKey: "test_api_key",
customTemperature: 0.222,
customModelName: "Custom_Model",
- maxTokens: 1234,
+ customMaxTokens: 1234,
};
const model = createModel(customSettings);
expect(model.temperature).toBe(customSettings.customTemperature);
expect(model.modelName).toBe(customSettings.customModelName);
- expect(model.maxTokens).toBe(customSettings.maxTokens);
+ expect(model.maxTokens).toBe(customSettings.customMaxTokens);
});
test("should use default settings when API key is not provided", () => {
const customSettings = {
customTemperature: 0.222,
customModelName: "Custom_Model",
- maxTokens: 1234,
+ customMaxTokens: 1234,
};
const model = createModel(customSettings);
diff --git a/src/components/AutonomousAgent.ts b/src/components/AutonomousAgent.ts
index f760d4d8..62e8179a 100644
--- a/src/components/AutonomousAgent.ts
+++ b/src/components/AutonomousAgent.ts
@@ -196,11 +196,10 @@ class AutonomousAgent {
};
return task;
});
- //FIXME
- // this.tasks = newTasks.concat(this.tasks);
+ this.tasks = newTasks.concat(this.tasks);
for (const task of newTasks) {
await new Promise((r) => setTimeout(r, TIMOUT_SHORT));
- this.tasks.push(task);
+ // this.tasks.push(task);
this.sendMessage(task);
}
@@ -436,8 +435,6 @@ class AutonomousAgent {
sendErrorMessage(error: string) {
this.sendMessage({ type: MESSAGE_TYPE_SYSTEM, value: error });
}
-
-
}
const testConnection = async (modelSettings: ModelSettings) => {
diff --git a/src/components/ChatWindow.tsx b/src/components/ChatWindow.tsx
index 003a92dd..fd42af3c 100644
--- a/src/components/ChatWindow.tsx
+++ b/src/components/ChatWindow.tsx
@@ -96,7 +96,7 @@ const ChatWindow = ({
return depth;
}
const index = messages.findLastIndex(
- (i) => i.parentTaskId && i.taskId === message.taskId
+ (i: Message) => i.parentTaskId && i.taskId === message.taskId
);
if (index > -1) {
const { parentTaskId } = messages[index] as Message;
diff --git a/src/components/stores/messageStore.ts b/src/components/stores/messageStore.ts
index 5c6dae68..4ddb5570 100644
--- a/src/components/stores/messageStore.ts
+++ b/src/components/stores/messageStore.ts
@@ -39,21 +39,20 @@ const createMessageSlice: StateCreator<
const newTask = { ...newMessage };
newMessage = { ...newMessage };
set((state) => {
- //FIXME
- // const preMessages = state.messages;
- // const index = preMessages.findLastIndex(
- // (message) => message?.taskId === newMessage?.parentTaskId
- // );
- // const messagesCopy = [...preMessages];
- // messagesCopy.splice(
- // index > -1 ? index + 1 : messagesCopy.length,
- // 0,
- // newMessage
- // );
+ const preMessages = state.messages;
+ const index = preMessages.findLastIndex(
+ (message) => message?.taskId === newMessage?.taskId
+ );
+ const messagesCopy = [...preMessages];
+ messagesCopy.splice(
+ index > -1 ? index + 1 : messagesCopy.length,
+ 0,
+ newMessage
+ );
return {
...state,
- // messages: messagesCopy,
- messages: [...state.messages, newMessage],
+ messages: messagesCopy,
+ // messages: [...state.messages, newMessage],
tasks:
isTask(newTask) && !isExistingTask(newTask)
? [...state.tasks, newTask]
From 253d655e67baf0c16d9480bc64a7d388e44da6b4 Mon Sep 17 00:00:00 2001
From: Dogtiti <499960698@qq.com>
Date: Wed, 3 May 2023 23:04:07 +0800
Subject: [PATCH 9/9] fix: key validate
---
src/components/SettingsDialog.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/components/SettingsDialog.tsx b/src/components/SettingsDialog.tsx
index a130e395..e73805a1 100644
--- a/src/components/SettingsDialog.tsx
+++ b/src/components/SettingsDialog.tsx
@@ -50,7 +50,7 @@ export const SettingsDialog: React.FC<{
};
const keyIsValid = (key: string | undefined) => {
- const pattern = /^sk-[a-zA-Z0-9]{48}$/;
+ const pattern = /^(sk-[a-zA-Z0-9]{48}|[a-fA-F0-9]{32})$/;
return key && pattern.test(key);
};