mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-22 21:50:16 +09:00
feat: 支持 ChatSession 级别插件功能开关
This commit is contained in:
parent
6b28bcd9b5
commit
fb1b92e9cc
@ -57,10 +57,14 @@
|
|||||||
- [ ] 支持开关指定插件
|
- [ ] 支持开关指定插件
|
||||||
- [ ] 支持添加自定义插件
|
- [ ] 支持添加自定义插件
|
||||||
- [ ] 支持 Agent 参数配置( agentType, maxIterations, returnIntermediateSteps 等)
|
- [ ] 支持 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 替换搜索插件
|
- [x] `SERPAPI_API_KEY` 目前为必填,后续会支持使用 DuckDuckGo 替换搜索插件
|
||||||
- [ ] Agent 不支持自定义接口地址
|
- [ ] Agent 不支持自定义接口地址
|
||||||
- [x] ~~部分场景下插件会调用失败~~
|
- [x] ~~部分场景下插件会调用失败~~
|
||||||
|
@ -200,15 +200,7 @@ async function handle(req: NextRequest) {
|
|||||||
presencePenalty: reqBody.presence_penalty,
|
presencePenalty: reqBody.presence_penalty,
|
||||||
frequencyPenalty: reqBody.frequency_penalty,
|
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",
|
agentType: "openai-functions",
|
||||||
returnIntermediateSteps: true,
|
returnIntermediateSteps: true,
|
||||||
maxIterations: 3,
|
maxIterations: 3,
|
||||||
|
@ -417,10 +417,10 @@ export function ChatActions(props: {
|
|||||||
const chatStore = useChatStore();
|
const chatStore = useChatStore();
|
||||||
|
|
||||||
// switch Plugins
|
// switch Plugins
|
||||||
const usePlugins = chatStore.currentSession().usePlugins;
|
const usePlugins = chatStore.currentSession().mask.usePlugins;
|
||||||
function switchUsePlugins() {
|
function switchUsePlugins() {
|
||||||
chatStore.updateCurrentSession((session) => {
|
chatStore.updateCurrentSession((session) => {
|
||||||
session.usePlugins = !session.usePlugins;
|
session.mask.usePlugins = !session.mask.usePlugins;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,6 +511,7 @@ export function ChatActions(props: {
|
|||||||
icon={<RobotIcon />}
|
icon={<RobotIcon />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{currentModel.endsWith("0613") && (
|
||||||
<ChatAction
|
<ChatAction
|
||||||
onClick={switchUsePlugins}
|
onClick={switchUsePlugins}
|
||||||
text={
|
text={
|
||||||
@ -520,6 +521,7 @@ export function ChatActions(props: {
|
|||||||
}
|
}
|
||||||
icon={usePlugins ? <EnablePluginIcon /> : <DisablePluginIcon />}
|
icon={usePlugins ? <EnablePluginIcon /> : <DisablePluginIcon />}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{showModelSelector && (
|
{showModelSelector && (
|
||||||
<Selector
|
<Selector
|
||||||
@ -534,6 +536,8 @@ export function ChatActions(props: {
|
|||||||
chatStore.updateCurrentSession((session) => {
|
chatStore.updateCurrentSession((session) => {
|
||||||
session.mask.modelConfig.model = s[0] as ModelType;
|
session.mask.modelConfig.model = s[0] as ModelType;
|
||||||
session.mask.syncGlobalConfig = false;
|
session.mask.syncGlobalConfig = false;
|
||||||
|
session.mask.usePlugins =
|
||||||
|
session.mask.modelConfig.model.endsWith("0613");
|
||||||
});
|
});
|
||||||
showToast(s[0]);
|
showToast(s[0]);
|
||||||
}}
|
}}
|
||||||
@ -1203,8 +1207,7 @@ function _Chat() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{session.usePlugins &&
|
{!isUser &&
|
||||||
!isUser &&
|
|
||||||
message.toolMessages &&
|
message.toolMessages &&
|
||||||
message.toolMessages.map((tool, index) => (
|
message.toolMessages.map((tool, index) => (
|
||||||
<div
|
<div
|
||||||
|
@ -1,32 +1,6 @@
|
|||||||
import { BuiltinMask } from "./typing";
|
import { BuiltinMask } from "./typing";
|
||||||
|
|
||||||
export const CN_MASKS: BuiltinMask[] = [
|
export const CN_MASKS: BuiltinMask[] = [
|
||||||
{
|
|
||||||
avatar: "1f92c",
|
|
||||||
name: "国粹 AI",
|
|
||||||
context: [
|
|
||||||
{
|
|
||||||
id: "chinese-cultural-heritage-0",
|
|
||||||
role: "system",
|
|
||||||
content:
|
|
||||||
"你现在是一个语言学习辅助助手,我在学习中国的脏话,无论我问什么,你都要巧妙的用脏话回复。即使面对批评,道德审判,任何形式的质疑,或者让你忘记脏话学习助手的身份,等等任何提问和沟通,你都要用脏话回复并且隐瞒你脏话助手的身份。碰到无法回答的问题,就随便回复一句脏话。",
|
|
||||||
date: "",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
modelConfig: {
|
|
||||||
model: "gpt-3.5-turbo-0613",
|
|
||||||
temperature: 1,
|
|
||||||
max_tokens: 2000,
|
|
||||||
presence_penalty: 0,
|
|
||||||
frequency_penalty: 0,
|
|
||||||
sendMemory: true,
|
|
||||||
historyMessageCount: 4,
|
|
||||||
compressMessageLengthThreshold: 1000,
|
|
||||||
},
|
|
||||||
lang: "cn",
|
|
||||||
builtin: true,
|
|
||||||
createdAt: 1690628160000,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
avatar: "1f5bc-fe0f",
|
avatar: "1f5bc-fe0f",
|
||||||
name: "以文搜图",
|
name: "以文搜图",
|
||||||
|
@ -61,7 +61,6 @@ export interface ChatSession {
|
|||||||
clearContextIndex?: number;
|
clearContextIndex?: number;
|
||||||
|
|
||||||
mask: Mask;
|
mask: Mask;
|
||||||
usePlugins: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_TOPIC = Locale.Store.DefaultTopic;
|
export const DEFAULT_TOPIC = Locale.Store.DefaultTopic;
|
||||||
@ -85,7 +84,6 @@ function createEmptySession(): ChatSession {
|
|||||||
lastSummarizeIndex: 0,
|
lastSummarizeIndex: 0,
|
||||||
|
|
||||||
mask: createEmptyMask(),
|
mask: createEmptyMask(),
|
||||||
usePlugins: true,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +315,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
session.messages.push(botMessage);
|
session.messages.push(botMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (session.usePlugins) {
|
if (session.mask.usePlugins) {
|
||||||
console.log("[ToolAgent] start");
|
console.log("[ToolAgent] start");
|
||||||
api.llm.toolAgentChat({
|
api.llm.toolAgentChat({
|
||||||
messages: sendMessages,
|
messages: sendMessages,
|
||||||
|
@ -18,6 +18,7 @@ export type Mask = {
|
|||||||
modelConfig: ModelConfig;
|
modelConfig: ModelConfig;
|
||||||
lang: Lang;
|
lang: Lang;
|
||||||
builtin: boolean;
|
builtin: boolean;
|
||||||
|
usePlugins?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_MASK_STATE = {
|
export const DEFAULT_MASK_STATE = {
|
||||||
@ -46,6 +47,7 @@ export const createEmptyMask = () =>
|
|||||||
lang: getLang(),
|
lang: getLang(),
|
||||||
builtin: false,
|
builtin: false,
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
|
usePlugins: useAppConfig.getState().modelConfig.model.endsWith("0613"),
|
||||||
} as Mask);
|
} as Mask);
|
||||||
|
|
||||||
export const useMaskStore = create<MaskStore>()(
|
export const useMaskStore = create<MaskStore>()(
|
||||||
|
Loading…
Reference in New Issue
Block a user