1010# pages/ml_serving_invoke.py
1111dash .register_page (
1212 __name__ ,
13- path = ' /bi/genie' ,
14- title = ' Genie' ,
15- name = ' Genie' ,
16- category = ' Business Intelligence' ,
17- icon = ' material-symbols:chat'
13+ path = " /bi/genie" ,
14+ title = " Genie" ,
15+ name = " Genie" ,
16+ category = " Business Intelligence" ,
17+ icon = " material-symbols:chat"
1818)
1919
2020# Initialize WorkspaceClient with error handling
2626
2727def dash_dataframe (df : pd .DataFrame ) -> dash .dash_table .DataTable :
2828 table = dash .dash_table .DataTable (
29- data = df .to_dict (' records' ),
30- columns = [{' name' : i , 'id' : i } for i in df .columns ],
29+ data = df .to_dict (" records" ),
30+ columns = [{" name" : i , "id" : i } for i in df .columns ],
3131 style_table = {
32- ' overflowX' : ' auto' ,
33- ' minWidth' : ' 100%' ,
32+ " overflowX" : " auto" ,
33+ " minWidth" : " 100%" ,
3434 },
3535 style_header = {
36- ' backgroundColor' : ' #f8f9fa' ,
37- ' fontWeight' : ' bold' ,
38- ' border' : ' 1px solid #dee2e6' ,
39- ' padding' : ' 12px 15px'
36+ " backgroundColor" : " #f8f9fa" ,
37+ " fontWeight" : " bold" ,
38+ " border" : " 1px solid #dee2e6" ,
39+ " padding" : " 12px 15px"
4040 },
4141 style_cell = {
42- ' padding' : ' 12px 15px' ,
43- ' textAlign' : ' left' ,
44- ' border' : ' 1px solid #dee2e6' ,
45- ' maxWidth' : ' 200px' ,
46- ' overflow' : ' hidden' ,
47- ' textOverflow' : ' ellipsis'
42+ " padding" : " 12px 15px" ,
43+ " textAlign" : " left" ,
44+ " border" : " 1px solid #dee2e6" ,
45+ " maxWidth" : " 200px" ,
46+ " overflow" : " hidden" ,
47+ " textOverflow" : " ellipsis"
4848 },
4949 style_data = {
50- ' whiteSpace' : ' normal' ,
51- ' height' : ' auto' ,
50+ " whiteSpace" : " normal" ,
51+ " height" : " auto" ,
5252 },
5353
5454 page_size = 10 ,
55- page_action = ' native' ,
56- sort_action = ' native' ,
57- sort_mode = ' multi'
55+ page_action = " native" ,
56+ sort_action = " native" ,
57+ sort_mode = " multi"
5858 )
5959
6060 return table
@@ -69,7 +69,7 @@ def format_message_display(chat_history: List[Dict]) -> List[Dict]:
6969 if "data" in message :
7070 display .append (message ["data" ])
7171 if "code" in message :
72- display .append (dcc .Markdown (f''' ```sql { message [" code" ]} ```''' , className = "border rounded p-3" ))
72+ display .append (dcc .Markdown (f" ```sql { message [' code' ]} ```" , className = "border rounded p-3" ))
7373 chat_display .append (html .Div (display , className = f"chat-message { message ['role' ]} -message" ))
7474
7575 return chat_display
@@ -143,7 +143,7 @@ def layout():
143143 ),
144144 dbc .InputGroup ([
145145 dbc .Input (
146- id = "question-input " ,
146+ id = "prompt " ,
147147 type = "text" ,
148148 placeholder = "Ask your question..." ,
149149 style = {
@@ -162,8 +162,8 @@ def layout():
162162
163163 # Chat history area
164164 html .Div (id = "chat-history" , className = "mt-4" ),
165- dcc .Store (id = ' chat-history-store' ),
166- dcc .Store (id = ' conversation-id' ),
165+ dcc .Store (id = " chat-history-store" ),
166+ dcc .Store (id = " conversation-id" ),
167167
168168 # Status/error messages
169169 html .Div (id = "status-area-genie" , className = "mt-3" )
@@ -246,12 +246,13 @@ def process_genie_response(response):
246246 ], fluid = True , className = "py-4" )
247247
248248@callback (
249- [Output ('chat-history-store' , 'data' , allow_duplicate = True ),
250- Output ('chat-history' , 'children' , allow_duplicate = True )],
249+ [Output ("chat-history-store" , "data" , allow_duplicate = True ),
250+ Output ("chat-history" , "children" , allow_duplicate = True ),
251+ Output ("conversation-id" , "value" , allow_duplicate = True )],
251252 Input ("chat-button" , "n_clicks" ),
252253 [State ("genie-space-id-input" , "value" ),
253254 State ("conversation-id" , "value" ),
254- State ("question-input " , "value" ),
255+ State ("prompt " , "value" ),
255256 State ("chat-history-store" , "data" )],
256257 prevent_initial_call = True
257258)
@@ -277,7 +278,7 @@ def update_chat(n_clicks, genie_space_id, conversation_id, prompt, chat_history)
277278
278279 chat_display = format_message_display (chat_history )
279280
280- return chat_history , chat_display
281+ return chat_history , chat_display , conversation_id
281282
282283 except Exception as e :
283284 return dash .no_update , dbc .Alert (
@@ -286,4 +287,4 @@ def update_chat(n_clicks, genie_space_id, conversation_id, prompt, chat_history)
286287 )
287288
288289# Make layout available at module level
289- __all__ = [' layout' ]
290+ __all__ = [" layout" ]
0 commit comments