diff --git a/README.md b/README.md
index f226937dd..e4250f0cd 100644
--- a/README.md
+++ b/README.md
@@ -57,10 +57,14 @@
- [ ] 支持开关指定插件
- [ ] 支持添加自定义插件
- [ ] 支持 Agent 参数配置( agentType, maxIterations, returnIntermediateSteps 等)
-- [ ] 支持 ChatSession 级别插件功能开关
+- [x] 支持 ChatSession 级别插件功能开关
+
+ 仅在使用 `0613` 版本模型时会出现插件开关,其它模型默认为关闭状态,开关也不会显示。
## 已知问题
-- [ ] 使用插件时需将模型切换为 `0613` 版本模型,如:`gpt-3.5-turbo-0613`
+- [x] 使用插件时需将模型切换为 `0613` 版本模型,如:`gpt-3.5-turbo-0613`
+
+ 尝试使用 `chat-conversational-react-description` 等类型的 `agent` 使用插件时效果并不理想,不再考虑支持其它版本的模型。
- [x] `SERPAPI_API_KEY` 目前为必填,后续会支持使用 DuckDuckGo 替换搜索插件
- [ ] Agent 不支持自定义接口地址
- [x] ~~部分场景下插件会调用失败~~
diff --git a/app/api/langchain/tool/agent/route.ts b/app/api/langchain/tool/agent/route.ts
index f67b9e0a3..c2b38716d 100644
--- a/app/api/langchain/tool/agent/route.ts
+++ b/app/api/langchain/tool/agent/route.ts
@@ -68,6 +68,7 @@ async function handle(req: NextRequest) {
const handler = BaseCallbackHandler.fromMethods({
async handleLLMNewToken(token: string) {
if (token) {
+ console.log("[Token]", token);
var response = new ResponseBody();
response.message = token;
await writer.ready;
@@ -199,13 +200,13 @@ async function handle(req: NextRequest) {
presencePenalty: reqBody.presence_penalty,
frequencyPenalty: reqBody.frequency_penalty,
});
-
const executor = await initializeAgentExecutorWithOptions(tools, llm, {
agentType: "openai-functions",
returnIntermediateSteps: true,
maxIterations: 3,
memory: memory,
});
+
executor.call(
{
input: reqBody.messages.slice(-1)[0].content,
diff --git a/app/components/chat.module.scss b/app/components/chat.module.scss
index 2be0e795d..150477510 100644
--- a/app/components/chat.module.scss
+++ b/app/components/chat.module.scss
@@ -3,6 +3,7 @@
.chat-input-actions {
display: flex;
flex-wrap: wrap;
+ justify-content: space-between;
.chat-input-action {
display: inline-flex;
diff --git a/app/components/chat.tsx b/app/components/chat.tsx
index 50c7f13cc..f09a29236 100644
--- a/app/components/chat.tsx
+++ b/app/components/chat.tsx
@@ -27,6 +27,8 @@ import PinIcon from "../icons/pin.svg";
import EditIcon from "../icons/rename.svg";
import ConfirmIcon from "../icons/confirm.svg";
import CancelIcon from "../icons/cancel.svg";
+import EnablePluginIcon from "../icons/plugin_enable.svg";
+import DisablePluginIcon from "../icons/plugin_disable.svg";
import LightIcon from "../icons/light.svg";
import DarkIcon from "../icons/dark.svg";
@@ -414,11 +416,11 @@ export function ChatActions(props: {
const navigate = useNavigate();
const chatStore = useChatStore();
- // switch tools
- const useTools = chatStore.currentSession().useTools;
- function switchUseTools() {
+ // switch Plugins
+ const usePlugins = chatStore.currentSession().mask.usePlugins;
+ function switchUsePlugins() {
chatStore.updateCurrentSession((session) => {
- session.useTools = !session.useTools;
+ session.mask.usePlugins = !session.mask.usePlugins;
});
}
@@ -450,107 +452,114 @@ export function ChatActions(props: {
return (
- {couldStop && (
+
+ {couldStop && (
+
}
+ />
+ )}
+ {!props.hitBottom && (
+
}
+ />
+ )}
+ {props.hitBottom && (
+
}
+ />
+ )}
+
}
+ onClick={nextTheme}
+ text={Locale.Chat.InputActions.Theme[theme]}
+ icon={
+ <>
+ {theme === Theme.Auto ? (
+
+ ) : theme === Theme.Light ? (
+
+ ) : theme === Theme.Dark ? (
+
+ ) : null}
+ >
+ }
/>
- )}
- {!props.hitBottom && (
+
}
+ onClick={props.showPromptHints}
+ text={Locale.Chat.InputActions.Prompt}
+ icon={
}
/>
- )}
- {props.hitBottom && (
+
}
+ onClick={() => {
+ navigate(Path.Masks);
+ }}
+ text={Locale.Chat.InputActions.Masks}
+ icon={
}
/>
- )}
-
- {theme === Theme.Auto ? (
-
- ) : theme === Theme.Light ? (
-
- ) : theme === Theme.Dark ? (
-
- ) : null}
- >
- }
- />
+ setShowModelSelector(true)}
+ text={currentModel}
+ icon={}
+ />
- }
- />
-
- {
- navigate(Path.Masks);
- }}
- text={Locale.Chat.InputActions.Masks}
- icon={}
- />
-
- }
- onClick={() => {
- chatStore.updateCurrentSession((session) => {
- if (session.clearContextIndex === session.messages.length) {
- session.clearContextIndex = undefined;
- } else {
- session.clearContextIndex = session.messages.length;
- session.memoryPrompt = ""; // will clear memory
+ {currentModel.endsWith("0613") && (
+
+ icon={usePlugins ? : }
+ />
+ )}
- setShowModelSelector(true)}
- text={currentModel}
- icon={}
- />
-
- {/* : }
- /> */}
-
- {showModelSelector && (
- ({
- title: m,
- value: m,
- }))}
- onClose={() => setShowModelSelector(false)}
- onSelection={(s) => {
- if (s.length === 0) return;
+ {showModelSelector && (
+ ({
+ title: m,
+ value: m,
+ }))}
+ onClose={() => setShowModelSelector(false)}
+ onSelection={(s) => {
+ if (s.length === 0) return;
+ chatStore.updateCurrentSession((session) => {
+ session.mask.modelConfig.model = s[0] as ModelType;
+ session.mask.syncGlobalConfig = false;
+ session.mask.usePlugins =
+ session.mask.modelConfig.model.endsWith("0613");
+ });
+ showToast(s[0]);
+ }}
+ />
+ )}
+
+
+ }
+ onClick={() => {
chatStore.updateCurrentSession((session) => {
- session.mask.modelConfig.model = s[0] as ModelType;
- session.mask.syncGlobalConfig = false;
+ if (session.clearContextIndex === session.messages.length) {
+ session.clearContextIndex = undefined;
+ } else {
+ session.clearContextIndex = session.messages.length;
+ session.memoryPrompt = ""; // will clear memory
+ }
});
- showToast(s[0]);
}}
/>
- )}
+
);
}
@@ -1198,8 +1207,7 @@ function _Chat() {
)}
- {session.useTools &&
- !isUser &&
+ {!isUser &&
message.toolMessages &&
message.toolMessages.map((tool, index) => (
()(
session.messages.push(botMessage);
});
- if (session.useTools && modelConfig.model.endsWith("0613")) {
+ if (session.mask.usePlugins) {
console.log("[ToolAgent] start");
api.llm.toolAgentChat({
messages: sendMessages,
diff --git a/app/store/mask.ts b/app/store/mask.ts
index 02132b77d..117a6b3c3 100644
--- a/app/store/mask.ts
+++ b/app/store/mask.ts
@@ -18,6 +18,7 @@ export type Mask = {
modelConfig: ModelConfig;
lang: Lang;
builtin: boolean;
+ usePlugins?: boolean;
};
export const DEFAULT_MASK_STATE = {
@@ -46,6 +47,7 @@ export const createEmptyMask = () =>
lang: getLang(),
builtin: false,
createdAt: Date.now(),
+ usePlugins: useAppConfig.getState().modelConfig.model.endsWith("0613"),
} as Mask);
export const useMaskStore = create()(