-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversations.py
More file actions
58 lines (51 loc) · 1.58 KB
/
conversations.py
File metadata and controls
58 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import mesop as me
from data_model import State, ChatMessage
def model_conversation():
state = me.state(State)
for convesation in state.conversations:
messages = convesation.messages
with me.box(
style=me.Style(
overflow_y = "auto"
)
):
for message in messages:
if message.role == "user":
user_message(message.content)
else :
model_message(message)
me.box(
key="end_of_messages",
style=me.Style(
margin=me.Margin(
bottom="50vh" if messages[-1].in_progress else 0
)
),
)
def user_message(content: str):
with me.box(
style=me.Style(
background="#e7f2ff",
padding=me.Padding.all(15),
margin=me.Margin.symmetric(vertical=16),
border_radius=16
)
):
me.text(
text="User message: {}".format(content)
)
def model_message(message: ChatMessage):
with me.box(
style=me.Style(
background="white",
padding=me.Padding.all(15),
margin=me.Margin.symmetric(vertical=16),
border_radius=16
)
):
me.markdown(
text=message.content
)
if message.in_progress:
me.progress_spinner()
message.in_progress=False