Spaces:
Running
Running
maartenbreddels
commited on
Commit
•
74c8dfc
1
Parent(s):
a8b0740
fix: broke styling
Browse files- wanderlust.py +44 -39
wanderlust.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
import json
|
2 |
import os
|
|
|
3 |
from pathlib import Path
|
4 |
|
5 |
import ipyleaflet
|
6 |
-
from openai import
|
7 |
from openai.types.beta import Thread
|
8 |
|
9 |
-
import time
|
10 |
-
|
11 |
import solara
|
12 |
|
13 |
HERE = Path(__file__).parent
|
@@ -129,26 +128,31 @@ def Map():
|
|
129 |
|
130 |
@solara.component
|
131 |
def ChatMessage(message):
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
else:
|
147 |
solara.v.Icon(children=["mdi-compass-outline"], style_="padding-top: 10px;")
|
148 |
solara.Preformatted(repr(message))
|
149 |
-
else:
|
150 |
-
solara.v.Icon(children=["mdi-compass-outline"], style_="padding-top: 10px;")
|
151 |
-
solara.Preformatted(repr(message))
|
152 |
|
153 |
|
154 |
@solara.component
|
@@ -156,23 +160,25 @@ def ChatBox(children=[]):
|
|
156 |
# this uses a flexbox with column-reverse to reverse the order of the messages
|
157 |
# if we now also reverse the order of the messages, we get the correct order
|
158 |
# but the scroll position is at the bottom of the container automatically
|
159 |
-
solara.
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
176 |
|
177 |
|
178 |
@solara.component
|
@@ -237,9 +243,8 @@ def ChatInterface():
|
|
237 |
classes=["chat-interface"],
|
238 |
):
|
239 |
if len(messages.value) > 0:
|
240 |
-
# The height works effectively as `min-height`, since flex will grow the container to fill the available space
|
241 |
with ChatBox():
|
242 |
-
|
243 |
ChatMessage(message)
|
244 |
|
245 |
with solara.Column():
|
|
|
1 |
import json
|
2 |
import os
|
3 |
+
import time
|
4 |
from pathlib import Path
|
5 |
|
6 |
import ipyleaflet
|
7 |
+
from openai import NotFoundError, OpenAI
|
8 |
from openai.types.beta import Thread
|
9 |
|
|
|
|
|
10 |
import solara
|
11 |
|
12 |
HERE = Path(__file__).parent
|
|
|
128 |
|
129 |
@solara.component
|
130 |
def ChatMessage(message):
|
131 |
+
with solara.Row(style={"align-items": "flex-start"}):
|
132 |
+
# Catch "messages" that are actually tool calls
|
133 |
+
if isinstance(message, dict):
|
134 |
+
icon = "mdi-map" if message["output"] == "Map updated" else "mdi-map-marker"
|
135 |
+
solara.v.Icon(children=[icon], style_="padding-top: 10px;")
|
136 |
+
solara.Markdown(message["output"])
|
137 |
+
elif message.role == "user":
|
138 |
+
solara.Text(message.content[0].text.value, style={"font-weight": "bold;"})
|
139 |
+
elif message.role == "assistant":
|
140 |
+
if message.content[0].text.value:
|
141 |
+
solara.v.Icon(
|
142 |
+
children=["mdi-compass-outline"], style_="padding-top: 10px;"
|
143 |
+
)
|
144 |
+
solara.Markdown(message.content[0].text.value)
|
145 |
+
elif message.content.tool_calls:
|
146 |
+
solara.v.Icon(children=["mdi-map"], style_="padding-top: 10px;")
|
147 |
+
solara.Markdown("*Calling map functions*")
|
148 |
+
else:
|
149 |
+
solara.v.Icon(
|
150 |
+
children=["mdi-compass-outline"], style_="padding-top: 10px;"
|
151 |
+
)
|
152 |
+
solara.Preformatted(repr(message))
|
153 |
else:
|
154 |
solara.v.Icon(children=["mdi-compass-outline"], style_="padding-top: 10px;")
|
155 |
solara.Preformatted(repr(message))
|
|
|
|
|
|
|
156 |
|
157 |
|
158 |
@solara.component
|
|
|
160 |
# this uses a flexbox with column-reverse to reverse the order of the messages
|
161 |
# if we now also reverse the order of the messages, we get the correct order
|
162 |
# but the scroll position is at the bottom of the container automatically
|
163 |
+
with solara.Column(style={"flex-grow": "1"}):
|
164 |
+
solara.Style(
|
165 |
+
"""
|
166 |
+
.chat-box > :last-child{
|
167 |
+
padding-top: 7.5vh;
|
168 |
+
}
|
169 |
+
"""
|
170 |
+
)
|
171 |
+
# The height works effectively as `min-height`, since flex will grow the container to fill the available space
|
172 |
+
solara.Column(
|
173 |
+
style={
|
174 |
+
"flex-grow": "1",
|
175 |
+
"overflow-y": "auto",
|
176 |
+
"height": "100px",
|
177 |
+
"flex-direction": "column-reverse",
|
178 |
+
},
|
179 |
+
classes=["chat-box"],
|
180 |
+
children=list(reversed(children)),
|
181 |
+
)
|
182 |
|
183 |
|
184 |
@solara.component
|
|
|
243 |
classes=["chat-interface"],
|
244 |
):
|
245 |
if len(messages.value) > 0:
|
|
|
246 |
with ChatBox():
|
247 |
+
for message in messages.value:
|
248 |
ChatMessage(message)
|
249 |
|
250 |
with solara.Column():
|