mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-24 06:30:16 +09:00
feat: 支持session级别插件开关
This commit is contained in:
parent
987598f30d
commit
6b28bcd9b5
@ -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;
|
||||
@ -200,12 +201,20 @@ async function handle(req: NextRequest) {
|
||||
frequencyPenalty: reqBody.frequency_penalty,
|
||||
});
|
||||
|
||||
const executor = await initializeAgentExecutorWithOptions(tools, llm, {
|
||||
let executor = await initializeAgentExecutorWithOptions(tools, llm, {
|
||||
agentType: "chat-conversational-react-description",
|
||||
returnIntermediateSteps: true,
|
||||
maxIterations: 3,
|
||||
memory: memory,
|
||||
});
|
||||
if (reqBody.model.endsWith("0613"))
|
||||
executor = await initializeAgentExecutorWithOptions(tools, llm, {
|
||||
agentType: "openai-functions",
|
||||
returnIntermediateSteps: true,
|
||||
maxIterations: 3,
|
||||
memory: memory,
|
||||
});
|
||||
|
||||
executor.call(
|
||||
{
|
||||
input: reqBody.messages.slice(-1)[0].content,
|
||||
|
@ -3,6 +3,7 @@
|
||||
.chat-input-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
|
||||
.chat-input-action {
|
||||
display: inline-flex;
|
||||
|
@ -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().usePlugins;
|
||||
function switchUsePlugins() {
|
||||
chatStore.updateCurrentSession((session) => {
|
||||
session.useTools = !session.useTools;
|
||||
session.usePlugins = !session.usePlugins;
|
||||
});
|
||||
}
|
||||
|
||||
@ -450,6 +452,7 @@ export function ChatActions(props: {
|
||||
|
||||
return (
|
||||
<div className={styles["chat-input-actions"]}>
|
||||
<div>
|
||||
{couldStop && (
|
||||
<ChatAction
|
||||
onClick={stopAll}
|
||||
@ -502,36 +505,21 @@ export function ChatActions(props: {
|
||||
icon={<MaskIcon />}
|
||||
/>
|
||||
|
||||
<ChatAction
|
||||
text={Locale.Chat.InputActions.Clear}
|
||||
icon={<BreakIcon />}
|
||||
onClick={() => {
|
||||
chatStore.updateCurrentSession((session) => {
|
||||
if (session.clearContextIndex === session.messages.length) {
|
||||
session.clearContextIndex = undefined;
|
||||
} else {
|
||||
session.clearContextIndex = session.messages.length;
|
||||
session.memoryPrompt = ""; // will clear memory
|
||||
}
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<ChatAction
|
||||
onClick={() => setShowModelSelector(true)}
|
||||
text={currentModel}
|
||||
icon={<RobotIcon />}
|
||||
/>
|
||||
|
||||
{/* <ChatAction
|
||||
onClick={switchUseTools}
|
||||
<ChatAction
|
||||
onClick={switchUsePlugins}
|
||||
text={
|
||||
useTools
|
||||
? Locale.Chat.InputActions.CloseTools
|
||||
: Locale.Chat.InputActions.OpenTools
|
||||
usePlugins
|
||||
? Locale.Chat.InputActions.DisablePlugins
|
||||
: Locale.Chat.InputActions.EnablePlugins
|
||||
}
|
||||
icon={useTools ? <SearchOpenIcon /> : <SearchCloseIcon />}
|
||||
/> */}
|
||||
icon={usePlugins ? <EnablePluginIcon /> : <DisablePluginIcon />}
|
||||
/>
|
||||
|
||||
{showModelSelector && (
|
||||
<Selector
|
||||
@ -552,6 +540,23 @@ export function ChatActions(props: {
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<ChatAction
|
||||
text={Locale.Chat.InputActions.Clear}
|
||||
icon={<BreakIcon />}
|
||||
onClick={() => {
|
||||
chatStore.updateCurrentSession((session) => {
|
||||
if (session.clearContextIndex === session.messages.length) {
|
||||
session.clearContextIndex = undefined;
|
||||
} else {
|
||||
session.clearContextIndex = session.messages.length;
|
||||
session.memoryPrompt = ""; // will clear memory
|
||||
}
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1198,7 +1203,7 @@ function _Chat() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{session.useTools &&
|
||||
{session.usePlugins &&
|
||||
!isUser &&
|
||||
message.toolMessages &&
|
||||
message.toolMessages.map((tool, index) => (
|
||||
|
Before Width: | Height: | Size: 963 B After Width: | Height: | Size: 963 B |
@ -58,8 +58,8 @@ const cn = {
|
||||
Masks: "所有面具",
|
||||
Clear: "清除聊天",
|
||||
Settings: "对话设置",
|
||||
OpenTools: "开启插件",
|
||||
CloseTools: "关闭插件",
|
||||
EnablePlugins: "开启插件",
|
||||
DisablePlugins: "关闭插件",
|
||||
},
|
||||
Rename: "重命名对话",
|
||||
Typing: "正在输入…",
|
||||
|
@ -60,8 +60,8 @@ const en: LocaleType = {
|
||||
Masks: "Masks",
|
||||
Clear: "Clear Context",
|
||||
Settings: "Settings",
|
||||
OpenTools: "Enable Plugins",
|
||||
CloseTools: "Disable Plugins",
|
||||
EnablePlugins: "Enable Plugins",
|
||||
DisablePlugins: "Disable Plugins",
|
||||
},
|
||||
Rename: "Rename Chat",
|
||||
Typing: "Typing…",
|
||||
|
@ -61,7 +61,7 @@ export interface ChatSession {
|
||||
clearContextIndex?: number;
|
||||
|
||||
mask: Mask;
|
||||
useTools: boolean;
|
||||
usePlugins: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_TOPIC = Locale.Store.DefaultTopic;
|
||||
@ -85,7 +85,7 @@ function createEmptySession(): ChatSession {
|
||||
lastSummarizeIndex: 0,
|
||||
|
||||
mask: createEmptyMask(),
|
||||
useTools: true,
|
||||
usePlugins: true,
|
||||
};
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ export const useChatStore = create<ChatStore>()(
|
||||
session.messages.push(botMessage);
|
||||
});
|
||||
|
||||
if (session.useTools && modelConfig.model.endsWith("0613")) {
|
||||
if (session.usePlugins) {
|
||||
console.log("[ToolAgent] start");
|
||||
api.llm.toolAgentChat({
|
||||
messages: sendMessages,
|
||||
|
Loading…
Reference in New Issue
Block a user