Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Use current model to generate summary title #1889

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 0 additions & 115 deletions src/chains/__tests__/summaryTitle.test.ts

This file was deleted.

11 changes: 3 additions & 8 deletions src/chains/summaryTitle.ts
@@ -1,8 +1,9 @@
import { chatHelpers } from '@/store/chat/helpers';
import { globalHelpers } from '@/store/global/helpers';
import { LobeAgentConfig } from '@/types/agent';
import { ChatStreamPayload, OpenAIChatMessage } from '@/types/openai/chat';

export const chainSummaryTitle = async (
agentConfig: LobeAgentConfig,
messages: OpenAIChatMessage[],
): Promise<Partial<ChatStreamPayload>> => {
const lang = globalHelpers.getCurrentLanguage();
Expand All @@ -19,15 +20,9 @@ export const chainSummaryTitle = async (
role: 'user',
},
];
// ε¦‚ζžœθΆ…θΏ‡ 16kοΌŒεˆ™δ½Ώη”¨ GPT-4-turbo ζ¨‘εž‹
const tokens = await chatHelpers.getMessagesTokenCount(finalMessages);
let model: string | undefined = undefined;
if (tokens > 16_000) {
model = 'gpt-4-turbo-preview';
}

return {
messages: finalMessages,
model,
...agentConfig,
};
};
7 changes: 6 additions & 1 deletion src/store/chat/slices/topic/action.ts
Expand Up @@ -14,6 +14,8 @@ import { chatService } from '@/services/chat';
import { messageService } from '@/services/message';
import { topicService } from '@/services/topic';
import { ChatStore } from '@/store/chat';
import { useSessionStore } from '@/store/session';
import { agentSelectors } from '@/store/session/selectors';
import { ChatMessage } from '@/types/message';
import { ChatTopic } from '@/types/topic';
import { setNamespace } from '@/utils/storeDebug';
Expand Down Expand Up @@ -46,6 +48,8 @@ export interface ChatTopicAction {
useSearchTopics: (keywords?: string) => SWRResponse<ChatTopic[]>;
}

const getAgentConfig = () => agentSelectors.currentAgentConfig(useSessionStore.getState());

export const chatTopic: StateCreator<
ChatStore,
[['zustand/devtools', never]],
Expand Down Expand Up @@ -100,6 +104,7 @@ export const chatTopic: StateCreator<
},
// update
summaryTopicTitle: async (topicId, messages) => {
const config = getAgentConfig();
const { updateTopicTitleInSummary, updateTopicLoading, refreshTopic } = get();
const topic = topicSelectors.getTopicById(topicId)(get());
if (!topic) return;
Expand All @@ -123,7 +128,7 @@ export const chatTopic: StateCreator<
output += x;
updateTopicTitleInSummary(topicId, output);
},
params: await chainSummaryTitle(messages),
params: await chainSummaryTitle(config, messages),
trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryTopicTitle, topicId }),
});
await refreshTopic();
Expand Down