-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
262 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script lang="ts" setup> | ||
import { marked } from "marked"; | ||
const props = defineProps<{ | ||
role: string; | ||
content: string; | ||
showTyping?: boolean; | ||
}>(); | ||
const resultHtml = computed(() => marked.parse(props.content || "...")); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div flex gap-x-2 :class="role === 'user' ? 'flex-row-reverse' : ''"> | ||
<div> | ||
<el-avatar class="bg-primary!"> | ||
<Icon | ||
v-if="role === 'assistant'" | ||
text-2xl | ||
name="simple-icons:openai" | ||
></Icon> | ||
<Icon | ||
v-else-if="role === 'user'" | ||
text-2xl | ||
name="carbon:user-filled" | ||
></Icon> | ||
</el-avatar> | ||
</div> | ||
<Card w-full relative> | ||
<div text-base prose dark:prose-invert v-html="resultHtml"></div> | ||
<transition name="fade"> | ||
<div | ||
v-show="showTyping" | ||
absolute | ||
right-2 | ||
bottom-1 | ||
text-sm | ||
text-gray | ||
mt-2 | ||
> | ||
OpenAI is typing... | ||
</div> | ||
</transition> | ||
</Card> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
.fade-enter-active, | ||
.fade-leave-active { | ||
transition: all 0.5s ease; | ||
} | ||
.fade-enter-from, | ||
.fade-leave-to { | ||
opacity: 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts" setup> | ||
import { ElScrollbar } from "element-plus"; | ||
import { OpenAIMessages } from "~~/types"; | ||
const props = defineProps<{ | ||
contexts: OpenAIMessages; | ||
result: string; | ||
loading: boolean; | ||
}>(); | ||
const history = computed(() => | ||
props.contexts.filter((v) => v.role !== "system") | ||
); | ||
const scrollbar = ref<InstanceType<typeof ElScrollbar> | null>(); | ||
const innerRef = ref<HTMLDivElement>(); | ||
watch( | ||
() => props.result, | ||
() => { | ||
nextTick(() => { | ||
scrollbar.value?.setScrollTop(innerRef.value!.clientHeight); | ||
}); | ||
} | ||
); | ||
</script> | ||
|
||
<template> | ||
<el-scrollbar ref="scrollbar" height="40vh" mb-8> | ||
<div ref="innerRef" flex flex-col gap-y-6 px-4> | ||
<el-empty v-if="!history.length" description="No chat data"> | ||
<template #image> | ||
<el-icon | ||
class="text-6xl! color-[var(--el-text-color-secondary)]! i-carbon:not-sent-filled" | ||
></el-icon> | ||
</template> | ||
</el-empty> | ||
<ToolChatItem v-for="item in history" v-bind="item"></ToolChatItem> | ||
<ToolChatItem | ||
v-if="loading" | ||
show-typing | ||
role="assistant" | ||
:content="result" | ||
></ToolChatItem> | ||
</div> | ||
</el-scrollbar> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.