Skip to content

Commit

Permalink
feat: allow users to copy assistant responses
Browse files Browse the repository at this point in the history
  • Loading branch information
zaldivards committed Jun 21, 2024
1 parent 8d5245d commit 2f74fec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/src/components/ChatBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
<div v-else v-html="message.content" />
</template>
<template #footer>
<div class="date w-max justify-content-end text-xs text-white-alpha-70">
<div class="date text-xs text-white-alpha-70 flex gap-2 align-items-center">
{{ message.date }}
<CopyButton v-if="message.role != 'user'" :content="message.content"/>
</div>
</template>
</Card>
Expand Down Expand Up @@ -117,6 +118,7 @@ import Toast from "primevue/toast";
import Card from "primevue/card";
import Avatar from "primevue/avatar";
import MessageAdder from "@/components/MessageAdder.vue";
import CopyButton from "@/components/CopyButton.vue";
const SourcesBox = defineAsyncComponent(() =>
import("@/components/SourcesBox.vue")
Expand Down Expand Up @@ -146,6 +148,7 @@ export default {
Button,
DynamicDialog,
Chip,
CopyButton
},
props: { requiresContext: Boolean },
mounted() {
Expand Down
27 changes: 27 additions & 0 deletions client/src/components/CopyButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<Button :icon="`pi ${copied ? 'pi-check' : 'pi-copy'}`" text class="bg-inherit text-gray-300" title="Copy"
size="large" @click="onClick" />
</template>

<script>
import Button from "primevue/button";
export default {
name: 'CopyButton',
components: { Button },
props: { content: String },
data() {
return {
copied: false,
}
},
methods: {
onClick() {
navigator.clipboard.writeText(this.content.replace('<sources>', ''))
this.copied = true
setTimeout(() => this.copied = false, 2000)
}
}
}
</script>

<style></style>

0 comments on commit 2f74fec

Please sign in to comment.