Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❔ Store %%ai answer into a variable #603

Closed
adriens opened this issue Jan 25, 2024 · 3 comments
Closed

❔ Store %%ai answer into a variable #603

adriens opened this issue Jan 25, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@adriens
Copy link
Contributor

adriens commented Jan 25, 2024

❔ About

%%ai is such a cumfortable way to call many AI services that sometimes, I would like use it as a function instead of sending the output straight into the next cell.

🎯 Objectives

The main purpose of this issue is to:

  • If already possible : document how to send output into a variable
  • If not already possible : Make it possible to send output into a variable (then document it πŸ˜… )
@adriens adriens added the enhancement New feature or request label Jan 25, 2024
@adriens adriens changed the title ❔ Store %%ai answer into a variable ❔ Store %%ai answer into a variable Jan 25, 2024
@JasonWeill
Copy link
Collaborator

@adriens Thanks for opening this issue! You can use IPython's built-in %%capture magic command to capture the outputs of a cell, including a cell that contains a magic command.

In one cell, run:

%%capture earth
%%ai anthropic:claude-v1
Tell me interesting facts about the size of the Earth

Then, in the following cell, you can iterate over the outputs and display them:

for o in earth.outputs:
    display(o)

Alternatively, you can use the special Out variable to refer to a cell's outputs. Each cell you run has a number, which corresponds to the index of Out that refers to the cell's outputs. If you run the following command in a cell, which gets assigned to number 14:

%%ai anthropic:claude-v1
Tell me interesting facts about the size of the Earth

Then, after this cell finishes running, you can refer to its outputs as Out[14].

@adriens
Copy link
Contributor Author

adriens commented Jan 26, 2024

I'm giving it a try then will close the issue πŸ‘

@adriens
Copy link
Contributor Author

adriens commented Jan 26, 2024

All perfect, : thanks a lot for your support :

image

@adriens adriens closed this as completed Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants