-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
133 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE "topics" ADD COLUMN "summary" text;--> statement-breakpoint | ||
ALTER TABLE "topics" ADD COLUMN "metadata" jsonb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useAgentStore } from '@/store/agent'; | ||
import { agentSelectors } from '@/store/agent/selectors'; | ||
|
||
export const getAgentConfig = () => agentSelectors.currentAgentConfig(useAgentStore.getState()); | ||
export const getAgentChatConfig = () => | ||
agentSelectors.currentAgentChatConfig(useAgentStore.getState()); | ||
|
||
export const getAgentKnowledge = () => | ||
agentSelectors.currentEnabledKnowledge(useAgentStore.getState()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { StateCreator } from 'zustand/vanilla'; | ||
|
||
import { summaryHistory } from '@/chains/summaryHistory'; | ||
import { chatService } from '@/services/chat'; | ||
import { topicService } from '@/services/topic'; | ||
import { ChatStore } from '@/store/chat'; | ||
import { useUserStore } from '@/store/user'; | ||
import { systemAgentSelectors } from '@/store/user/selectors'; | ||
import { ChatMessage } from '@/types/message'; | ||
|
||
import { getAgentConfig } from './helpers'; | ||
|
||
export interface ChatMemoryAction { | ||
internal_summaryHistory: (messages: ChatMessage[]) => Promise<void>; | ||
} | ||
|
||
export const chatMemory: StateCreator< | ||
ChatStore, | ||
[['zustand/devtools', never]], | ||
[], | ||
ChatMemoryAction | ||
> = (set, get) => ({ | ||
internal_summaryHistory: async (messages) => { | ||
const topicId = get().activeTopicId; | ||
if (messages.length <= 1 || !topicId) return; | ||
|
||
const { model, provider } = getAgentConfig(); | ||
|
||
const historyCompressConfig = systemAgentSelectors.historyCompress(useUserStore.getState()); | ||
|
||
let historySummary = ''; | ||
await chatService.fetchPresetTaskResult({ | ||
onFinish: async (text) => { | ||
historySummary = text; | ||
}, | ||
|
||
params: { | ||
...summaryHistory(messages), | ||
model: historyCompressConfig.model, | ||
provider: historyCompressConfig.provider, | ||
stream: false, | ||
}, | ||
}); | ||
|
||
await topicService.updateTopic(topicId, { | ||
metadata: { model, provider }, | ||
summary: historySummary, | ||
}); | ||
await get().refreshTopic(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters