mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-29 09:44:47 +00:00
perf: response tag;feat: history quote
This commit is contained in:
@@ -63,6 +63,7 @@ export const dispatchChatCompletion = async (props: Record<string, any>): Promis
|
||||
}
|
||||
|
||||
const { filterQuoteQA, quotePrompt } = filterQuote({
|
||||
history,
|
||||
quoteQA,
|
||||
model: modelConstantsData
|
||||
});
|
||||
@@ -181,23 +182,32 @@ export const dispatchChatCompletion = async (props: Record<string, any>): Promis
|
||||
};
|
||||
|
||||
function filterQuote({
|
||||
history = [],
|
||||
quoteQA = [],
|
||||
model
|
||||
}: {
|
||||
history: ChatProps['history'];
|
||||
quoteQA: ChatProps['quoteQA'];
|
||||
model: ChatModelItemType;
|
||||
}) {
|
||||
// concat history quote
|
||||
const historyQuote =
|
||||
history[history.length - 1]?.responseData
|
||||
?.find((item) => item.moduleName === ChatModuleEnum.AIChat)
|
||||
?.quoteList?.filter((item) => !quoteQA.find((quote) => quote.id === item.id)) || [];
|
||||
const concatQuote = quoteQA.concat(historyQuote.slice(0, 3));
|
||||
|
||||
const sliceResult = modelToolMap.tokenSlice({
|
||||
model: model.model,
|
||||
maxToken: model.quoteMaxToken,
|
||||
messages: quoteQA.map((item, i) => ({
|
||||
messages: concatQuote.map((item, i) => ({
|
||||
obj: ChatRoleEnum.System,
|
||||
value: item.a ? `{instruction:${item.q},output:${item.a}}` : `{instruction:${item.q}}`
|
||||
}))
|
||||
});
|
||||
|
||||
// slice filterSearch
|
||||
const filterQuoteQA = quoteQA.slice(0, sliceResult.length);
|
||||
const filterQuoteQA = concatQuote.slice(0, sliceResult.length);
|
||||
|
||||
const quotePrompt =
|
||||
filterQuoteQA.length > 0
|
||||
|
@@ -9,7 +9,6 @@ import { PgTrainingTableName } from '@/constants/plugin';
|
||||
|
||||
type KBSearchProps = {
|
||||
kbList: SelectedKbType;
|
||||
history: ChatItemType[];
|
||||
similarity: number;
|
||||
limit: number;
|
||||
userChatInput: string;
|
||||
@@ -22,13 +21,7 @@ export type KBSearchResponse = {
|
||||
};
|
||||
|
||||
export async function dispatchKBSearch(props: Record<string, any>): Promise<KBSearchResponse> {
|
||||
const {
|
||||
kbList = [],
|
||||
history = [],
|
||||
similarity = 0.8,
|
||||
limit = 5,
|
||||
userChatInput
|
||||
} = props as KBSearchProps;
|
||||
const { kbList = [], similarity = 0.8, limit = 5, userChatInput } = props as KBSearchProps;
|
||||
|
||||
if (kbList.length === 0) {
|
||||
return Promise.reject("You didn't choose the knowledge base");
|
||||
|
Reference in New Issue
Block a user