@@ -35,32 +35,40 @@ def ax_query(self, query, cell=None):
3535 if self .api_key :
3636 if cell :
3737 # REFINE
38- ...
39- ipython = get_ipython ()
40- last_cell = ipython .history_manager .input_hist_parsed [- 1 ]
41- print (f"Last executed cell:\n { last_cell } " )
4238 feedback = "" # TODO: add feedback according to interface
4339 result = self .ax .pic .refine (query = query , code = cell , feedback = feedback )
4440 else :
4541 # GENERATE FROM SCRATCH
4642 result = self .ax .pic .generate (query = query )
4743
48- display (HTML (result .thought_text ))
49-
50- try :
51- # When running in colab
52- from google .colab import _frontend # type: ignore
53-
54- _frontend .create_scratch_cell (
55- f"""# { query } \n { result .code } """ , bottom_pane = True
56- )
57- except Exception as e :
58- # When running in jupyter
59- get_ipython ().set_next_input (f"{ result .code } " , replace = False )
44+ # Process output
45+ output = result .thought_text .replace ("\n " , "<br>" )
46+ html_content = (
47+ "<div style='font-family: Arial, sans-serif; line-height: 1.5;'>"
48+ )
49+ html_content += (
50+ f"<div style='color: #6EB700;'><strong>AX:</strong> { output } </div>"
51+ )
52+ display (HTML (html_content ))
53+
54+ # Process code
55+ # remove last three lines (saving file)
56+ if result .code :
57+ code = "\n " .join (result .code .split ("\n " )[:- 3 ] + ["c" ])
58+ try :
59+ # When running in colab
60+ from google .colab import _frontend # type: ignore
61+
62+ _frontend .create_scratch_cell (
63+ f"""# { query } \n { code } """ , bottom_pane = True
64+ )
65+ except Exception as e :
66+ # When running in jupyter
67+ get_ipython ().set_next_input (f"{ code } " , replace = False )
6068
6169 else :
6270 print (
63- "Please set your Axiomatic API key first with the command %ax_api API_KEY. Request the api key at our Customer Service."
71+ "Please set your Axiomatic API key first with the command %ax_api API_KEY and restart the kernel . Request the api key at our Customer Service."
6472 )
6573
6674 def ax_fix (self , query , cell = None ):
0 commit comments