Skip to content

Commit 8670a76

Browse files
authored
Merge pull request #74 from CookSleep/fix/drop-legacy-tool-call-reply
fix(config): 废弃顶层工具调用回复配置
2 parents f857957 + f887e55 commit 8670a76

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export interface Config extends ChatLunaPlugin.Config {
4747
markdownRender: boolean
4848

4949
toolCalling: boolean
50-
experimentalToolCallReply: boolean
5150
toolCallReplyThinkTag: boolean
5251
toolCallReplyStatusTag: boolean
5352
toolCallReplyNextReply: boolean
@@ -668,7 +667,6 @@ type CommonMigration = {
668667
| 'imageInputMaxSize'
669668
| 'multimodalFileInputMaxSize'
670669
| 'toolCalling'
671-
| 'experimentalToolCallReply'
672670
| 'isForceMute'
673671
| 'coolDownTime'
674672
| 'splitVoice'
@@ -724,11 +722,6 @@ const commonMigrations: CommonMigration[] = [
724722
groupDefault: true,
725723
onlyFalse: true
726724
},
727-
{
728-
key: 'experimentalToolCallReply',
729-
privateDefault: false,
730-
groupDefault: false
731-
},
732725
{
733726
key: 'isForceMute',
734727
privateDefault: true,

src/plugins/chat.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { ComputedRef } from 'koishi-plugin-chatluna'
4848
let logger: Logger
4949

5050
type ParsedResponse = Awaited<ReturnType<typeof parseResponse>>
51+
type RuntimeConfig = Config & (GuildConfig | PrivateConfig)
5152
type StreamedParsedResponseChunk = StreamedModelResponseChunk<ParsedResponse>
5253

5354
interface StreamedResponseContentChunk {
@@ -578,7 +579,7 @@ function createReplyTools(
578579
]
579580
}
580581

581-
function formatReplyUserPrompt(session: Session, config: Config) {
582+
function formatReplyUserPrompt(session: Session, config: RuntimeConfig) {
582583
if (!config.experimentalToolCallReply || !config.toolCalling) {
583584
return ''
584585
}
@@ -911,7 +912,7 @@ function stripInternalTriggerTags(content: string) {
911912
async function parseResponseContent(
912913
ctx: Context,
913914
session: Session,
914-
config: Config,
915+
config: RuntimeConfig,
915916
chunk: StreamedResponseContentChunk
916917
): Promise<StreamedParsedResponseChunk> {
917918
let parsedResponse: ParsedResponse
@@ -1033,7 +1034,7 @@ async function* streamAgentResponseContents(
10331034
chain: ChatLunaChain,
10341035
session: Session,
10351036
model: ChatLunaChatModel,
1036-
config: Config,
1037+
config: RuntimeConfig,
10371038
presetName: string,
10381039
systemMessage: BaseMessage | undefined,
10391040
historyMessages: BaseMessage[],
@@ -1115,7 +1116,7 @@ async function registerResponseTriggers(
11151116
ctx: Context,
11161117
session: Session,
11171118
key: string,
1118-
config: Config,
1119+
config: RuntimeConfig,
11191120
nextReplyReasons: string[],
11201121
wakeUpReplies: ReturnType<typeof extractWakeUpReplies>
11211122
) {
@@ -1263,18 +1264,25 @@ async function getConfigAndPresetForGuild(
12631264
presetPool: Record<string, PresetTemplate>,
12641265
key: string,
12651266
preset: Preset
1266-
): Promise<{ copyOfConfig: Config; currentPreset: PresetTemplate }> {
1267+
): Promise<{ copyOfConfig: RuntimeConfig; currentPreset: PresetTemplate }> {
12671268
const globalConfig = isDirect
12681269
? config.globalPrivateConfig
12691270
: config.globalGroupConfig
12701271
const currentGuildConfig = isDirect
12711272
? config.privateConfigs[guildId]
12721273
: config.configs[guildId]
1273-
let copyOfConfig = Object.assign({}, config, globalConfig)
1274+
let copyOfConfig = Object.assign({}, config, globalConfig, {
1275+
experimentalToolCallReply:
1276+
globalConfig.experimentalToolCallReply === true
1277+
}) as RuntimeConfig
12741278
let currentPreset = isDirect ? globalPrivatePreset : globalGroupPreset
12751279

12761280
if (currentGuildConfig) {
1277-
copyOfConfig = Object.assign({}, copyOfConfig, currentGuildConfig)
1281+
copyOfConfig = Object.assign(
1282+
{},
1283+
copyOfConfig,
1284+
currentGuildConfig
1285+
) as RuntimeConfig
12781286
currentPreset =
12791287
presetPool[key] ??
12801288
(await (async () => {
@@ -1296,7 +1304,7 @@ async function getConfigAndPresetForGuild(
12961304
async function prepareMessages(
12971305
ctx: Context,
12981306
messages: Message[],
1299-
config: Config,
1307+
config: RuntimeConfig,
13001308
session: Session,
13011309
model: ChatLunaChatModel,
13021310
currentPreset: PresetTemplate,
@@ -1526,7 +1534,7 @@ async function* streamModelResponse(
15261534
session: Session,
15271535
model: ChatLunaChatModel,
15281536
completionMessages: BaseMessage[],
1529-
config: Config,
1537+
config: RuntimeConfig,
15301538
presetName: string,
15311539
chain?: ChatLunaChain,
15321540
signal?: AbortSignal,
@@ -1648,7 +1656,7 @@ async function handleMessageSending(
16481656
elements: h[],
16491657
text: string,
16501658
parsedResponse: Awaited<ReturnType<typeof parseResponse>>,
1651-
config: Config,
1659+
config: RuntimeConfig,
16521660
ctx: Context,
16531661
maxTime: number,
16541662
emoticonStatement: string,
@@ -1727,7 +1735,7 @@ async function handleMessageSending(
17271735

17281736
async function handleParsedResponseChunk(
17291737
session: Session,
1730-
config: Config,
1738+
config: RuntimeConfig,
17311739
ctx: Context,
17321740
parsedResponse: ParsedResponse
17331741
): Promise<{

0 commit comments

Comments
 (0)