diff --git a/src/App.vue b/src/App.vue index 43c89fac36ad70e4e247cc5959c1672c9229f03a..ba187709417e13f774b394ea6e15be3fdc6fa28c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,74 +1,41 @@ <template> <div class="w-full h-screen"> <!-- toolbar --> - <div class="w-full h-14 pt-2 border-b-2 shadow-2xl text-center fixed bg-slate-200"> - <a href="#/llm-rep/app/"> + <div class="w-full h-14 pt-2 border-b-2 shadow-2xl fixed bg-slate-200 flex items-center"> + + <div class="flex-none w-1/3"> + + </div> + <div class="flex-none w-1/3 text-center"> + <span class="leading-10 font-bold">{{ name }} {{ config?.mode === 'completions' ? 'ï¼ˆæ— ä¸Šä¸‹æ–‡ï¼‰' : '' }}</span> + + </div> + <div class="flex-none w-1/3 *:ml-4 *:text-gray-600 *:hover:text-gray-900 text-sm float-right flex justify-end pr-4"> + <button @click="page='chat'">Chat</button> + <button @click="page='content'">知识库</button> + <button>设置</button> + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" - class="w-4 h-4 absolute left-4 top-5"> + class="w-4 h-4 cursor-pointer inline" @click="cleanHistory"> <path stroke-linecap="round" stroke-linejoin="round" - d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" /> + d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" /> </svg> - </a> - <span class="leading-10 font-bold">{{ name }} {{ config?.mode === 'completions' ? 'ï¼ˆæ— ä¸Šä¸‹æ–‡ï¼‰' : '' }}</span> - <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" - class="w-4 h-4 absolute right-4 top-5 cursor-pointer" @click="cleanHistory"> - <path stroke-linecap="round" stroke-linejoin="round" - d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" /> - </svg> + </div> + + + </div> <!-- main content --> <div class="flex w-full h-full pt-14"> - <!-- left --> - <div class="flex-none w-0 md:w-[260px] bg-slate-200 border-r-2 hidden md:block p-8 text-sm"> - - <t-form labelAlign="top"> - <t-form-item label="GPTæœåŠ¡å™¨ç±»åž‹" name="sdServerType"> - <t-select v-model="sdServerType" @change="handleSDServerTypeChange" class="bg-gray-200" style="background: #ccc;font-size:12px;"> - <t-option v-for="(item, index) in sdServerTypeOptions" :key="index" :value="item.value" :label="item.label"> - {{ item.label }} - </t-option> - </t-select> - </t-form-item> - <t-form-item label="æœåŠ¡å™¨åœ°å€" name="sdServerUrl"> - <t-textarea placeholder="请输入内容" v-model="sdServerUrl" :autosize="true" @change="saveConfig"/> - </t-form-item> - </t-form> - <t-card class="bg-orange-100 mt-8 text-gray-600 text-sm" v-if="sdServerType === 'common'"> - 公共æœåŠ¡å™¨ä¸ºä¸´æ—¶æ供的测试æœåŠ¡å™¨ï¼Œå¯èƒ½å˜åœ¨éœ€è¦æŽ’队或éšæ—¶ä¸‹çº¿çš„å¯èƒ½ã€‚<br/> - 建议使用 - <t-tooltip content='è´ä¹°åŽä¸Šé¢æœåŠ¡å™¨åœ°å€å¡«å†™ 工作å°-å°ç¾Šé©¼ 域å,åŒæ—¶æŠŠç«¯å£æ¢æˆ8000ï¼Œå¹¶æ·»åŠ "/v1"åŽç¼€' theme="primary"> - <t-link href="https://inscode.csdn.net/gpu?utm_source=sd_app" target="_blank" :suffix-icon="renderSuffixIcon" underline>ç§æœ‰æœåŠ¡å™¨</t-link> - </t-tooltip> - </t-card> - - - <t-form labelAlign="top" label-width="100" :style="{display: showProfileSetting ? 'block':'none'}"> - <t-form-item label="机器人头åƒ"> - <!-- <t-input placeholder="请输入内容" v-model="config.robot_img"/> --> - <t-space direction="vertical" align="center" v-for="imgItem in robotAvatarList" class="mr-2 cursor-pointer hover:bg-blue-600"> - <t-image class="rounded-lg border-2 " :class="{ 'border-blue-800': imgItem.src === config.robot_img }" - @click="changeRobotAvatar(imgItem.src)" :src="imgItem.src" fit="cover" - :style="{ width: '40px', height: '40px' }" /> - <!-- <span>{{ imgItem.name }}</span> --> - </t-space> - </t-form-item> - <t-form-item label="ä½ çš„å¤´åƒ"> - <t-space direction="vertical" align="center" v-for="imgItem in userAvatarList" class="mr-2 cursor-pointer hover:bg-blue-600"> - <t-image class="rounded-lg border-2 " :class="{ 'border-blue-800': imgItem.src === config.user_img }" - @click="changeUserAvatar(imgItem.src)" :src="imgItem.src" fit="cover" - :style="{ width: '40px', height: '40px' }" /> - <!-- <span>{{ imgItem.name }}</span> --> - </t-space> - </t-form-item> - <t-form-item label="æœºå™¨äººå¯¹ä½ çš„ç§°å‘¼" help="多个称呼用逗å·éš”å¼€"> - <t-input v-model="config.user_call_name" /> - </t-form-item> - </t-form> + + + <div v-if="page === 'content'" class="w-full bg-slate-300 md:bg-slate-300 p-2 sm:p-8"> + <content/> </div> <!-- right --> - <div class="flex-auto bg-slate-300 md:bg-slate-300 p-2 sm:p-8"> + <div class="flex-auto bg-slate-300 md:bg-slate-300 p-2 sm:p-8" v-else> - <content/> + <div class="w-full bg-slate-200 h-full m-auto relative container max-w-6xl rounded-xl"> <div class="w-full h-full pb-24 p-4 overflow-y-auto overflow-x-hidden" ref="messageList"> @@ -188,6 +155,7 @@ export default { }, data() { return { + page: '', id: 0, name: 'åŠ è½½ä¸...', userAvatarList: [], diff --git a/src/components/content/index.vue b/src/components/content/index.vue index a7fcf74b9c0ddd5ed7d548925b51b43272ea3b83..667cabf7abd7c59660cfd1c2eae1d89ec29e4c9a 100644 --- a/src/components/content/index.vue +++ b/src/components/content/index.vue @@ -4,7 +4,7 @@ <div class="p-4"> <span>æ·»åŠ å†…å®¹</span> - <textarea class="block my-2 w-full" v-model="newContent"></textarea> + <textarea class="block my-2 w-full" v-model="newContent" maxLength="512"></textarea> <button class="bg-gray-300 py-2 px-4 rounded hover:bg-gray-400" @click="add"> add</button> <button class="bg-gray-300 py-2 px-4 rounded hover:bg-gray-400 ml-2" @click="search"> search</button> @@ -21,9 +21,11 @@ </thead> <tbody> <tr v-for="item in list" class="*:h-12 *:border-b *:border-slate-300 *:pl-2 *:hover:bg-gray-300"> - <td >{{ item._id }}</td> - <td>{{ item.content }}</td> - <td class="*:py-1 *:px-4 *:rounded-md *:mr-2 *:text-gray-100"> + <td class="w-[80px]">{{ item._id }}</td> + <td> + <textarea class="my-2 w-full bg-gray-100 max-h-48 border-gray-300" v-model="item.content" maxLength="512"></textarea> + </td> + <td class="*:py-1 *:px-4 *:rounded-md *:mr-2 *:text-gray-100 w-[160px]"> <button @click="deleteItem(item)" class="bg-orange-400 hover:bg-orange-500"> åˆ é™¤</button> <button @click="updateItem(item)" class="bg-blue-400 hover:bg-blue-500"> æ›´æ–°</button> </td> @@ -50,31 +52,48 @@ export default { }, data() { return { - newContent: '测试内容', + newContent: '', list: [] } }, methods: { add () { - debugger - esClient.add(this.newContent) + + esClient.add(this.newContent).then(res=>{ + MessagePlugin.success({ content: 'æ·»åŠ æˆåŠŸ', placement: 'center' }) + this.newContent = '' + + this.$nextTick(() => { + this.search() + }) + }) }, search () { esClient.query(this.newContent).then(res => { - console.info('query') console.info(res) this.list = res + }) }, updateItem (item) { esClient.update(item._id, item.content).then(res => { MessagePlugin.success({ content: 'æ›´æ–°æˆåŠŸ', placement: 'center' }) - }) + this.$nextTick(() => { + this.search() + }) }) }, deleteItem (item) { + esClient.delete(item._id).then(res => { MessagePlugin.success({ content: 'åˆ é™¤æˆåŠŸ', placement: 'center' }) + this.$nextTick(() => { + this.search() + }) + }).catch(() => { + this.$nextTick(() => { + this.search() + }) }) }, diff --git a/src/js/repEs.js b/src/js/repEs.js index 92b49758c10f5b58860c8920507c080085bbe0d2..75a13ec075deaa8cb14e5ac0c0c61ae60dd956da 100644 --- a/src/js/repEs.js +++ b/src/js/repEs.js @@ -70,18 +70,8 @@ class RepEs { user_token: token, content: content, }).then(res => { - - if (res?.status === 200 && res?.data?.code === 200) { - const result = [] - res?.data?.data?.hits.forEach(element => { - result.push({ - page_content: element?._source?.content - }) - }); - resolve(result) - - } console.info(res) + resolve(res) }).catch((err) => { @@ -101,7 +91,7 @@ class RepEs { axios.delete(url).then(res => { console.info(res) - resolve(result) + resolve(res) }).catch((err) => { console.error(err) @@ -120,7 +110,7 @@ class RepEs { axios.put(url, {content: content}).then(res => { console.info(res) - resolve(result) + resolve(res) }).catch((err) => { console.error(err)