Skip to content

Commit 5e16068

Browse files
authored
Merge pull request #3 from Axiomatic-AI/add-magic-for-ipython
add code endpoints
2 parents 9e3fa35 + a88d1e9 commit 5e16068

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/axiomatic/magic.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import platformdirs # type: ignore
1+
import platformdirs # type: ignore
22
import os
33

44

@@ -28,20 +28,28 @@ def ax_api(self, query):
2828
print("API key set.")
2929

3030
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
3734

3835
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))
4149

4250
try:
4351
# When running in colab
44-
from google.colab import _frontend # type: ignore
52+
from google.colab import _frontend # type: ignore
4553

4654
_frontend.create_scratch_cell(
4755
f"""# {query}\n{result.code}""", bottom_pane=True

0 commit comments

Comments
 (0)