|
1 |
| -import platformdirs # type: ignore |
| 1 | +import platformdirs # type: ignore |
2 | 2 | import os
|
3 | 3 |
|
4 | 4 |
|
@@ -28,20 +28,28 @@ def ax_api(self, query):
|
28 | 28 | print("API key set.")
|
29 | 29 |
|
30 | 30 | def ax_query(self, query, cell=None):
|
31 |
| - # NOTE: we need to add additional dependencies to the requirements! |
32 |
| - # TODO: This would actually be a different dependency group |
33 |
| - # we don't want to force users to install IPython! |
34 |
| - from IPython import get_ipython # type: ignore |
35 |
| - from IPython.core.magic import register_line_cell_magic, register_line_magic # type: ignore |
36 |
| - from IPython.display import HTML, display # type: ignore |
| 31 | + from IPython import get_ipython # type: ignore |
| 32 | + from IPython.core.magic import register_line_cell_magic, register_line_magic # type: ignore |
| 33 | + from IPython.display import HTML, display # type: ignore |
37 | 34 |
|
38 | 35 | if self.api_key:
|
39 |
| - result = self.ax.experimental.magic_request(query=query, cell=cell) |
40 |
| - display(HTML(result.response)) |
| 36 | + if cell: |
| 37 | + # 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}") |
| 42 | + feedback = "" # TODO: add feedback according to interface |
| 43 | + result = self.ax.pic.refine(query=query, code=cell, feedback=feedback) |
| 44 | + else: |
| 45 | + # GENERATE FROM SCRATCH |
| 46 | + result = self.ax.pic.generate(query=query) |
| 47 | + |
| 48 | + display(HTML(result.thought_text)) |
41 | 49 |
|
42 | 50 | try:
|
43 | 51 | # When running in colab
|
44 |
| - from google.colab import _frontend # type: ignore |
| 52 | + from google.colab import _frontend # type: ignore |
45 | 53 |
|
46 | 54 | _frontend.create_scratch_cell(
|
47 | 55 | f"""# {query}\n{result.code}""", bottom_pane=True
|
|
0 commit comments