maartenbreddels commited on
Commit
4153745
1 Parent(s): 1d70dc9

refactor: make ChatMessage its own component

Browse files
Files changed (1) hide show
  1. wanderlust.py +47 -45
wanderlust.py CHANGED
@@ -122,6 +122,51 @@ def Map():
122
  )
123
 
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  @solara.component
126
  def ChatInterface():
127
  prompt = solara.use_reactive("")
@@ -196,51 +241,8 @@ def ChatInterface():
196
  ):
197
  for message in reversed(messages.value):
198
  with solara.Row(style={"align-items": "flex-start"}):
199
- # Catch "messages" that are actually tool calls
200
- if isinstance(message, dict):
201
- icon = (
202
- "mdi-map"
203
- if message["output"] == "Map updated"
204
- else "mdi-map-marker"
205
- )
206
- solara.v.Icon(children=[icon], style_="padding-top: 10px;")
207
- solara.Markdown(message["output"])
208
- elif message.role == "user":
209
- solara.Text(
210
- message.content[0].text.value,
211
- classes=["chat-message", "user-message"],
212
- )
213
- elif message.role == "assistant":
214
- if message.content[0].text.value:
215
- solara.v.Icon(
216
- children=["mdi-compass-outline"],
217
- style_="padding-top: 10px;",
218
- )
219
- solara.Markdown(message.content[0].text.value)
220
- elif message.content.tool_calls:
221
- solara.v.Icon(
222
- children=["mdi-map"],
223
- style_="padding-top: 10px;",
224
- )
225
- solara.Markdown("*Calling map functions*")
226
- else:
227
- solara.v.Icon(
228
- children=["mdi-compass-outline"],
229
- style_="padding-top: 10px;",
230
- )
231
- solara.Preformatted(
232
- repr(message),
233
- classes=["chat-message", "assistant-message"],
234
- )
235
- else:
236
- solara.v.Icon(
237
- children=["mdi-compass-outline"],
238
- style_="padding-top: 10px;",
239
- )
240
- solara.Preformatted(
241
- repr(message),
242
- classes=["chat-message", "assistant-message"],
243
- )
244
  with solara.Column():
245
  solara.InputText(
246
  label="Ask your question here",
 
122
  )
123
 
124
 
125
+ @solara.component
126
+ def ChatMessage(message):
127
+ # Catch "messages" that are actually tool calls
128
+ if isinstance(message, dict):
129
+ icon = "mdi-map" if message["output"] == "Map updated" else "mdi-map-marker"
130
+ solara.v.Icon(children=[icon], style_="padding-top: 10px;")
131
+ solara.Markdown(message["output"])
132
+ elif message.role == "user":
133
+ solara.Text(
134
+ message.content[0].text.value,
135
+ classes=["chat-message", "user-message"],
136
+ )
137
+ elif message.role == "assistant":
138
+ if message.content[0].text.value:
139
+ solara.v.Icon(
140
+ children=["mdi-compass-outline"],
141
+ style_="padding-top: 10px;",
142
+ )
143
+ solara.Markdown(message.content[0].text.value)
144
+ elif message.content.tool_calls:
145
+ solara.v.Icon(
146
+ children=["mdi-map"],
147
+ style_="padding-top: 10px;",
148
+ )
149
+ solara.Markdown("*Calling map functions*")
150
+ else:
151
+ solara.v.Icon(
152
+ children=["mdi-compass-outline"],
153
+ style_="padding-top: 10px;",
154
+ )
155
+ solara.Preformatted(
156
+ repr(message),
157
+ classes=["chat-message", "assistant-message"],
158
+ )
159
+ else:
160
+ solara.v.Icon(
161
+ children=["mdi-compass-outline"],
162
+ style_="padding-top: 10px;",
163
+ )
164
+ solara.Preformatted(
165
+ repr(message),
166
+ classes=["chat-message", "assistant-message"],
167
+ )
168
+
169
+
170
  @solara.component
171
  def ChatInterface():
172
  prompt = solara.use_reactive("")
 
241
  ):
242
  for message in reversed(messages.value):
243
  with solara.Row(style={"align-items": "flex-start"}):
244
+ ChatMessage(message)
245
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  with solara.Column():
247
  solara.InputText(
248
  label="Ask your question here",