Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
14d9a124
Unverified
提交
14d9a124
authored
5月 13, 2025
作者:
Will Chen
提交者:
GitHub
5月 13, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Max chat turns settings (default to 5) (#152)
上级
d1a6b06f
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
142 行增加
和
3 行删除
+142
-3
MaxChatTurnsSelector.tsx
src/components/MaxChatTurnsSelector.tsx
+92
-0
settings_constants.ts
src/constants/settings_constants.ts
+1
-0
chat_stream_handlers.ts
src/ipc/handlers/chat_stream_handlers.ts
+41
-1
proposal_handlers.ts
src/ipc/handlers/proposal_handlers.ts
+2
-2
schemas.ts
src/lib/schemas.ts
+1
-0
settings.tsx
src/pages/settings.tsx
+5
-0
没有找到文件。
src/components/MaxChatTurnsSelector.tsx
0 → 100644
浏览文件 @
14d9a124
import
React
from
"react"
;
import
{
useSettings
}
from
"@/hooks/useSettings"
;
import
{
Select
,
SelectContent
,
SelectItem
,
SelectTrigger
,
SelectValue
,
}
from
"@/components/ui/select"
;
import
{
MAX_CHAT_TURNS_IN_CONTEXT
}
from
"@/constants/settings_constants"
;
interface
OptionInfo
{
value
:
string
;
label
:
string
;
description
:
string
;
}
const
defaultValue
=
"default"
;
const
options
:
OptionInfo
[]
=
[
{
value
:
"3"
,
label
:
"Economy (3)"
,
description
:
"Minimal context to reduce token usage and improve response times."
,
},
{
value
:
defaultValue
,
label
:
`Default (
${
MAX_CHAT_TURNS_IN_CONTEXT
}
) `
,
description
:
"Balanced context size for most conversations."
,
},
{
value
:
"10"
,
label
:
"High (10)"
,
description
:
"Extended context for complex conversations requiring more history."
,
},
{
value
:
"100"
,
label
:
"Max (100)"
,
description
:
"Maximum context (not recommended due to cost and speed)."
,
},
];
export
const
MaxChatTurnsSelector
:
React
.
FC
=
()
=>
{
const
{
settings
,
updateSettings
}
=
useSettings
();
const
handleValueChange
=
(
value
:
string
)
=>
{
if
(
value
===
"default"
)
{
updateSettings
({
maxChatTurnsInContext
:
undefined
});
}
else
{
const
numValue
=
parseInt
(
value
,
10
);
updateSettings
({
maxChatTurnsInContext
:
numValue
});
}
};
// Determine the current value
const
currentValue
=
settings
?.
maxChatTurnsInContext
?.
toString
()
||
defaultValue
;
// Find the current option to display its description
const
currentOption
=
options
.
find
((
opt
)
=>
opt
.
value
===
currentValue
)
||
options
[
1
];
return
(
<
div
className=
"space-y-1"
>
<
div
className=
"flex items-center gap-4"
>
<
label
htmlFor=
"max-chat-turns"
className=
"text-sm font-medium text-gray-700 dark:text-gray-300"
>
Maximum number of chat turns used in context
</
label
>
<
Select
value=
{
currentValue
}
onValueChange=
{
handleValueChange
}
>
<
SelectTrigger
className=
"w-[180px]"
id=
"max-chat-turns"
>
<
SelectValue
placeholder=
"Select turns"
/>
</
SelectTrigger
>
<
SelectContent
>
{
options
.
map
((
option
)
=>
(
<
SelectItem
key=
{
option
.
value
}
value=
{
option
.
value
}
>
{
option
.
label
}
</
SelectItem
>
))
}
</
SelectContent
>
</
Select
>
</
div
>
<
div
className=
"text-sm text-gray-500 dark:text-gray-400"
>
{
currentOption
.
description
}
</
div
>
</
div
>
);
};
src/constants/settings_constants.ts
0 → 100644
浏览文件 @
14d9a124
export
const
MAX_CHAT_TURNS_IN_CONTEXT
=
5
;
src/ipc/handlers/chat_stream_handlers.ts
浏览文件 @
14d9a124
...
...
@@ -28,6 +28,7 @@ import * as os from "os";
import
*
as
crypto
from
"crypto"
;
import
{
readFile
,
writeFile
,
unlink
}
from
"fs/promises"
;
import
{
getMaxTokens
}
from
"../utils/token_utils"
;
import
{
MAX_CHAT_TURNS_IN_CONTEXT
}
from
"@/constants/settings_constants"
;
const
logger
=
log
.
scope
(
"chat_stream_handlers"
);
...
...
@@ -241,6 +242,45 @@ export function registerChatStreamHandlers() {
role
:
message
.
role
as
"user"
|
"assistant"
|
"system"
,
content
:
message
.
content
,
}));
// Limit chat history based on maxChatTurnsInContext setting
// We add 1 because the current prompt counts as a turn.
const
maxChatTurns
=
(
settings
.
maxChatTurnsInContext
||
MAX_CHAT_TURNS_IN_CONTEXT
)
+
1
;
// If we need to limit the context, we take only the most recent turns
let
limitedMessageHistory
=
messageHistory
;
if
(
messageHistory
.
length
>
maxChatTurns
*
2
)
{
// Each turn is a user + assistant pair
// Calculate how many messages to keep (maxChatTurns * 2)
let
recentMessages
=
messageHistory
.
filter
((
msg
)
=>
msg
.
role
!==
"system"
)
.
slice
(
-
maxChatTurns
*
2
);
// Ensure the first message is a user message
if
(
recentMessages
.
length
>
0
&&
recentMessages
[
0
].
role
!==
"user"
)
{
// Find the first user message
const
firstUserIndex
=
recentMessages
.
findIndex
(
(
msg
)
=>
msg
.
role
===
"user"
,
);
if
(
firstUserIndex
>
0
)
{
// Drop assistant messages before the first user message
recentMessages
=
recentMessages
.
slice
(
firstUserIndex
);
}
else
if
(
firstUserIndex
===
-
1
)
{
logger
.
warn
(
"No user messages found in recent history, set recent messages to empty"
,
);
recentMessages
=
[];
}
}
limitedMessageHistory
=
[...
recentMessages
];
logger
.
log
(
`Limiting chat history from
${
messageHistory
.
length
}
to
${
limitedMessageHistory
.
length
}
messages (max
${
maxChatTurns
}
turns)`
,
);
}
let
systemPrompt
=
SYSTEM_PROMPT
;
if
(
updatedChat
.
app
?.
supabaseProjectId
&&
...
...
@@ -292,7 +332,7 @@ This conversation includes one or more image attachments. When the user uploads
role
:
"assistant"
,
content
:
"OK, got it. I'm ready to help"
,
},
...
m
essageHistory
.
map
((
msg
)
=>
({
...
limitedM
essageHistory
.
map
((
msg
)
=>
({
role
:
msg
.
role
as
"user"
|
"assistant"
|
"system"
,
content
:
msg
.
content
,
})),
...
...
src/ipc/handlers/proposal_handlers.ts
浏览文件 @
14d9a124
...
...
@@ -285,9 +285,9 @@ const getProposalHandler = async (
);
// If we're using more than 80% of the context window, suggest summarizing
if
(
totalTokens
>
contextWindow
*
0.8
)
{
if
(
totalTokens
>
contextWindow
*
0.8
||
chat
.
messages
.
length
>
10
)
{
logger
.
log
(
`Token usage
high (
${
totalTokens
}
/
${
contextWindow
}
), suggesting summarize action`
,
`Token usage
is high (
${
totalTokens
}
/
${
contextWindow
}
) OR long chat history (
${
chat
.
messages
.
length
}
messages
), suggesting summarize action`
,
);
actions
.
push
({
id
:
"summarize-in-new-chat"
,
...
...
src/lib/schemas.ts
浏览文件 @
14d9a124
...
...
@@ -117,6 +117,7 @@ export const UserSettingsSchema = z.object({
dyadProBudget
:
DyadProBudgetSchema
.
optional
(),
experiments
:
ExperimentsSchema
.
optional
(),
lastShownReleaseNotesVersion
:
z
.
string
().
optional
(),
maxChatTurnsInContext
:
z
.
number
().
optional
(),
// DEPRECATED.
runtimeMode
:
RuntimeModeSchema
.
optional
(),
});
...
...
src/pages/settings.tsx
浏览文件 @
14d9a124
...
...
@@ -6,6 +6,7 @@ import { IpcClient } from "@/ipc/ipc_client";
import
{
showSuccess
,
showError
}
from
"@/lib/toast"
;
import
{
AutoApproveSwitch
}
from
"@/components/AutoApproveSwitch"
;
import
{
TelemetrySwitch
}
from
"@/components/TelemetrySwitch"
;
import
{
MaxChatTurnsSelector
}
from
"@/components/MaxChatTurnsSelector"
;
import
{
useSettings
}
from
"@/hooks/useSettings"
;
import
{
useAppVersion
}
from
"@/hooks/useAppVersion"
;
import
{
Button
}
from
"@/components/ui/button"
;
...
...
@@ -106,6 +107,10 @@ export default function SettingsPage() {
This will automatically approve code changes and run them.
</
div
>
</
div
>
<
div
className=
"mt-4"
>
<
MaxChatTurnsSelector
/>
</
div
>
</
div
>
<
div
className=
"bg-white dark:bg-gray-800 rounded-xl shadow-sm"
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论