> ## Documentation Index
> Fetch the complete documentation index at: https://docs.briefer.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# AI assistant

> Use AI to generate code and queries for you.

Briefer comes with an AI assistant that can help you generate code and queries for your pages. It can also automatically fix errors in your code.

<Warning>To use Briefer's AI assistant in the open-source version, you need to have an OpenAI API key. Please see the [configuring an OpenAI API key](#configuring-an-openai-api-key-open-source-version) section below for more information.</Warning>

To use the AI assistant, click on the "Edit with AI" button that appears on the bottom right of your Python and SQL blocks' editor. This will open the AI assistant prompt, where you can ask for help with your code.

<Frame caption="Opening the AI assistant from a Python block.">
  <img src="https://mintcdn.com/briefer/b4K8SyWze93KZnrl/images/open-ai-assistant.png?fit=max&auto=format&n=b4K8SyWze93KZnrl&q=85&s=436b04ddbbe6693b0291dbb2184803d1" alt="Opening the AI assistant" width="2920" height="794" data-path="images/open-ai-assistant.png" />
</Frame>

After prompting the AI assistant, it will show you a diff containing the changes it suggests. You can then choose to apply the changes, test, or discard them.

<Frame caption="An example of a diff generated by the AI assistant.">
  <img src="https://mintcdn.com/briefer/b4K8SyWze93KZnrl/images/ai-assistant-diff.png?fit=max&auto=format&n=b4K8SyWze93KZnrl&q=85&s=662126139b2b42c71afc56c6bd06dd4d" alt="AI assistant diff" width="2920" height="1134" data-path="images/ai-assistant-diff.png" />
</Frame>

## Fixing errors

Whenever your Python or SQL code has an error, the AI assistant can help you fix it. To do this, click on the "Fix with AI" button that appears on the output part of the block when an error is detected.

<Frame caption="Fixing an error with the AI assistant.">
  <img src="https://mintcdn.com/briefer/b4K8SyWze93KZnrl/images/fix-with-ai.png?fit=max&auto=format&n=b4K8SyWze93KZnrl&q=85&s=d7fb72f91fc87990c4ccb0cc77d06dfe" alt="Fixing an error with the AI assistant" width="2920" height="1494" data-path="images/fix-with-ai.png" />
</Frame>

## Configuring an OpenAI API key (open-source version)

In Briefer's open-source version, you need to have an OpenAI API key to use the AI assistant.

To configure your API key, open the settings panel by clicking on "Settings" in the bottom left corner of the screen. Then, add your API key in the "OpenAI API key" field and save it.
