diff --git a/api/core/model_runtime/model_providers/vertex_ai/llm/gemini-2.0-flash-001.yaml b/api/core/model_runtime/model_providers/vertex_ai/llm/gemini-2.0-flash-001.yaml index bef7ca5eef..494f5aa68e 100644 --- a/api/core/model_runtime/model_providers/vertex_ai/llm/gemini-2.0-flash-001.yaml +++ b/api/core/model_runtime/model_providers/vertex_ai/llm/gemini-2.0-flash-001.yaml @@ -5,11 +5,6 @@ model_type: llm features: - agent-thought - vision - - tool-call - - stream-tool-call - - document - - video - - audio model_properties: mode: chat context_size: 1048576 @@ -20,20 +15,21 @@ parameter_rules: use_template: top_p - name: top_k label: - zh_Hans: 取样数量 en_US: Top k type: int help: - zh_Hans: 仅从每个后续标记的前 K 个选项中采样。 en_US: Only sample from the top K options for each subsequent token. required: false + - name: presence_penalty + use_template: presence_penalty + - name: frequency_penalty + use_template: frequency_penalty - name: max_output_tokens use_template: max_tokens + required: true default: 8192 min: 1 max: 8192 - - name: json_schema - use_template: json_schema pricing: input: '0.00' output: '0.00' diff --git a/web/app/components/base/chat/utils.ts b/web/app/components/base/chat/utils.ts index ce7a7c09b3..4539e88d0e 100644 --- a/web/app/components/base/chat/utils.ts +++ b/web/app/components/base/chat/utils.ts @@ -1,6 +1,8 @@ import { UUID_NIL } from './constants' import type { IChatItem } from './chat/type' import type { ChatItem, ChatItemInTree } from './types' +import { addFileInfos, sortAgentSorts } from '../../tools/utils' +import { getProcessedFilesFromResponse } from '../file-uploader/utils' async function decodeBase64AndDecompress(base64String: string) { const binaryString = atob(base64String) @@ -19,6 +21,60 @@ function getProcessedInputsFromUrlParams(): Record { return inputs } +function appendQAToChatList(chatList: ChatItem[], item: any) { + // we append answer first and then question since will reverse the whole chatList later + const answerFiles = item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [] + chatList.push({ + id: item.id, + content: item.answer, + agent_thoughts: addFileInfos(item.agent_thoughts ? sortAgentSorts(item.agent_thoughts) : item.agent_thoughts, item.message_files), + feedback: item.feedback, + isAnswer: true, + citation: item.retriever_resources, + message_files: getProcessedFilesFromResponse(answerFiles.map((item: any) => ({ ...item, related_id: item.id }))), + }) + const questionFiles = item.message_files?.filter((file: any) => file.belongs_to === 'user') || [] + chatList.push({ + id: `question-${item.id}`, + content: item.query, + isAnswer: false, + message_files: getProcessedFilesFromResponse(questionFiles.map((item: any) => ({ ...item, related_id: item.id }))), + }) +} + +/** + * Computes the latest thread messages from all messages of the conversation. + * Same logic as backend codebase `api/core/prompt/utils/extract_thread_messages.py` + * + * @param fetchedMessages - The history chat list data from the backend, sorted by created_at in descending order. This includes all flattened history messages of the conversation. + * @returns An array of ChatItems representing the latest thread. + */ + + +function getPrevChatList(fetchedMessages: any[]) { + const ret: ChatItem[] = [] + let nextMessageId = null + + for (const item of fetchedMessages) { + if (!item.parent_message_id) { + appendQAToChatList(ret, item) + break + } + + if (!nextMessageId) { + appendQAToChatList(ret, item) + nextMessageId = item.parent_message_id + } + else { + if (item.id === nextMessageId || nextMessageId === UUID_NIL) { + appendQAToChatList(ret, item) + nextMessageId = item.parent_message_id + } + } + } + return ret.reverse() +} + function isValidGeneratedAnswer(item?: ChatItem | ChatItemInTree): boolean { return !!item && item.isAnswer && !item.id.startsWith('answer-placeholder-') && !item.isOpeningStatement } @@ -164,6 +220,7 @@ function getThreadMessages(tree: ChatItemInTree[], targetMessageId?: string): Ch export { getProcessedInputsFromUrlParams, isValidGeneratedAnswer, + getPrevChatList, getLastAnswer, buildChatItemTree, getThreadMessages,