Skip to content

Commit

Permalink
fix: broke styling
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Nov 10, 2023
1 parent a8b0740 commit 74c8dfc
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions wanderlust.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import json
import os
import time
from pathlib import Path

import ipyleaflet
from openai import OpenAI, NotFoundError
from openai import NotFoundError, OpenAI
from openai.types.beta import Thread

import time

import solara

HERE = Path(__file__).parent
Expand Down Expand Up @@ -129,50 +128,57 @@ def Map():

@solara.component
def ChatMessage(message):
# Catch "messages" that are actually tool calls
if isinstance(message, dict):
icon = "mdi-map" if message["output"] == "Map updated" else "mdi-map-marker"
solara.v.Icon(children=[icon], style_="padding-top: 10px;")
solara.Markdown(message["output"])
elif message.role == "user":
solara.Text(message.content[0].text.value, style={"font-weight": "bold;"})
elif message.role == "assistant":
if message.content[0].text.value:
solara.v.Icon(children=["mdi-compass-outline"], style_="padding-top: 10px;")
solara.Markdown(message.content[0].text.value)
elif message.content.tool_calls:
solara.v.Icon(children=["mdi-map"], style_="padding-top: 10px;")
solara.Markdown("*Calling map functions*")
with solara.Row(style={"align-items": "flex-start"}):
# Catch "messages" that are actually tool calls
if isinstance(message, dict):
icon = "mdi-map" if message["output"] == "Map updated" else "mdi-map-marker"
solara.v.Icon(children=[icon], style_="padding-top: 10px;")
solara.Markdown(message["output"])
elif message.role == "user":
solara.Text(message.content[0].text.value, style={"font-weight": "bold;"})
elif message.role == "assistant":
if message.content[0].text.value:
solara.v.Icon(
children=["mdi-compass-outline"], style_="padding-top: 10px;"
)
solara.Markdown(message.content[0].text.value)
elif message.content.tool_calls:
solara.v.Icon(children=["mdi-map"], style_="padding-top: 10px;")
solara.Markdown("*Calling map functions*")
else:
solara.v.Icon(
children=["mdi-compass-outline"], style_="padding-top: 10px;"
)
solara.Preformatted(repr(message))
else:
solara.v.Icon(children=["mdi-compass-outline"], style_="padding-top: 10px;")
solara.Preformatted(repr(message))
else:
solara.v.Icon(children=["mdi-compass-outline"], style_="padding-top: 10px;")
solara.Preformatted(repr(message))


@solara.component
def ChatBox(children=[]):
# this uses a flexbox with column-reverse to reverse the order of the messages
# if we now also reverse the order of the messages, we get the correct order
# but the scroll position is at the bottom of the container automatically
solara.Style(
"""
.chat-box > :last-child{
padding-top: 7.5vh;
}
"""
)
solara.Column(
style={
"flex-grow": "1",
"overflow-y": "auto",
"height": "100px",
"flex-direction": "column-reverse",
},
classes=["chat-box"],
children=reversed(children),
)
with solara.Column(style={"flex-grow": "1"}):
solara.Style(
"""
.chat-box > :last-child{
padding-top: 7.5vh;
}
"""
)
# The height works effectively as `min-height`, since flex will grow the container to fill the available space
solara.Column(
style={
"flex-grow": "1",
"overflow-y": "auto",
"height": "100px",
"flex-direction": "column-reverse",
},
classes=["chat-box"],
children=list(reversed(children)),
)


@solara.component
Expand Down Expand Up @@ -237,9 +243,8 @@ def poll():
classes=["chat-interface"],
):
if len(messages.value) > 0:
# The height works effectively as `min-height`, since flex will grow the container to fill the available space
with ChatBox():
with solara.Row(style={"align-items": "flex-start"}):
for message in messages.value:
ChatMessage(message)

with solara.Column():
Expand Down

0 comments on commit 74c8dfc

Please sign in to comment.