Skip to content

Quickstart

Fast-track to running an AI JSON flow

These docs are a work in progress.
If you get stuck, please join our Discord and let us know.

Python Setup

Create a virtual environment

Install python3.12, and run:

Terminal window
python3.12 -m venv venv

Activate the virtual environment

Terminal window
source venv/bin/activate

Install AI JSON

Terminal window
pip install aijson-meta

aijson-meta is a metapackage – a shortcut to installing aijson-core and some common actionpacks.

IDE Setup

Install Visual Studio Code

Follow the instructions on the download page.

Install the AI JSON extension

Click here, or search for AI JSON & AI YAML in the VSCode marketplace.

Select your virtual environment

  1. Open the command palette (Cmd+Shift+P / Ctrl+Shift+P);
  2. Type and select Python: Select Interpreter;
  3. Choose the virtual environment you created earlier.

Running an Example

Provide a language model

There’s a guide on using any language model, but to get started you can simply:

Create a .env file in your project root with the following contents:

OPENAI_API_KEY=your-api-key

Grab an example

Copy one of the following example files in your project, or see example files for more.

version: "0.1"
flow:
ask:
action: llm
prompt: List some examples of {{ thing }}
extract:
action: extract_list
text:
link: ask

Preview the example

  1. Open the file in VSCode;
  2. Press preview in the top-right corner;
  3. Editing the file, save it, and see the preview update in real-time.

Run the example

Run the example in your code like:

from aijson import Flow
import asyncio
from dotenv import load_dotenv
# load environment variables from .env
load_dotenv()
async def main():
# load the flow
flow = Flow.from_file('simple_list.ai.yaml')
# set variables
flow = flow.set_vars(thing='pizza')
# run it
result = await flow.run()
print(result)
# alternatively, INSTEAD of running it, stream it
async for result in flow.stream():
print(result)
if __name__ == '__main__':
asyncio.run(main())