diff --git a/src/apis/index.ts b/src/apis/index.ts index 5562d4bf115e46f3679a1d420989585650130099..9791c928b8a2eb230a416d6b7a2b9f1efc048077 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -17,6 +17,7 @@ import { apiApi, modelApi, mcpApi, + llmApi, } from './paths'; import { workFlowApi } from './workFlow'; import { appCenterApi, promptApi, kbApi } from './appCenter'; @@ -33,6 +34,7 @@ export const api = { ...apiApi, ...modelApi, ...mcpApi, + ...llmApi, ...promptApi, ...kbApi, }; diff --git a/src/apis/paths/conversation.ts b/src/apis/paths/conversation.ts index b8dd3c345ead1bf4793692fad07933a836d64f24..56cc14442005dbec757879161c29af23885c8f76 100644 --- a/src/apis/paths/conversation.ts +++ b/src/apis/paths/conversation.ts @@ -37,7 +37,17 @@ export const getSessionRecord = (): Promise< * 创建一个会话 * @returns */ -export const createSession = (): Promise< +export const createSession = ({ + appId, + debug = false, + llm_id = '', + kb_ids = [], +}: { + appId: string; + debug?: boolean; + llm_id?: string; + kb_ids?: string[]; +}): Promise< [ any, ( @@ -48,7 +58,7 @@ export const createSession = (): Promise< ), ] > => { - return post(BASE_URL); + return post(BASE_URL,{appId,debug},{llm_id,kb_ids}); }; /** diff --git a/src/apis/paths/index.ts b/src/apis/paths/index.ts index 786e662db6b4bb1970a829822c1fd6813d4b7da2..ddf41fa545611e17388959db525a4f5b42c43619 100644 --- a/src/apis/paths/index.ts +++ b/src/apis/paths/index.ts @@ -16,3 +16,4 @@ export * from './app'; export * from './api'; export * from './model'; export * from './mcp'; +export * from './llm'; diff --git a/src/apis/paths/knowledge.ts b/src/apis/paths/knowledge.ts index 7ce9d72b5b0cbe3e7a809ae4bcdc4708f02fb6fa..7ec1e225e78b44052bccd1759ee342919ee972f0 100644 --- a/src/apis/paths/knowledge.ts +++ b/src/apis/paths/knowledge.ts @@ -7,19 +7,31 @@ // IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR // PURPOSE. // See the Mulan PSL v2 for more details. -import { get, post } from 'src/apis/server'; +import { get, post, put } from 'src/apis/server'; import type { FcResponse } from 'src/apis/server'; /** - * USER登录 + * updateKnowledgeList * @returns */ -export const updateKnowledgeList = (params: { - kb_id: string; +export const updateKnowledgeList = ({ + kb_ids, + conversationId, +}: { + kb_ids: string[]; + conversationId: string; }): Promise<[any, FcResponse<{}> | undefined]> => { - return post('/api/knowledge', params); + return put('/api/knowledge', {kb_ids} , { conversationId }); +}; + +export const getConvKnowledgeList = (params:{ + conversationId: string; + kbName?: string; +}): Promise<[any, FcResponse<{}> | undefined]> => { + return get('/api/knowledge',params); }; export const knowledgeApi = { updateKnowledgeList, + getConvKnowledgeList, }; diff --git a/src/apis/paths/llm.ts b/src/apis/paths/llm.ts new file mode 100644 index 0000000000000000000000000000000000000000..393541838023af0151f3743f1b2a905da2d123ab --- /dev/null +++ b/src/apis/paths/llm.ts @@ -0,0 +1,41 @@ +import { get, post, del, put } from '../server'; +import { addedModalList } from './type'; +/** + * 获取用户的模型列表 + * @returns + */ +const getLLMList = () => { + return get< + { + id: string; + icon: string; + openaiBaseUrl: string; + openaiApiKey: string; + modelName: string; + maxTokens: number; + }[] + >('/api/llm'); +}; + +/** + * 获取用户的模型列表 + * @returns + */ +const updateLLMList = ({ conversationId, llmId }) => { + return put('/api/llm/conv', { conversationId, llmId:[llmId.llmId] }); +}; + +/** + * 获取已添加模型列表 + */ +const getAddedModels = () => { + return get<{ + models: addedModalList[]; + }>('/api/model'); +}; + +export const llmApi = { + getAddedModels, + getLLMList, + updateLLMList, +}; diff --git a/src/apis/paths/model.ts b/src/apis/paths/model.ts index 5b26f71e80bff95917c2bc519d7d0144eaa5b5f3..9e3d7c33a4424fbb7ae83169cfd80fbf06218124 100644 --- a/src/apis/paths/model.ts +++ b/src/apis/paths/model.ts @@ -54,9 +54,6 @@ const getModelProviderList = () => { >('/api/llm/provider'); }; -const getKnowledgeList = (conversationId?: string) => { - return post('/api/kb', { conversationId }); -}; const getAllModels = (searchKey: string) => { return get<{ @@ -114,6 +111,5 @@ export const modelApi = { createOrUpdateModel, getAllModels, deleteModel, - getKnowledgeList, getModelById, }; diff --git a/src/apis/paths/type.ts b/src/apis/paths/type.ts index f420fb2135728334113d9b894f8e4a481456fe03..14478d83b537a2e94bb95360d1c44b7962d8831f 100644 --- a/src/apis/paths/type.ts +++ b/src/apis/paths/type.ts @@ -86,6 +86,10 @@ export interface ConversationListItem { createdTime: string; docCount: number; title: string; + llm:{ + icon: string; + modelName: string; + } } /* diff --git a/src/components/sessionCard/type.ts b/src/components/sessionCard/type.ts index e8b0bd7d2012da07c94a830de117122d722008ab..825c80951820048f6b6e561453c4aaaed3b89a3f 100644 --- a/src/components/sessionCard/type.ts +++ b/src/components/sessionCard/type.ts @@ -19,5 +19,14 @@ export interface SessionItem { appId?: string; debug?: boolean; model?: AddedModalList; + llm?:{ + icon: string; + modelName: string; + } kbList?: teamKnowledgeList[]; } +// 新增接口 +export interface modelItem { + icon: string; + modelName: string; +} diff --git a/src/store/historySession.ts b/src/store/historySession.ts index 947750cb313f31ccff73f8416bb570a741bcdcac..162c3779d33e318e14b4fa458136ebab6a95d2a5 100644 --- a/src/store/historySession.ts +++ b/src/store/historySession.ts @@ -29,8 +29,8 @@ export const useHistorySessionStore = defineStore( // 历史会话列表 const historySession = ref([]); const params = ref(); - const user_selected_app = ref(); - const selectMode = ref([]); + const user_selected_app = ref(); + const selectLLM= ref(); const currentSelectedSession = ref(''); /** * 选择历史会话 @@ -77,6 +77,18 @@ export const useHistorySessionStore = defineStore( selectedSessionIds.value = []; } }; + /** + * 获取当前 llm 模型的数值 + */ + const currentLLM = async() => { + console.log(currentSelectedSession.value); + await getHistorySession(); + historySession.value.forEach((item) => { + if (item.conversationId === currentSelectedSession.value) { + selectLLM.value = item.llm; + } + }) + }; /** * 选中某个会话 * @param conversationId 会话id @@ -120,6 +132,7 @@ export const useHistorySessionStore = defineStore( createdTime: item.createdTime, title: item.title, docCount: item.docCount || 0, + llm: item.llm || {}, })); if (res.result.conversations.length === 0) { await generateSession(); @@ -127,6 +140,7 @@ export const useHistorySessionStore = defineStore( if (!currentSelectedSession.value) { currentSelectedSession.value = res.result.conversations[0]?.conversationId; + //----- } if (currentSelectedSession.value) { const { getConversation, isAnswerGenerating } = useSessionStore(); @@ -188,7 +202,7 @@ export const useHistorySessionStore = defineStore( * 创建一个新的会话 */ const generateSession = async (): Promise => { - const [_, res] = await api.createSession(); + const [_, res] = await api.createSession(user_selected_app.value); if (!_ && res) { currentSelectedSession.value = res.result.conversationId; await getHistorySession(); @@ -224,7 +238,8 @@ export const useHistorySessionStore = defineStore( generateSession, generateSessionDebug, user_selected_app, - selectMode, + selectLLM, + currentLLM, }; }, { diff --git a/src/views/dialogue/components/DialogueAside.vue b/src/views/dialogue/components/DialogueAside.vue index 3b4bc6fcf814f3ee5595156edd81241d52709491..976c1749eee3d0bf0db2aafcf53fab00598d7f66 100644 --- a/src/views/dialogue/components/DialogueAside.vue +++ b/src/views/dialogue/components/DialogueAside.vue @@ -50,7 +50,7 @@ const { currentSelectedSession, } = storeToRefs(useHistorySessionStore()); const { app, appList } = storeToRefs(useSessionStore()); -const { getHistorySession, createNewSession } = useHistorySessionStore(); +const { getHistorySession, createNewSession, currentLLM } = useHistorySessionStore(); const { userinfo } = storeToRefs(useAccountStore()); const deleteType = ref(true); // 搜索的关键词 @@ -125,6 +125,7 @@ function checkDate(date: string | Date): string { onMounted(() => { getHistorySession(); + currentLLM(); }); const deletedSessionName = ref(''); diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index 5d167573bfe643f9da378c72182e7065ecda08f7..73c54bcf205aa09be3ee38245facde58d99033bb 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -4,11 +4,9 @@ import DialoguePanel from 'src/components/dialoguePanel/DialoguePanel.vue'; import UploadFileGroup from 'src/components/uploadFile/UploadFileGroup.vue'; import InitalPanel from 'src/views/dialogue/components/InitalPanel.vue'; import InterPreview from 'src/views/dialogue/components/InterPreview.vue'; -import MultiSelectTags from'src/views/dialogue/components/MultiSelectTags.vue'; +import MultiSelectTags from 'src/views/dialogue/components/MultiSelectTags.vue'; import { storeToRefs } from 'pinia'; -import { - IconCaretRight, -} from '@computing/opendesign-icons'; +import { IconCaretRight } from '@computing/opendesign-icons'; import { useSessionStore, useChangeThemeStore } from 'src/store'; import type { ConversationItem, RobotConversationItem } from '../types'; import type { UploadFileCard } from 'src/components/uploadFile/type.ts'; @@ -18,7 +16,7 @@ import { api } from 'src/apis'; import { useHistorySessionStore } from 'src/store/historySession'; import { successMsg, errorMsg } from 'src/components/Message'; import i18n from 'src/i18n'; -const { user_selected_app, selectMode } = storeToRefs(useHistorySessionStore()); +const { user_selected_app, selectLLM } = storeToRefs(useHistorySessionStore()); const { getHistorySession } = useHistorySessionStore(); export interface DialogueSession { @@ -33,12 +31,12 @@ const knowledgeList = ref(); const { pausedStream } = useSessionStore(); const themeStore = useChangeThemeStore(); const isCreateApp = ref(props?.isCreateApp); -const selectedModal = ref({}); -const handleChangeMode = (val: string) => { - selectedModal.value = val; -} +const selectedLLM = ref({}); +const handleChangeMode = (val: string) => { + selectedLLM.value = val; + }; // const isCreateApp = ref(true); -const modeOptions = ref([]); +const llmOptions = ref([]); const { app } = storeToRefs(useSessionStore()); const questions = [ { @@ -191,11 +189,16 @@ const handleSendMessage = async ( await generateSession(); } // 更新当前的会话模型和知识库列表 - await api.updateModelAndKnowLedgeList({ - conversationId: currentSelectedSession.value, - modelId: selectMode.value[0], - kbIds:knowledgeList.value, - }) + await Promise.all([ + await api.updateKnowledgeList({ + kb_ids: knowledgeList.value, + conversationId: currentSelectedSession.value, + }), + await api.updateLLMList({ + conversationId: currentSelectedSession.value, + llmId: selectedLLM.value, + }), + ]); if (user_selected_flow) { await sendQuestion( groupId, @@ -251,10 +254,14 @@ const inputRef = ref(null); * @param type * @param cid */ -const handleReport = async (qaRecordId: string,reason_type:string,reason: string) => { +const handleReport = async ( + qaRecordId: string, + reason_type: string, + reason: string, +) => { const params: { qaRecordId: string; - reason_type:string; + reason_type: string; reason: string; } = { reason_type: reason_type, @@ -509,7 +516,7 @@ const isSameSession = (sessionId, curSessionId): boolean => { const handleUpdate = (kbList: any[]): void => { // 获取 knowledgeList 列表 knowledgeList.value = kbList; -} +}; // 上传文件(用户操作可能分批次) const updateFilesInSession = async ( @@ -608,27 +615,41 @@ const clearSuggestion = (index: number): void => { } }; -const getAddedModalList = async() => { - const [_, res] = await api.getAddedModels(); - if(!_ && res && res.code === 200) { - modeOptions.value = res.result.models; +const getProviderLLM = async () => { + const [_, res] = await api.getLLMList(); + if (!_ && res && res.code === 200) { + llmOptions.value = res.result; } -} +}; onMounted(() => { // 数据初始化 AppForm.value = props.createAppForm; if (!inputRef.value) return; inputRef.value.focus(); - getAddedModalList(); + getProviderLLM(); +}); + +watch(selectLLM, (newValue) => { + console.log(selectLLM); + if (newValue) { + selectedLLM.value.modalName = newValue.modelName; + selectedLLM.value.icon = newValue.icon; + console.log(selectedLLM.value); + selectedLLM.value = { ...selectLLM.value }; + } }); -watch(currentSelectedSession, (newValue, oldValue) => { - // 更新选择 mode - selectMode.value = []; -},{ - immediate: true, -}) +watch( + currentSelectedSession, + (newValue, oldValue) => { + // 更新选择 mode + selectedLLM.value = []; + }, + { + immediate: true, + }, +); const selectQuestion = (val: any) => { dialogueInput.value = val; @@ -668,8 +689,7 @@ const getappMode = (appId: string) => { watch( () => user_selected_app, (val) => { - if(app.value){ - console.log(app.value.appId); + if (app.value) { user_selected_app.value = app.value.appId; } if (user_selected_app.value && !isCreateApp.value) { @@ -723,9 +743,7 @@ watch( :isCommentList=" item.belong === 'robot' ? item.messageList.getCommentList() : '' " - :messageArray=" - item.belong === 'robot' ? item.messageList : '' - " + :messageArray="item.belong === 'robot' ? item.messageList : ''" :is-finish="getItem(item, 'isFinish')" :test="getItem(item, 'test')" :metadata="getItem(item, 'metadata')" @@ -777,39 +795,50 @@ watch(
-
- - - - - -
- +
+ + + + +
+ +
@@ -893,10 +922,10 @@ watch(