add history conversations
This commit is contained in:
1 parent
726e7b8e04
commit
cea31c5011
7 files changed
+145
-110
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="sidebar">
|
||||
<el-skeleton v-if="loading" />
|
||||
<el-skeleton v-if="loading && conversations.length === 0" />
|
||||
<div v-else class="conversations">
|
||||
<div
|
||||
v-for="(conversation, conversationIndex) in conversations"
|
||||
@@ -12,7 +12,9 @@
|
||||
<font-awesome-icon icon="fa-regular fa-comment" class="icon" />
|
||||
</div>
|
||||
<div class="title">
|
||||
<span>{{ conversation.title }}</span>
|
||||
<span v-if="conversation?.messages">{{
|
||||
conversation?.messages[conversation?.messages.length - 1]?.content
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="operations">
|
||||
<font-awesome-icon icon="fa-solid fa-edit" class="icon icon-edit" />
|
||||
@@ -28,13 +30,13 @@ import { defineComponent } from 'vue';
|
||||
import { ElTooltip, ElButton, ElSkeleton } from 'element-plus';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_INDEX } from '@/router/constants';
|
||||
import { apiUsageOperator, midjourneyOperator, MidjourneyImagineState, IApplication } from '@/operators';
|
||||
import { apiUsageOperator, midjourneyOperator, MidjourneyImagineState, IApplication, chatOperator } from '@/operators';
|
||||
import { chatgptOperator } from '@/operators/api/chatgpt/operator';
|
||||
import { IConversation } from '@/operators/conversation/models';
|
||||
import { IChatConversation } from '@/operators/chat/models';
|
||||
|
||||
interface IData {
|
||||
loading: boolean;
|
||||
conversations: IConversation[];
|
||||
conversations: IChatConversation[];
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -45,8 +47,8 @@ export default defineComponent({
|
||||
ElSkeleton
|
||||
},
|
||||
props: {
|
||||
application: {
|
||||
type: Object as () => IApplication | undefined,
|
||||
applications: {
|
||||
type: Object as () => IApplication[],
|
||||
required: true
|
||||
}
|
||||
},
|
||||
@@ -57,51 +59,34 @@ export default defineComponent({
|
||||
conversations: []
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchAllConversations();
|
||||
watch: {
|
||||
applications(val) {
|
||||
if (val) {
|
||||
this.onFetchAllConversations();
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
async onFetchAllConversations() {
|
||||
// applicationOperator.getAll()
|
||||
console.log('srtart to load');
|
||||
this.loading = true;
|
||||
const {
|
||||
data: { items: apiUsages }
|
||||
} = await apiUsageOperator.getAll({
|
||||
user_id: this.$store.state.user.id,
|
||||
application_id: this.application?.id,
|
||||
application_id: this.applications?.map((application) => application.id),
|
||||
offset: 0,
|
||||
limit: 20,
|
||||
limit: 30,
|
||||
ordering: '-created_at'
|
||||
});
|
||||
this.loading = false;
|
||||
|
||||
// de duplicate conversations using id
|
||||
const conversationIds: string[] = [];
|
||||
const uniqueApiUsages = apiUsages.filter((apiUsage) => {
|
||||
const conversationId = apiUsage.metadata?.conversation_id;
|
||||
if (!conversationId) {
|
||||
return false;
|
||||
}
|
||||
if (conversationIds.includes(conversationId)) {
|
||||
return false;
|
||||
}
|
||||
conversationIds.push(conversationId);
|
||||
return true;
|
||||
});
|
||||
|
||||
const conversations = await Promise.all(
|
||||
uniqueApiUsages.map(async (apiUsage) => {
|
||||
// const taskId = apiUsage.metadata?.task_id;
|
||||
// console.log('taskid', taskId);
|
||||
return {
|
||||
id: apiUsage.metadata?.conversation_id,
|
||||
title: apiUsage.metadata?.conversation_id
|
||||
} as IConversation;
|
||||
})
|
||||
);
|
||||
const conversationIds: string[] = apiUsages
|
||||
.map((apiUsage) => apiUsage.metadata?.conversation_id)
|
||||
.filter((id) => id);
|
||||
const uniqueConversationIds = [...new Set(conversationIds)];
|
||||
const conversations = (await chatOperator.conversations(uniqueConversationIds)).data;
|
||||
this.conversations = conversations;
|
||||
// this.historyTasks = tasks.filter((task) => task && task?.response);
|
||||
},
|
||||
onClick(id: string) {
|
||||
if (!id) {
|
||||
|
||||
@@ -770,12 +770,14 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/7fd2cd5c-7671-4b40-85a0-230de9c37234.png',
|
||||
label: '黑光',
|
||||
value: 'Blacklight'
|
||||
value: 'Blacklight',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/a08bff6e-8a0f-4d56-aa91-576f0a9921f2.png',
|
||||
label: '黄金时段光线',
|
||||
value: 'Golden hour light'
|
||||
value: 'Golden hour light',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/3cd28696-493f-4b3e-9187-9d1a4c17e95b.png',
|
||||
@@ -785,7 +787,8 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/58c9a17e-f7d5-4481-abc8-9e9b66609a4d.png',
|
||||
label: '音乐会照明',
|
||||
value: 'Concert Lighting'
|
||||
value: 'Concert Lighting',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/efb8893c-8bd6-4c7d-8e45-6e0626f69479.png',
|
||||
@@ -795,7 +798,7 @@ export default defineComponent({
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/27b90e83-09b0-4339-9b2c-48fe6fe45bdd.png',
|
||||
label: '阳光直接照射',
|
||||
label: '阳光直射',
|
||||
value: 'Direct Sunlight'
|
||||
},
|
||||
{
|
||||
@@ -807,7 +810,8 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/3af133d0-5a86-45a9-a16e-f23e6cc68b24.png',
|
||||
label: '工作室照明',
|
||||
value: 'Studio lighting'
|
||||
value: 'Studio lighting',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/6bc889b1-a563-4890-9117-7d3ded276caa.png',
|
||||
@@ -835,7 +839,8 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/63bc0645-ab94-4327-84b8-e226020c6c0f.png',
|
||||
label: '荧光棒',
|
||||
value: 'Glow-stick'
|
||||
value: 'Glow-stick',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/824111e9-7ebf-47ec-80ef-a6ad0a1d949b.png',
|
||||
@@ -867,7 +872,8 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/ac3fe310-3639-4fc0-b56e-4d69278bc2ca.png',
|
||||
label: '夜总会照明',
|
||||
value: 'Nightclub Lighting'
|
||||
value: 'Nightclub Lighting',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/c9331a92-87d2-43b5-9319-24c8629bffd1.png',
|
||||
@@ -889,7 +895,8 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/b1f16a4b-fb3d-4783-9c66-c3567e79baeb.png',
|
||||
label: '边缘光',
|
||||
value: 'Edge light'
|
||||
value: 'Edge light',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/97fecbc1-a164-48e2-bdf0-c69975c16d63.png',
|
||||
@@ -905,17 +912,20 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/5ab92c7e-bca1-4fbc-8975-6d9fb3f15626.png',
|
||||
label: '环境光',
|
||||
value: 'Ambient Light'
|
||||
value: 'Ambient Light',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/ac80d283-5532-4664-bbe5-42fbb9582a63.png',
|
||||
label: '高调照明',
|
||||
value: 'High key lighting'
|
||||
value: 'High key lighting',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/add3524d-fc90-45a8-9edc-348bb1f79075.png',
|
||||
label: '低调照明',
|
||||
value: 'Low key lighting'
|
||||
value: 'Low key lighting',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/42174ff8-3080-4004-9ae2-c2ff919e1145.png',
|
||||
@@ -943,7 +953,8 @@ export default defineComponent({
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/4360a40b-2126-43c2-be8e-e482978e1ea6.png',
|
||||
label: '紫外线',
|
||||
value: 'Ultraviolet'
|
||||
value: 'Ultraviolet',
|
||||
advanced: true
|
||||
},
|
||||
{
|
||||
image: 'https://cdn.zhishuyun.com/8b6bea86-9ed1-4fc8-9040-8fc2b64abbff.png',
|
||||
|
||||
@@ -72,7 +72,8 @@ export interface IChatAskResponse {
|
||||
|
||||
export enum IChatConversationAction {
|
||||
RETRIEVE = 'retrieve',
|
||||
UPDATE = 'update'
|
||||
UPDATE = 'update',
|
||||
RETRIEVE_BATCH = 'retrieve_batch'
|
||||
}
|
||||
|
||||
export interface IChatConversationRequest {
|
||||
|
||||
@@ -5,8 +5,13 @@ import {
|
||||
IChatAskResponse,
|
||||
IChatConversationRequest,
|
||||
IChatConversationOptions,
|
||||
IChatConversationResponse
|
||||
IChatConversationResponse,
|
||||
IChatConversation,
|
||||
IChatConversationAction
|
||||
} from './models';
|
||||
import { IApplication } from '../application';
|
||||
import { IApi } from '../api';
|
||||
import { ENDPOINT_API } from '../common/contants';
|
||||
|
||||
class ChatOperator {
|
||||
async ask(data: IChatAskRequest, options: IChatAskOptions): Promise<AxiosResponse<IChatAskResponse>> {
|
||||
@@ -32,16 +37,36 @@ class ChatOperator {
|
||||
});
|
||||
}
|
||||
|
||||
async conversations(
|
||||
data: IChatConversationRequest,
|
||||
options: IChatConversationOptions
|
||||
): Promise<AxiosResponse<IChatConversationResponse>> {
|
||||
return await axios.post(options.path, data, {
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
async conversation(id: string | undefined): Promise<AxiosResponse<IChatConversation>> {
|
||||
return await axios.post(
|
||||
`/chatgpt/conversations`,
|
||||
{
|
||||
action: IChatConversationAction.RETRIEVE,
|
||||
id: id
|
||||
},
|
||||
baseURL: options.endpoint
|
||||
});
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
baseURL: ENDPOINT_API
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async conversations(ids: string[]): Promise<AxiosResponse<IChatConversation[]>> {
|
||||
return await axios.post(
|
||||
`/chatgpt/conversations`,
|
||||
{
|
||||
action: IChatConversationAction.RETRIEVE_BATCH,
|
||||
ids: ids
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
baseURL: ENDPOINT_API
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<sidebar class="left" :application="application" @click="onFetchHistory" />
|
||||
<sidebar class="left" :applications="applications" @click="onFetchHistory" />
|
||||
<div class="main">
|
||||
<model-selector v-model="model" class="model-selector" @select="onSelectModel" />
|
||||
<api-status :application="application" />
|
||||
@@ -27,12 +27,14 @@ import {
|
||||
IChatModel,
|
||||
IChatMessage,
|
||||
CHAT_MODEL_CHATGPT,
|
||||
API_ID_CHATGPT,
|
||||
applicationOperator,
|
||||
IApplication,
|
||||
IChatMessageState,
|
||||
IChatAskResponse,
|
||||
IChatConversationAction
|
||||
CHAT_MODEL_CHATGPT_16K,
|
||||
CHAT_MODEL_CHATGPT_BROWSING,
|
||||
CHAT_MODEL_CHATGPT4,
|
||||
CHAT_MODEL_CHATGPT4_BROWSING
|
||||
} from '@/operators';
|
||||
import InputBox from '@/components/chat/InputBox.vue';
|
||||
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
||||
@@ -46,7 +48,7 @@ import Sidebar from '@/components/chat/Sidebar.vue';
|
||||
export interface IData {
|
||||
messages: IChatMessage[];
|
||||
model: IChatModel;
|
||||
application: IApplication | undefined;
|
||||
applications: IApplication[];
|
||||
question: '';
|
||||
initializing: boolean;
|
||||
applied: boolean | undefined;
|
||||
@@ -55,7 +57,6 @@ export interface IData {
|
||||
export default defineComponent({
|
||||
name: 'ChatConversation',
|
||||
components: {
|
||||
// Introduction,
|
||||
InputBox,
|
||||
ModelSelector,
|
||||
Message,
|
||||
@@ -68,18 +69,21 @@ export default defineComponent({
|
||||
question: '',
|
||||
initializing: false,
|
||||
applied: undefined,
|
||||
application: undefined,
|
||||
applications: [],
|
||||
messages: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
conversationId(): string | undefined {
|
||||
return this.$route.params.id?.toString();
|
||||
},
|
||||
application() {
|
||||
return this.applications.find((application) => application.api?.id === this.model.apiId);
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
console.log('mounted');
|
||||
await this.onFetchModel();
|
||||
await this.onFetchApplications();
|
||||
await this.onFetchHistory();
|
||||
},
|
||||
methods: {
|
||||
@@ -89,23 +93,24 @@ export default defineComponent({
|
||||
name: ROUTE_CHAT_CONVERSATION_NEW
|
||||
});
|
||||
},
|
||||
|
||||
async onSelectModel() {
|
||||
await this.onCreateNewConversation();
|
||||
await this.onFetchModel();
|
||||
await this.onFetchApplications();
|
||||
},
|
||||
async onFetchModel() {
|
||||
async onFetchApplications() {
|
||||
this.initializing = true;
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: this.$store.state.user.id,
|
||||
api_id: this.model.apiId
|
||||
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;
|
||||
if (!applications || applications?.items?.length === 0) {
|
||||
this.applied = false;
|
||||
return;
|
||||
}
|
||||
this.application = applications.items[0];
|
||||
this.applications = applications?.items;
|
||||
},
|
||||
async onSubmitQuestion() {
|
||||
this.messages.push({
|
||||
@@ -116,23 +121,7 @@ export default defineComponent({
|
||||
await this.onFetchAnswer();
|
||||
},
|
||||
async onFetchHistory(id?: string) {
|
||||
const endpoint = this.application?.api?.endpoint;
|
||||
const path = this.application?.api?.path;
|
||||
console.log(endpoint, path);
|
||||
if (!endpoint || !path) {
|
||||
console.error('no endpoint or path');
|
||||
return;
|
||||
}
|
||||
const { data: data } = await chatOperator.conversations(
|
||||
{
|
||||
action: IChatConversationAction.RETRIEVE,
|
||||
id: id || this.conversationId
|
||||
},
|
||||
{
|
||||
endpoint,
|
||||
path: `${path}/conversations`
|
||||
}
|
||||
);
|
||||
const { data: data } = await chatOperator.conversation(id || this.conversationId);
|
||||
this.messages = data.messages || [];
|
||||
},
|
||||
async onFetchAnswer() {
|
||||
@@ -180,7 +169,7 @@ export default defineComponent({
|
||||
)
|
||||
.then(() => {
|
||||
this.messages[this.messages.length - 1].state = IChatMessageState.FINISHED;
|
||||
this.onFetchModel();
|
||||
this.onFetchApplications();
|
||||
})
|
||||
.catch((error) => {
|
||||
if (this.messages && this.messages.length > 0) {
|
||||
@@ -236,11 +225,13 @@ export default defineComponent({
|
||||
.model-selector {
|
||||
width: max-content;
|
||||
margin: auto;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.dialogue {
|
||||
flex: 1;
|
||||
.messages {
|
||||
padding-top: 30px;
|
||||
.message {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
+37
-10
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<sidebar class="left" :application="application" />
|
||||
<sidebar class="left" :applications="applications" />
|
||||
<div class="main">
|
||||
<div class="card">
|
||||
<h2 class="title">Chat</h2>
|
||||
@@ -14,14 +14,22 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElMain, ElAside, ElButton, ElDrawer } from 'element-plus';
|
||||
import LeftNavigator from '@/components/common/LeftNavigator.vue';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import Introduction from '@/components/conversation/Introduction.vue';
|
||||
import InputBox from '@/components/chat/InputBox.vue';
|
||||
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
||||
import Sidebar from '@/components/chat/Sidebar.vue';
|
||||
import { ROUTE_CHAT_CONVERSATION_NEW } from '@/router/constants';
|
||||
import application from '@/i18n/zh/application';
|
||||
import { IApplication } from '@/operators/application/models';
|
||||
import { applicationOperator } from '@/operators/application/operator';
|
||||
import {
|
||||
CHAT_MODEL_CHATGPT,
|
||||
CHAT_MODEL_CHATGPT4,
|
||||
CHAT_MODEL_CHATGPT4_BROWSING,
|
||||
CHAT_MODEL_CHATGPT_16K,
|
||||
CHAT_MODEL_CHATGPT_BROWSING
|
||||
} from '@/operators/chat/constants';
|
||||
|
||||
interface IData {
|
||||
initializing: boolean;
|
||||
applications: IApplication[];
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ChatIndex',
|
||||
@@ -29,16 +37,35 @@ export default defineComponent({
|
||||
Sidebar,
|
||||
ElButton
|
||||
},
|
||||
data() {
|
||||
data(): IData {
|
||||
return {
|
||||
model: 'chatgpt',
|
||||
initializing: false,
|
||||
drawer: false,
|
||||
question: ''
|
||||
question: '',
|
||||
applications: []
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchApplications();
|
||||
},
|
||||
methods: {
|
||||
async onFetchApplications() {
|
||||
this.initializing = true;
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: this.$store.state.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.applications = applications?.items;
|
||||
},
|
||||
onStart() {
|
||||
console.log('onStart');
|
||||
this.$router.push({
|
||||
name: ROUTE_CHAT_CONVERSATION_NEW
|
||||
});
|
||||
|
||||
@@ -143,11 +143,6 @@ export default defineComponent({
|
||||
});
|
||||
this.initializing = false;
|
||||
this.applications = applications?.items;
|
||||
if (!applications || applications?.items?.length === 0) {
|
||||
this.applied = false;
|
||||
return;
|
||||
}
|
||||
this.application = applications.items[0];
|
||||
},
|
||||
async onStartTask(request: IMidjourneyImagineRequest) {
|
||||
const token = this.application?.credential?.token;
|
||||
|
||||
Reference in new issue
Block a user