13
13
# =========== Copyright 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
14
14
import warnings
15
15
from pathlib import Path
16
+ from typing import Literal
16
17
from uuid import uuid4
17
18
18
19
import customtkinter as ctk
@@ -50,8 +51,10 @@ def get_model_instance(model_key: str):
50
51
51
52
def assign_task ():
52
53
task_description = input_entry .get ()
54
+ if not task_description .strip ():
55
+ return
53
56
input_entry .delete (0 , "end" )
54
- display_message (task_description )
57
+ display_message (task_description , "user" )
55
58
56
59
try :
57
60
model = get_model_instance (model_dropdown .get ())
@@ -65,31 +68,44 @@ def assign_task():
65
68
agent_policy = agent_policy ,
66
69
log_dir = log_dir ,
67
70
)
68
-
71
+
69
72
experiment .set_display_callback (display_message )
70
73
71
74
def run_experiment ():
72
75
try :
73
76
experiment .start_benchmark ()
74
77
except Exception as e :
75
- display_message (f"Error: { str (e )} " , "ai " )
78
+ display_message (f"Error: { str (e )} " , "error " )
76
79
77
80
import threading
81
+
78
82
thread = threading .Thread (target = run_experiment , daemon = True )
79
83
thread .start ()
80
-
84
+
81
85
except Exception as e :
82
- display_message (f"Error: { str (e )} " , "ai " )
86
+ display_message (f"Error: { str (e )} " , "error " )
83
87
84
88
85
- def display_message (message , sender = "user" ):
89
+ def display_message (
90
+ message , category : Literal ["system" , "user" , "action" , "error" ] = "system"
91
+ ):
86
92
chat_display .configure (state = "normal" )
87
- if sender == "user" :
88
- chat_display .insert ("end" , f"User: { message } \n " , "user" )
89
- else :
90
- chat_display .insert ("end" , f"AI: { message } \n " , "ai" )
91
- chat_display .tag_config ("user" , justify = "left" , foreground = "blue" )
92
- chat_display .tag_config ("ai" , justify = "right" , foreground = "green" )
93
+ if category == "user" :
94
+ chat_display .insert ("end" , f"{ message } \n " , "user" )
95
+ elif category == "system" :
96
+ chat_display .insert ("end" , f"{ message } \n " , "system" )
97
+ elif category == "error" :
98
+ chat_display .insert ("end" , f"{ message } \n " , "error" )
99
+ elif category == "action" :
100
+ chat_display .insert ("end" , f"{ message } \n " , "action" )
101
+ chat_display .tag_config (
102
+ "user" , justify = "right" , foreground = "lightblue" , wrap = "word"
103
+ )
104
+ chat_display .tag_config ("system" , justify = "left" , foreground = "gray" , wrap = "word" )
105
+ chat_display .tag_config (
106
+ "action" , justify = "left" , foreground = "lightgreen" , wrap = "word"
107
+ )
108
+ chat_display .tag_config ("error" , justify = "left" , foreground = "red" , wrap = "word" )
93
109
chat_display .configure (state = "disabled" )
94
110
chat_display .see ("end" )
95
111
app .update_idletasks ()
@@ -98,7 +114,7 @@ def display_message(message, sender="user"):
98
114
if __name__ == "__main__" :
99
115
log_dir = (Path (__file__ ).parent / "logs" ).resolve ()
100
116
101
- ctk .set_appearance_mode ("System " )
117
+ ctk .set_appearance_mode ("dark " )
102
118
ctk .set_default_color_theme ("blue" )
103
119
104
120
app = ctk .CTk ()
@@ -118,7 +134,7 @@ def display_message(message, sender="user"):
118
134
model_dropdown .pack (pady = 10 , padx = 10 , fill = "x" )
119
135
120
136
chat_display_frame = ctk .CTkFrame (app , width = 480 , height = 880 )
121
- chat_display_frame .pack (pady = 10 , expand = True , fill = "y " )
137
+ chat_display_frame .pack (pady = 10 , padx = 10 , expand = True , fill = "both " )
122
138
chat_display = ctk .CTkTextbox (
123
139
chat_display_frame , width = 480 , height = 880 , state = "disabled" , font = normal_font
124
140
)
0 commit comments