-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement chain of thoughts for chatbot - WF-88
- Loading branch information
Showing
6 changed files
with
230 additions
and
10 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
85 changes: 85 additions & 0 deletions
85
src/ui/src/components/core/content/CoreChatBot/ThoughtProcess/ThoughtProcess.vue
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,85 @@ | ||
<template> | ||
<ThoughtProcessStep | ||
v-if="pending" | ||
:content="String(pendingContent)" | ||
pending | ||
/> | ||
<div v-else class="ThoughtProcess"> | ||
<div> | ||
<button | ||
class="ThoughtProcess__toggler" | ||
:class="{ | ||
'ThoughtProcess__toggler--expanded': isExpanded, | ||
}" | ||
@click="isExpanded = !isExpanded" | ||
> | ||
<i class="icon material-symbols-outlined" aria-hidden="true">{{ | ||
togglerIcon | ||
}}</i> | ||
Though process | ||
</button> | ||
</div> | ||
<ThoughtProcessSteps | ||
v-show="isExpanded" | ||
:aria-expanded="isExpanded" | ||
:content="content" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, PropType, ref } from "vue"; | ||
import ThoughtProcessStep from "./ThoughtProcessStep.vue"; | ||
import ThoughtProcessSteps from "./ThoughtProcessSteps.vue"; | ||
import type { Message } from "../CoreChatbotMessage.vue"; | ||
const props = defineProps({ | ||
content: { | ||
type: [String, Array] as PropType<Message["content"]>, | ||
required: true, | ||
}, | ||
pending: { type: Boolean }, | ||
}); | ||
const isExpanded = ref(false); | ||
const togglerIcon = computed(() => | ||
isExpanded.value ? "arrow_drop_down" : "arrow_drop_up", | ||
); | ||
function getLastContent(content: Message["content"]): string | undefined { | ||
if (!Array.isArray(content)) return content; | ||
const element = content.at(-1); | ||
return Array.isArray(element) ? getLastContent(element) : element; | ||
} | ||
const pendingContent = computed(() => getLastContent(props.content)); | ||
</script> | ||
|
||
<style scoped> | ||
.ThoughtProcess__toggler { | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
border-radius: 16px; | ||
border: none; | ||
height: 24px; | ||
padding: 0 8px; | ||
cursor: pointer; | ||
background-color: transparent; | ||
} | ||
.ThoughtProcess__toggler:hover { | ||
background-color: var(--separatorColor); | ||
} | ||
.ThoughtProcess__toggler--expanded { | ||
background-color: var(--separatorColor); | ||
margin-bottom: 16px; | ||
} | ||
.ThoughtProcess__toggler i { | ||
font-size: 20px; | ||
} | ||
</style> |
50 changes: 50 additions & 0 deletions
50
src/ui/src/components/core/content/CoreChatBot/ThoughtProcess/ThoughtProcessStep.vue
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,50 @@ | ||
<template> | ||
<ThoughtProcessSteps | ||
v-if="Array.isArray(content)" | ||
:content="content" | ||
style="margin-left: 12px" | ||
/> | ||
<div | ||
v-else | ||
class="ThoughtProcessStep" | ||
:class="{ 'ThoughtProcessStep--pending': pending }" | ||
> | ||
{{ content }} | ||
<CoreChatbotLoader v-if="pending" style="width: auto" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { defineAsyncComponent, PropType } from "vue"; | ||
import type { Message } from "../CoreChatbotMessage.vue"; | ||
import ThoughtProcessSteps from "./ThoughtProcessSteps.vue"; | ||
const CoreChatbotLoader = defineAsyncComponent( | ||
() => import("../CoreChatbotLoader.vue"), | ||
); | ||
defineProps({ | ||
content: { | ||
type: [String, Array] as PropType<Message["content"]>, | ||
required: true, | ||
}, | ||
pending: { type: Boolean }, | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.ThoughtProcessStep { | ||
position: relative; | ||
padding: 8px 16px; | ||
border: 1px solid var(--separatorColor); | ||
border-radius: 8px; | ||
box-shadow: var(--containerShadow); | ||
background-color: var(--containerBackgroundColor); | ||
} | ||
.ThoughtProcessStep--pending { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
} | ||
</style> |
49 changes: 49 additions & 0 deletions
49
src/ui/src/components/core/content/CoreChatBot/ThoughtProcess/ThoughtProcessSteps.vue
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,49 @@ | ||
<template> | ||
<ul class="ThoughtProcessSteps"> | ||
<li | ||
v-for="(line, index) of contentAsArray" | ||
:key="index" | ||
class="ThoughtProcessSteps__step" | ||
> | ||
<ThoughtProcessStep :content="line" /> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, PropType } from "vue"; | ||
import type { Message } from "../CoreChatbotMessage.vue"; | ||
import ThoughtProcessStep from "./ThoughtProcessStep.vue"; | ||
const props = defineProps({ | ||
content: { | ||
type: [String, Array] as PropType<Message["content"]>, | ||
required: true, | ||
}, | ||
}); | ||
const contentAsArray = computed(() => | ||
Array.isArray(props.content) ? props.content : [props.content], | ||
); | ||
</script> | ||
|
||
<style scoped> | ||
.ThoughtProcessSteps { | ||
display: flex; | ||
gap: 8px; | ||
flex-direction: column; | ||
list-style: none; | ||
position: relative; | ||
} | ||
/* vertical line behind the messages */ | ||
.ThoughtProcessSteps::before { | ||
content: ""; | ||
background-color: var(--separatorColor); | ||
width: 1px; | ||
height: 100%; | ||
position: absolute; | ||
left: 17px; | ||
} | ||
</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
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