17
17
from playground .global_values import GlobalValues
18
18
import argparse
19
19
20
- thread = api .create_thread () # create a new thread everytime this is run
20
+ # thread = api.create_thread() # create a new thread everytime this is run
21
21
actions_manager = ActionsManager ()
22
22
semantic_manager = SemanticManager ()
23
23
28
28
logger = Logger ("logs.txt" )
29
29
logger .reset_logs ()
30
30
31
+ current_thread = None
31
32
32
- def wrap_latex_with_markdown (text ):
33
- # system = """You are a LaTeX genius and equation genius!,
34
- # Your job is to identify LaTeX and equations in the text.
35
- # For each block of LaTeX or equation text you will wrap it with $ if the block is inline,
36
- # or with $$ if the block is on its own line.
37
- # Examples:
38
- # inline x^2 + y^2 = z^2 with text -> inline $x^2 + y^2 = z^2$ with text
39
- # x^2 + y^2 = z^2 -> $$x^2 + y^2 = z^2$$
40
- # """
41
- # user = text
42
- # text = semantic_manager.get_semantic_response(system, user)
43
- # return text
44
- # Regular expression to find LaTeX enclosed in [] or ()
45
- bracket_pattern = re .compile (r"\[(.*?)\]" )
46
- parenthesis_pattern = re .compile (r"\((.*?)\)" )
47
33
48
- # Replace LaTeX within brackets with Markdown inline math
49
- text = bracket_pattern .sub (r"$$\1$$" , text )
34
+ def create_new_thread ():
35
+ global current_thread
36
+ current_thread = api .create_thread ()
37
+ return "New thread created."
50
38
51
- # Replace LaTeX within parentheses with Markdown inline math
52
- text = parenthesis_pattern .sub (r"$$\1$$" , text )
53
- return text
39
+
40
+ create_new_thread ()
54
41
55
42
56
43
def print_like_dislike (x : gr .LikeData ):
@@ -90,7 +77,9 @@ def ask_assistant(assistant_id, history, message):
90
77
history .append ((message ["text" ], None ))
91
78
content = message ["text" ]
92
79
if content or attachments : # only create a message if there is content
93
- api .create_thread_message (thread .id , "user" , content , attachments = attachments )
80
+ api .create_thread_message (
81
+ current_thread .id , "user" , content , attachments = attachments
82
+ )
94
83
95
84
return history , gr .MultimodalTextbox (value = None , interactive = False )
96
85
@@ -122,6 +111,15 @@ def get_file_path(file):
122
111
123
112
124
113
def run (history , assistant_id , artifacts ):
114
+ if current_thread is None :
115
+ history .append ((None , "Please create a new thread first." ))
116
+ yield (
117
+ history ,
118
+ artifacts ,
119
+ gr .update (visible = artifacts ),
120
+ )
121
+ return
122
+
125
123
assistant = api .retrieve_assistant (assistant_id )
126
124
output_queue = queue .Queue ()
127
125
eh = EventHandler (output_queue )
@@ -146,7 +144,7 @@ def stream_worker(assistant_id, thread_id, event_handler):
146
144
output_queue .put (("text" , text ))
147
145
148
146
# Start the initial stream
149
- thread_id = thread .id
147
+ thread_id = current_thread .id
150
148
initial_thread = threading .Thread (
151
149
target = stream_worker , args = (assistant .id , thread_id , eh )
152
150
)
@@ -272,17 +270,24 @@ def main_interface():
272
270
elem_id = "chatbot" ,
273
271
bubble_full_width = True ,
274
272
container = True ,
275
- avatar_images = ["avatar1.png" , "avatar2 .png" ],
273
+ avatar_images = ["avatar1.png" , "avatar2_lite .png" ],
276
274
layout = "panel" ,
277
275
)
278
-
279
- chat_input = gr .MultimodalTextbox (
280
- interactive = True ,
281
- file_types = ["image" ],
282
- placeholder = "Enter message or upload file..." ,
283
- show_label = False ,
284
- elem_id = "chat_input" ,
285
- )
276
+ with gr .Row ():
277
+ with gr .Column (scale = 12 ):
278
+ chat_input = gr .MultimodalTextbox (
279
+ interactive = True ,
280
+ file_types = ["image" ],
281
+ placeholder = "Enter message or upload file..." ,
282
+ show_label = False ,
283
+ elem_id = "chat_input" ,
284
+ )
285
+ with gr .Column (scale = 1 ):
286
+ new_thread_button = gr .Button (
287
+ "Create New Thread" , size = "lg"
288
+ )
289
+
290
+ new_thread_button .click (create_new_thread , [], None )
286
291
287
292
chat_msg = chat_input .submit (
288
293
ask_assistant ,
@@ -303,7 +308,7 @@ def main_interface():
303
308
304
309
chatbot .like (print_like_dislike , None , None )
305
310
306
- with gr .Tab (label = "Behavior Tree Runner" ):
311
+ with gr .Tab (label = "Agentic Behavior Tree Runner" ):
307
312
with gr .Column (scale = 4 ):
308
313
btree_runner = btree_runner_panel ()
309
314
0 commit comments