Skip to content

Commit

Permalink
fix(core): handle empty additional_kwargs correctly in serialized mes…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
dingyi222666 committed Dec 28, 2024
1 parent bb8088b commit 4b3b4e4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/llm-core/memory/message/database_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,23 @@ export class KoishiChatMessageHistory extends BaseChatMessageHistory {
(item) => item.id === this._latestId
)

const additionalArgs = message.additional_kwargs
let additionalArgs = Object.assign({}, message.additional_kwargs)

if (additionalArgs?.['preset']) {
delete additionalArgs['preset']
}

if (Object.keys(additionalArgs).length === 0) {
additionalArgs = null
}

const serializedMessage: ChatLunaMessage = {
id: uuidv4(),
text: JSON.stringify(message.content),
parent: lastedMessage?.id ?? null,
role: message.getType(),
additional_kwargs: additionalArgs
? JSON.stringify(message.additional_kwargs)
? JSON.stringify(additionalArgs)
: null,
rawId: message.id ?? null,
conversation: this.conversationId
Expand Down

0 comments on commit 4b3b4e4

Please sign in to comment.