maartenbreddels commited on
Commit
74c8dfc
1 Parent(s): a8b0740

fix: broke styling

Browse files
Files changed (1) hide show
  1. 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 OpenAI, NotFoundError
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
- # 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(children=["mdi-compass-outline"], style_="padding-top: 10px;")
142
- solara.Markdown(message.content[0].text.value)
143
- elif message.content.tool_calls:
144
- solara.v.Icon(children=["mdi-map"], style_="padding-top: 10px;")
145
- solara.Markdown("*Calling map functions*")
 
 
 
 
 
 
 
 
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.Style(
160
- """
161
- .chat-box > :last-child{
162
- padding-top: 7.5vh;
163
- }
164
- """
165
- )
166
- solara.Column(
167
- style={
168
- "flex-grow": "1",
169
- "overflow-y": "auto",
170
- "height": "100px",
171
- "flex-direction": "column-reverse",
172
- },
173
- classes=["chat-box"],
174
- children=reversed(children),
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
- with solara.Row(style={"align-items": "flex-start"}):
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():