# AI Code Generation

This functionality allows users to quickly generate code snippets or full contracts by providing a simple natural language prompt.

#### How to Use:

* Press **Ctrl + I** on Windows/Linux or **Command + I** on macOS.
* An input pop-up box will appear, asking you to enter your prompt. For example, you can type:\
  `"Create an ERC20 token contract"`
* Based on your prompt, the AI engine will:
  * Parse your intent.
  * Generate a valid Solidity contract or code snippet.
  * Display the result directly within the Q-Remix code editor.
* Caution:
  * The prompt needs to be well structured and as detailed as possible for an accurate generation of code

#### Interactions:

* After code generation, a small window will display the suggested code.
* Two options will be presented:
  * **Cancel:** Closes the pop-up without accepting the suggestion.
  * **Get Suggestion:** Confirms the prompt and generates the code.

Additionally, two icons will appear with the generated code:

* A **checkmark** to accept and integrate the code into your editor.
* A **cross** to discard the generated code.

#### Use Case:

Perfect for quickly scaffolding components of a smart contract, like token standards (ERC20, ERC721), DAO mechanics, or custom functions, especially when you want to avoid boilerplate or remember specific syntax.

> You can modify the prompt to regenerate different variations of the code if needed.

<figure><img src="/files/0P13oZFwykLEJjjXAdwU" alt=""><figcaption></figcaption></figure>

There are two options: **Cancel** and **Get Suggestion**. If you click on **Cancel** , the popup will close. When you click on **Get Suggestion**, it will generate a suggestion

<figure><img src="/files/NG47Aoc6RH5wKLal5mz2" alt=""><figcaption></figcaption></figure>

When you send your prompt for fetching suggestion, it shall display the corresponding response in the following format embedded in the current file itself, highlighted for the user to understand that this code snippet was generated as a suggestion from our AI model.

<figure><img src="/files/VLCuxe5dpUjPX5W1WVun" alt=""><figcaption></figcaption></figure>

Alongwith the code snippet we get options to accept and reject the changes suggested by AI, after acceptance it gets embedded as a part of the editor otherwise it is totally removed leaving the screen clean for the user to write a contract.

<figure><img src="/files/w2OhHfI5PY97waxY5UNz" alt=""><figcaption></figcaption></figure>

After acceptance of the changes the extra highlightings get removed and the file would look like the following example:

<figure><img src="/files/SkUJi22VJC0MK7IZzsw8" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.qremix.org/solidity-modules/ai-code-generation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
