refactor chat
This commit is contained in:
1 parent
565b367c59
commit
cd5dbaa264
20 files changed
+192
-230
No files matched your search
+6
-65
@@ -4,7 +4,7 @@
|
||||
<navigator />
|
||||
</div>
|
||||
<div class="main">
|
||||
<sidebar class="sidebar" />
|
||||
<side-panel />
|
||||
<router-view />
|
||||
</div>
|
||||
</div>
|
||||
@@ -13,68 +13,17 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import Navigator from '@/components/common/Navigator.vue';
|
||||
import Sidebar from '@/components/chat/Sidebar.vue';
|
||||
import {
|
||||
CHAT_MODEL_CHATGPT,
|
||||
CHAT_MODEL_CHATGPT4,
|
||||
CHAT_MODEL_CHATGPT4_BROWSING,
|
||||
CHAT_MODEL_CHATGPT_16K,
|
||||
CHAT_MODEL_CHATGPT_BROWSING,
|
||||
applicationOperator
|
||||
} from '@/operators';
|
||||
import SidePanel from '@/components/chat/SidePanel.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'LayoutChat',
|
||||
components: {
|
||||
Sidebar,
|
||||
SidePanel,
|
||||
Navigator
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
initializing: false,
|
||||
applications: this.$store.state.chat.applications || undefined
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchApplications();
|
||||
},
|
||||
methods: {
|
||||
async onFetchConversations() {
|
||||
this.loading = true;
|
||||
const {
|
||||
data: { items: apiUsages }
|
||||
} = await apiUsageOperator.getAll({
|
||||
user_id: this.$store.state.common.user.id,
|
||||
// @ts-ignore
|
||||
application_id: this.applications?.map((application) => application.id),
|
||||
offset: 0,
|
||||
limit: 30,
|
||||
ordering: '-created_at'
|
||||
});
|
||||
this.loading = false;
|
||||
// de duplicate conversations using id
|
||||
const conversationIds: string[] = apiUsages
|
||||
.map((apiUsage) => apiUsage.metadata?.conversation_id)
|
||||
.filter((id) => id);
|
||||
const uniqueConversationIds = [...new Set(conversationIds)];
|
||||
const conversations = (await chatOperator.getConversations(uniqueConversationIds)).data;
|
||||
this.conversations = conversations;
|
||||
},
|
||||
async onFetchApplications() {
|
||||
this.initializing = true;
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: this.$store.state.common.user.id,
|
||||
api_id: [
|
||||
CHAT_MODEL_CHATGPT.apiId,
|
||||
CHAT_MODEL_CHATGPT_16K.apiId,
|
||||
CHAT_MODEL_CHATGPT_BROWSING.apiId,
|
||||
CHAT_MODEL_CHATGPT4.apiId,
|
||||
CHAT_MODEL_CHATGPT4_BROWSING.apiId
|
||||
]
|
||||
});
|
||||
this.initializing = false;
|
||||
this.$store.dispatch('chat/setApplications', applications?.items);
|
||||
}
|
||||
async mounted() {
|
||||
await this.$store.dispatch('chat/getApplications');
|
||||
await this.$store.dispatch('chat/getConversations');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -97,14 +46,6 @@ export default defineComponent({
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
.sidebar {
|
||||
display: block;
|
||||
width: 300px;
|
||||
height: 100%;
|
||||
border-right: 1px solid #eee;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user