1
0
forked from Leaf/amber-ui

改进 助理共享部分

This commit is contained in:
Twilight 2024-09-25 14:57:45 +08:00
parent 46ba7a641d
commit 49975c600a
4 changed files with 227 additions and 124 deletions

2
src/components.d.ts vendored
View File

@ -9,10 +9,12 @@ declare module 'vue' {
export interface GlobalComponents {
AccountSettings: typeof import('./components/settings/AccountSettings.vue')['default']
AssistantMenu: typeof import('./components/AssistantMenu.vue')['default']
AssistantPublistSettings: typeof import('./components/settings/AssistantPublistSettings.vue')['default']
AssistantSettings: typeof import('./components/settings/AssistantSettings.vue')['default']
Chat: typeof import('./components/chat/Chat.vue')['default']
ChatMenu: typeof import('./components/ChatMenu.vue')['default']
ChatSettings: typeof import('./components/settings/ChatSettings.vue')['default']
copy: typeof import('./components/settings/AssistantSettings copy.vue')['default']
LeftSettings: typeof import('./components/settings/LeftSettings.vue')['default']
LibrarySettings: typeof import('./components/settings/LibrarySettings.vue')['default']
Lottie: typeof import('./components/Lottie.vue')['default']

View File

@ -1,7 +1,9 @@
<template>
<div class="relative flex flex-col items-center">
<div class="w-4/5">
<div>
<div
class="flex flex-col items-center justify-between pl-20 pr-20"
>
<div class=" min-w-full w-4/5">
<n-scrollbar style="max-height: calc(100vh - (var(--header-height) *3.5))">
<div
class="flex-grow mt-3 mb-1 text-5xl select-none"
v-if="!chatMessages?.length"
@ -18,131 +20,119 @@
<div v-else @click="assistantStore.selectMenu = false">
<MessageList :chat_messages="chatMessages" />
</div>
</n-scrollbar>
</div>
<div class="w-full pr-2 pl-2 pt-2">
<div
class="mx-auto w-2xl max-w-2xl text-center mb-3 animate__animated animate__pulse text-lg"
v-if="isMobile && chatStore.toolName != ''"
>
<n-gradient-text type="info">
正在执行 {{ chatStore.toolName }}
</n-gradient-text>
</div>
<div class="fixed bottom-0 left-0 right-0">
<!-- <div
class="mx-auto w-2xl max-w-2xl text-center mb-3 animate__animated animate__pulse text-lg"
v-if="toolCalling"
>
<n-gradient-text type="info">
{{ toolName }}
</n-gradient-text>
</div> -->
<div
class="mx-auto w-2xl max-w-2xl text-center mb-3 animate__animated animate__pulse text-lg"
v-if="isMobile && chatStore.toolName != ''"
>
<n-gradient-text type="info">
正在执行 {{ chatStore.toolName }}
</n-gradient-text>
</div>
<div
ref="inputContainer"
class="mx-auto w-2xl max-w-xs lg:max-w-2xl outline-none input-color input-bg rounded-full flex pl-5 pr-5 bg-white shadow-lg items-center p-4 pb-4 transition-all"
>
<div class="overflow-x-hidden h-full w-full flex items-center">
<n-scrollbar class="max-h-96">
<n-dropdown
:show="assistantStore.selectMenu"
:options="assistantMenuOptions"
placement="top-start"
@select="handleSelect"
>
<div class="absolute left-0"></div>
</n-dropdown>
<div
ref="inputText"
:class="{ 'has-placeholder': isPlaceholderVisible }"
contenteditable="true"
placeholder="请输入文本..."
class="input-text max-w-full outline-none text-lg text-pretty pl-2 min-h-6"
@keydown="onKeydown"
@input="updateInputHeight"
@compositionstart="handleCompositionStart"
@compositionend="handleCompositionEnd"
></div>
</n-scrollbar>
</div>
<n-spin :show="processing">
<div
ref="actionContainer"
class="flex [&>button]:ml-2 pr-4 justify-end"
<div
ref="inputContainer"
class="mx-auto w-2xl max-w-md lg:max-w-2xl outline-none input-color input-bg rounded-full flex pl-5 pr-5 bg-white shadow-lg items-center p-4 pb-4 transition-all"
>
<div class="overflow-x-hidden h-full w-full flex items-center">
<n-scrollbar class="max-h-96">
<n-dropdown
:show="assistantStore.selectMenu"
:options="assistantMenuOptions"
placement="top-start"
@select="handleSelect"
>
<n-tooltip
trigger="hover"
v-if="chatId !== null && chatData.assistant_id !== null"
>
<template #trigger>
<n-button
tertiary
circle
size="large"
@click="showUploadModal = true"
>
<template #icon>
<n-icon><DocumentAttachOutline /></n-icon>
</template>
</n-button>
</template>
<span> 在做了在做了 </span>
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<n-button tertiary circle size="large">
<template #icon>
<n-icon><MicOutline /></n-icon>
</template>
</n-button>
</template>
<span> 在做了在做了 </span>
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<n-button
tertiary
circle
size="large"
v-show="chatMessages?.length"
@click="clearChatHistory"
>
<template #icon>
<n-icon><TrashBinOutline /></n-icon>
</template>
</n-button>
</template>
<span> 清空历史 </span>
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<n-button
tertiary
circle
size="large"
v-show="showSendBtn"
@click="sendText"
>
<template #icon>
<n-icon><SendOutline /></n-icon>
</template>
</n-button>
</template>
<span> 发送 </span>
</n-tooltip>
</div>
</n-spin>
<div class="absolute left-0"></div>
</n-dropdown>
<div
ref="inputText"
:class="{ 'has-placeholder': isPlaceholderVisible }"
contenteditable="true"
placeholder="请输入文本..."
class="input-text max-w-full outline-none text-lg text-pretty pl-2 min-h-6"
@keydown="onKeydown"
@input="updateInputHeight"
@compositionstart="handleCompositionStart"
@compositionend="handleCompositionEnd"
></div>
</n-scrollbar>
</div>
<n-text
depth="3"
class="text-center block mt-2 mb-2 text-sm select-none"
>
AI 也有可能犯错误请在使用之前核查信息
</n-text>
<n-spin :show="processing">
<div
ref="actionContainer"
class="flex [&>button]:ml-2 pr-4 justify-end"
>
<n-tooltip
trigger="hover"
v-if="chatId !== null && chatData.assistant_id !== null"
>
<template #trigger>
<n-button
tertiary
circle
size="large"
@click="showUploadModal = true"
>
<template #icon>
<n-icon><DocumentAttachOutline /></n-icon>
</template>
</n-button>
</template>
<span> 在做了在做了 </span>
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<n-button tertiary circle size="large">
<template #icon>
<n-icon><MicOutline /></n-icon>
</template>
</n-button>
</template>
<span> 在做了在做了 </span>
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<n-button
tertiary
circle
size="large"
v-show="chatMessages?.length"
@click="clearChatHistory"
>
<template #icon>
<n-icon><TrashBinOutline /></n-icon>
</template>
</n-button>
</template>
<span> 清空历史 </span>
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<n-button
tertiary
circle
size="large"
v-show="showSendBtn"
@click="sendText"
>
<template #icon>
<n-icon><SendOutline /></n-icon>
</template>
</n-button>
</template>
<span> 发送 </span>
</n-tooltip>
</div>
</n-spin>
</div>
<n-text depth="3" class="text-center block mt-2 mb-2 text-sm select-none">
AI 也有可能犯错误请在使用之前核查信息
</n-text>
</div>
</div>

View File

@ -0,0 +1,104 @@
<template>
<p>在做了在做了</p>
<div v-if="assistants.length">
<n-list hoverable clickable>
<n-list-item v-for="c in assistants" :key="c.id">
<n-thing>
<div class="flex justify-between items-center">
<div>
{{ c.name }}
<br />
{{ c.description }}
</div>
<div>
<n-button
quaternary
circle
type="info"
>
<template #icon>
<n-icon size="16" class="cursor-pointer">
<SettingsOutline />
</n-icon>
</template>
</n-button>
</div>
</div>
</n-thing>
</n-list-item>
</n-list>
</div>
<div v-else class="text-center">
<n-result
status="404"
title="目前没有共享的助理"
description="你可以在这里收藏别人发布的助理,并使用它。"
>
<n-button type="primary"> 在做了在做了 </n-button>
</n-result>
</div>
</template>
<script lang="ts" setup>
import { useDialog } from "naive-ui";
import {
TrashBinOutline,
SettingsOutline,
HelpCircleOutline,
} from "@vicons/ionicons5";
import getApi from "@/plugins/api";
import { useChatStore } from "@/stores/chat";
import { ref } from "vue";
import {
EntityAssistant,
EntityAssistantKey,
EntityAssistantTool,
EntityLibrary,
EntityTool,
SchemaAssistantPublic,
} from "@/api";
import { useIsMobile } from "@/utils/composables";
const currentAssistantTools: Ref<EntityAssistantTool[]> = ref([]);
const currentAssistantId = ref();
const assistants: Ref<SchemaAssistantPublic[]> = ref([]);
const assistantApiKeys: Ref<EntityAssistantKey[]> = ref([]);
const isMobile = useIsMobile();
const drawerWidth = computed(() => {
if (isMobile.value) {
return window.innerWidth;
} else {
return window.innerWidth * 0.6;
}
});
const getAssistants = async () => {
getApi()
.Assistant.apiV1AssistantsPublicGet(1)
.then((r) => {
assistants.value = r.data.data?.data ?? [];
});
};
// const bindOrUnbind = async (id: number) => {
// let binded = findTool(id);
// if (binded) {
// await getApi().Assistant.apiV1AssistantsIdToolsToolIdDelete(
// currentAssistantId.value,
// id
// );
// } else {
// await getApi().Assistant.apiV1AssistantsIdToolsToolIdPost(
// currentAssistantId.value,
// id
// );
// }
// };
getAssistants();
</script>

View File

@ -1,3 +1,7 @@
<script setup lang="ts">
import AssistantPublistSettings from './AssistantPublistSettings.vue';
</script>
<template>
<n-tabs type="segment" animated class="select-none">
<n-tab-pane name="chat" tab="对话">
@ -6,6 +10,9 @@
<n-tab-pane name="assistant" tab="助理">
<AssistantSettings />
</n-tab-pane>
<n-tab-pane name="assistant_public" tab="发布">
<AssistantPublistSettings />
</n-tab-pane>
<n-tab-pane name="tool" tab="工具">
<ToolSettings />
</n-tab-pane>