Skip to content

Commit

Permalink
update conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Sep 30, 2023
1 parent e50892c commit d33079c
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 4 deletions.
93 changes: 93 additions & 0 deletions src/components/chat/Message.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<template>
<div :class="'message ' + message.role">
<div class="content">
<markdown-renderer :content="message?.content" />
</div>
</div>
</template>

<script lang="ts">
import { IContent, IError, IMessage, IMessageState } from '@/operators/message/models';
import { defineComponent } from 'vue';
// import MessageContent from './MessageContent.vue';
import { ElImage, ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import copy from 'copy-to-clipboard';
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
interface IData {
copied: boolean;
messageState: typeof IMessageState;
}
export default defineComponent({
name: 'Message',
components: {
// MessageContent,
// ElImage,
// ElButton,
// FontAwesomeIcon
MarkdownRenderer
},
props: {
message: {
type: Object as () => IMessage,
required: true
}
},
emits: ['stop'],
data(): IData {
return {
copied: false,
messageState: IMessageState
};
},
computed: {
// conversationId() {
// return this.$route.params?.id?.toString();
// }
},
methods: {
// onCopy() {
// copy(this.content.value, {
// debug: true
// });
// this.copied = true;
// setTimeout(() => {
// this.copied = false;
// }, 3000);
// },
// onStop() {
// this.$emit('stop');
// }
}
});
</script>

<style lang="scss" scoped>
.message {
display: flex;
flex-direction: column;
&.assistant {
align-items: start;
.content {
background-color: var(--el-bg-color-page);
color: var(--el-color-black);
border-bottom-left-radius: 0;
}
}
&.user {
align-items: end;
.content {
background-color: var(--el-color-primary);
color: var(--el-color-white);
border-bottom-right-radius: 0;
}
}
.content {
border-radius: 10px;
padding: 8px 15px;
// background-color: aqua;
}
}
</style>
3 changes: 2 additions & 1 deletion src/components/common/MarkdownRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default defineComponent({
.markdown-body {
background: none;
padding-top: 3px;
color: var(--el-text-color-primary);
color: inherit;
// color: var(--el-text-color-primary);
ol {
list-style: initial;
}
Expand Down
9 changes: 7 additions & 2 deletions src/operators/message/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export enum IMessageState {
FAILED = 'failed'
}

export const ROLE_SYSTEM = 'system';
export const ROLE_ASSISTANT = 'assistant';
export const ROLE_USER = 'user';

export interface IMessage {
state?: IMessageState;
content: IContent;
author: IUser | IBot;
content: string;
author?: IUser | IBot;
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
error?: IError;
}
48 changes: 47 additions & 1 deletion src/pages/chat/Conversation.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
<template>
<div>hi</div>
<div class="page">
<div v-for="(message, messageIndex) in messages" :key="messageIndex">
<message :message="message" class="message" />
</div>
</div>
</template>

<script lang="ts">
import { IMessage, ROLE_ASSISTANT, ROLE_SYSTEM, ROLE_USER } from '@/operators/message/models';
import { defineComponent } from 'vue';
import Message from '@/components/chat/Message.vue';
export interface IData {
messages: IMessage[];
}
export default defineComponent({
name: 'ChatConversation',
components: {
// Introduction,
// InputBox,
// ModelSelector,
Message
},
data(): IData {
return {
messages: [
{
role: ROLE_USER,
content: 'hello'
},
{
role: ROLE_ASSISTANT,
content: 'hello, how can I assist you?'
}
]
};
}
});
</script>

<style lang="scss" scoped>
.page {
padding: 20px;
.message {
margin-bottom: 10px;
}
}
</style>

0 comments on commit d33079c

Please sign in to comment.