|
| 1 | +<script setup lang="ts"> |
| 2 | +import { Conversation, ConversationContent, ConversationScrollButton } from '@repo/elements/conversation' |
| 3 | +import { Message, MessageAvatar, MessageContent } from '@repo/elements/message' |
| 4 | +import { nanoid } from 'nanoid' |
| 5 | +import { onMounted, onUnmounted, ref } from 'vue' |
| 6 | +
|
| 7 | +interface MessageItem { |
| 8 | + key: string |
| 9 | + value: string |
| 10 | + name: string |
| 11 | + avatar: string |
| 12 | +} |
| 13 | +
|
| 14 | +const messages: MessageItem[] = [ |
| 15 | + { |
| 16 | + key: nanoid(), |
| 17 | + value: 'Hello, how are you?', |
| 18 | + name: 'Alex Johnson', |
| 19 | + avatar: 'https://github.com/haydenbleasel.png', |
| 20 | + }, |
| 21 | + { |
| 22 | + key: nanoid(), |
| 23 | + value: 'I\'m good, thank you! How can I assist you today?', |
| 24 | + name: 'AI Assistant', |
| 25 | + avatar: 'https://github.com/openai.png', |
| 26 | + }, |
| 27 | + { |
| 28 | + key: nanoid(), |
| 29 | + value: 'I\'m looking for information about your services.', |
| 30 | + name: 'Alex Johnson', |
| 31 | + avatar: 'https://github.com/haydenbleasel.png', |
| 32 | + }, |
| 33 | + { |
| 34 | + key: nanoid(), |
| 35 | + value: 'Sure! We offer a variety of AI solutions. What are you interested in?', |
| 36 | + name: 'AI Assistant', |
| 37 | + avatar: 'https://github.com/openai.png', |
| 38 | + }, |
| 39 | + { |
| 40 | + key: nanoid(), |
| 41 | + value: 'I\'m interested in natural language processing tools.', |
| 42 | + name: 'Alex Johnson', |
| 43 | + avatar: 'https://github.com/haydenbleasel.png', |
| 44 | + }, |
| 45 | + { |
| 46 | + key: nanoid(), |
| 47 | + value: 'Great choice! We have several NLP APIs. Would you like a demo?', |
| 48 | + name: 'AI Assistant', |
| 49 | + avatar: 'https://github.com/openai.png', |
| 50 | + }, |
| 51 | + { |
| 52 | + key: nanoid(), |
| 53 | + value: 'Yes, a demo would be helpful.', |
| 54 | + name: 'Alex Johnson', |
| 55 | + avatar: 'https://github.com/haydenbleasel.png', |
| 56 | + }, |
| 57 | + { |
| 58 | + key: nanoid(), |
| 59 | + value: 'Alright, I can show you a sentiment analysis example. Ready?', |
| 60 | + name: 'AI Assistant', |
| 61 | + avatar: 'https://github.com/openai.png', |
| 62 | + }, |
| 63 | + { |
| 64 | + key: nanoid(), |
| 65 | + value: 'Yes, please proceed.', |
| 66 | + name: 'Alex Johnson', |
| 67 | + avatar: 'https://github.com/haydenbleasel.png', |
| 68 | + }, |
| 69 | + { |
| 70 | + key: nanoid(), |
| 71 | + value: 'Here is a sample: \'I love this product!\' → Positive sentiment.', |
| 72 | + name: 'AI Assistant', |
| 73 | + avatar: 'https://github.com/openai.png', |
| 74 | + }, |
| 75 | + { |
| 76 | + key: nanoid(), |
| 77 | + value: 'Impressive! Can it handle multiple languages?', |
| 78 | + name: 'Alex Johnson', |
| 79 | + avatar: 'https://github.com/haydenbleasel.png', |
| 80 | + }, |
| 81 | + { |
| 82 | + key: nanoid(), |
| 83 | + value: 'Absolutely, our models support over 20 languages.', |
| 84 | + name: 'AI Assistant', |
| 85 | + avatar: 'https://github.com/openai.png', |
| 86 | + }, |
| 87 | + { |
| 88 | + key: nanoid(), |
| 89 | + value: 'How do I get started with the API?', |
| 90 | + name: 'Alex Johnson', |
| 91 | + avatar: 'https://github.com/haydenbleasel.png', |
| 92 | + }, |
| 93 | + { |
| 94 | + key: nanoid(), |
| 95 | + value: 'You can sign up on our website and get an API key instantly.', |
| 96 | + name: 'AI Assistant', |
| 97 | + avatar: 'https://github.com/openai.png', |
| 98 | + }, |
| 99 | + { |
| 100 | + key: nanoid(), |
| 101 | + value: 'Is there a free trial available?', |
| 102 | + name: 'Alex Johnson', |
| 103 | + avatar: 'https://github.com/haydenbleasel.png', |
| 104 | + }, |
| 105 | + { |
| 106 | + key: nanoid(), |
| 107 | + value: 'Yes, we offer a 14-day free trial with full access.', |
| 108 | + name: 'AI Assistant', |
| 109 | + avatar: 'https://github.com/openai.png', |
| 110 | + }, |
| 111 | + { |
| 112 | + key: nanoid(), |
| 113 | + value: 'What kind of support do you provide?', |
| 114 | + name: 'Alex Johnson', |
| 115 | + avatar: 'https://github.com/haydenbleasel.png', |
| 116 | + }, |
| 117 | + { |
| 118 | + key: nanoid(), |
| 119 | + value: 'We provide 24/7 chat and email support for all users.', |
| 120 | + name: 'AI Assistant', |
| 121 | + avatar: 'https://github.com/openai.png', |
| 122 | + }, |
| 123 | + { |
| 124 | + key: nanoid(), |
| 125 | + value: 'Thank you for the information!', |
| 126 | + name: 'Alex Johnson', |
| 127 | + avatar: 'https://github.com/haydenbleasel.png', |
| 128 | + }, |
| 129 | + { |
| 130 | + key: nanoid(), |
| 131 | + value: 'You\'re welcome! Let me know if you have any more questions.', |
| 132 | + name: 'AI Assistant', |
| 133 | + avatar: 'https://github.com/openai.png', |
| 134 | + }, |
| 135 | +] |
| 136 | +
|
| 137 | +const visibleMessages = ref<MessageItem[]>([]) |
| 138 | +
|
| 139 | +let timer: number | null = null |
| 140 | +
|
| 141 | +onMounted(() => { |
| 142 | + let index = 0 |
| 143 | + timer = window.setInterval(() => { |
| 144 | + const next = messages[index] |
| 145 | + if (!next) { |
| 146 | + if (timer !== null) { |
| 147 | + clearInterval(timer) |
| 148 | + timer = null |
| 149 | + } |
| 150 | + return |
| 151 | + } |
| 152 | + visibleMessages.value = [...visibleMessages.value, next] |
| 153 | + index += 1 |
| 154 | + }, 500) |
| 155 | +}) |
| 156 | +
|
| 157 | +onUnmounted(() => { |
| 158 | + if (timer !== null) { |
| 159 | + clearInterval(timer) |
| 160 | + timer = null |
| 161 | + } |
| 162 | +}) |
| 163 | +</script> |
| 164 | + |
| 165 | +<template> |
| 166 | + <div class="h-[498px] rounded-xl border"> |
| 167 | + <Conversation class="relative h-full"> |
| 168 | + <ConversationContent class="space-y-2"> |
| 169 | + <Message v-for="(m, idx) in visibleMessages" :key="m.key" :from="idx % 2 === 0 ? 'user' : 'assistant'"> |
| 170 | + <MessageContent>{{ m.value }}</MessageContent> |
| 171 | + <MessageAvatar :src="m.avatar" :name="m.name" /> |
| 172 | + </Message> |
| 173 | + </ConversationContent> |
| 174 | + <ConversationScrollButton /> |
| 175 | + </Conversation> |
| 176 | + </div> |
| 177 | +</template> |
0 commit comments