Skip to content

Commit

Permalink
🚸 (openai) Improve streaming bubble sequence and visual
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 9, 2023
1 parent 8eb9f25 commit 49826d1
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ export const createChatCompletionOpenAI = async (
options.advancedSettings?.temperature
)

const assistantMessageVariableName = typebot.variables.find(
(variable) =>
options.responseMapping.find(
(m) => m.valueToExtract === 'Message content'
)?.variableId === variable.id
)?.name

if (
isPlaneteScale() &&
isCredentialsV2(credentials) &&
newSessionState.isStreamEnabled &&
!newSessionState.whatsApp
!newSessionState.whatsApp &&
isNextBubbleMessageWithAssistantMessage(typebot)(
blockId,
assistantMessageVariableName
)
) {
const assistantMessageVariableName = typebot.variables.find(
(variable) =>
options.responseMapping.find(
(m) => m.valueToExtract === 'Message content'
)?.variableId === variable.id
)?.name

return {
clientSideActions: [
{
Expand All @@ -93,10 +97,6 @@ export const createChatCompletionOpenAI = async (
content?: string
role: (typeof chatCompletionMessageRoles)[number]
}[],
displayStream: isNextBubbleMessageWithAssistantMessage(typebot)(
blockId,
assistantMessageVariableName
),
},
expectsDedicatedReply: true,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.2.3",
"version": "0.2.4",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export const ChatChunk = (props: Props) => {
<div
class="flex flex-col flex-1 gap-2"
style={{
width: isMobile() ? 'calc(100% - 32px)' : 'calc(100% - 48px)',
'max-width': isMobile()
? 'calc(100% - 32px)'
: 'calc(100% - 48px)',
'margin-right': props.theme.chat.guestAvatar?.isEnabled
? isMobile()
? '32px'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ export const ConversationContainer = (props: Props) => {
context={props.context}
hideAvatar={
!chatChunk.input &&
!chatChunk.streamingMessageId &&
index() < chatChunks().length - 1
((chatChunks()[index() + 1]?.messages ?? 0).length > 0 ||
chatChunks()[index() + 1]?.streamingMessageId !== undefined ||
isSending())
}
hasError={hasError() && index() === chatChunks().length - 1}
onNewBubbleDisplayed={handleNewBubbleDisplayed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const StreamingBubble = (props: Props) => {
return (
<div class="flex flex-col animate-fade-in">
<div class="flex w-full items-center">
<div class="flex relative items-start typebot-host-bubble w-full">
<div class="flex relative items-start typebot-host-bubble max-w-full">
<div
class="flex items-center absolute px-4 py-2 bubble-typing "
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,52 @@ export const PlateElement = (props: Props) => (
</For>
</a>
</Match>
<Match when={props.element.type !== 'a'}>
<Match when={props.element.type === 'ol'}>
<ol>
<For each={props.element.children as TDescendant[]}>
{(child) => (
<PlateElement
element={child}
isUniqueChild={
(props.element.children as TDescendant[])?.length === 1
}
inElement={true}
/>
)}
</For>
</ol>
</Match>
<Match when={props.element.type === 'ul'}>
<ul>
<For each={props.element.children as TDescendant[]}>
{(child) => (
<PlateElement
element={child}
isUniqueChild={
(props.element.children as TDescendant[])?.length === 1
}
inElement={true}
/>
)}
</For>
</ul>
</Match>
<Match when={props.element.type === 'li'}>
<li>
<For each={props.element.children as TDescendant[]}>
{(child) => (
<PlateElement
element={child}
isUniqueChild={
(props.element.children as TDescendant[])?.length === 1
}
inElement={true}
/>
)}
</For>
</li>
</Match>
<Match when={true}>
<ElementRoot
element={props.element as TElement}
inElement={props.inElement ?? false}
Expand Down
5 changes: 1 addition & 4 deletions packages/embeds/js/src/utils/executeClientSideActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export const executeClientSideAction = async ({
const { error, message } = await streamChat(context)(
clientSideAction.streamOpenAiChatCompletion.messages,
{
onMessageStream: clientSideAction.streamOpenAiChatCompletion
.displayStream
? onMessageStream
: undefined,
onMessageStream,
}
)
if (error)
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.2.3",
"version": "0.2.4",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.2.3",
"version": "0.2.4",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion packages/schemas/features/chat/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ const clientSideActionSchema = z
messages: z.array(
chatCompletionMessageSchema.pick({ content: true, role: true })
),
displayStream: z.boolean().optional(),
}),
})
)
Expand Down

3 comments on commit 49826d1

@vercel
Copy link

@vercel vercel bot commented on 49826d1 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

webwhatsapp.work
whatisappweb.com
www.pantaflow.ai
zap.fundviser.in
acordocorreto.com
akses.sifucrm.com
analistamines.com
app.bouclidom.com
app.chatforms.net
appbotcontato.com
appmillion.online
averdadehoje.site
bot.cerograsa.com
bot.chatbotcv.com
bot.hostnation.de
bot.ketoolife.com
bot.phuonghub.com
bot.reviewamp.com
bot.reviewzer.com
bot.uluhub.com.br
cares.urlabout.me
chat.ezbooking.ai
chat.gaswadern.de
chat.gniorder.com
chat.leadmagic.io
chat.onrentme.com
chat.rojie.online
chatdocidadao.com
chatwebonline.com
ds-leadmagnet.com
encode.share5.net
fmm.wpwakanda.com
footballmeetup.ie
gentleman-shop.fr
island.wakanda.is
k1.kandabrand.com
kp.pedroknoll.com
kylebot.goafk.com
lb.ticketfute.com
mariwelash.com.br
metodoelev.com.br
nutriandreia.shop
order.chatjer.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
pcb.drapamela.com
seribusebulan.com
softwarelucra.com
support.triplo.ai
survey.collab.day
test.eqfeqfeq.com
viewer.typebot.io
welcome.triplo.ai
www.thegymgame.it
zeropendencia.com
1988.bouclidom.com
a.onewebcenter.com
amostra-safe.click
andreimayer.com.br
bot.innovacion.fun
viewer-v2-typebot-io.vercel.app
mdb.assessoria.fernanda.progenbr.com
mdb.assessoria.jbatista.progenbr.com
mdb.assessoria.mauricio.progenbr.com
mdb.evento.autocadastro.progenbr.com
form.shopmercedesbenzsouthorlando.com
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

@vercel
Copy link

@vercel vercel bot commented on 49826d1 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 49826d1 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.