Chat with AI
This functionality relies on the AI Assistant plugin that requires an additional license.
For more information about licensing and enabling AI Assistant, refer to JetBrains AI Service licensing and Enable AI Assistant plugin.
Use the AI Assistant tool window to have a conversation with the LLM (Large Language Model), ask questions about your project, or iterate on a task.
AI Assistant takes into consideration the language and technologies used in your project, as well as local changes and version control system commits. You can search for files, classes, and element usages.
Click
AI Assistant on the right toolbar to open AI Assistant.
In the input field, type your question and press Enter to submit your query.
If you have a piece of code selected in the editor tab, use
/explain
and/refactor
commands to save time when typing your query.If you want to attach a particular file or function to your query to provide more context, use
#
:#thisFile
refers to the currently open file.#localChanges
refers to the uncommitted changes.#file:
invokes a popup with selection of files from the current project. You can select the necessary file from the popup or write the name of the file (for example,#file:Foo.md
) .#symbol:
adds a symbol into prompt (for example,#symbol:FieldName
).#jupyter:
adds a Jupyter variable into prompt (for example,#jupyter:df
).#schema:
refers to a database schema. You can attach a database schema to enhance the quality of generated SQL queries with your schema's context.
tip
Each generated code snippet or a selected fragment within it can be quickly inserted into the editor at the caret position by clicking
in its top right corner.
Each generated code snippet can be also run in the Python console separately from the rest of the project by clicking
.
Click
Regenerate this response at the beginning of the AI Assistant's answer to get a new response to your question.
AI Assistant keeps the chats' history separately for each project across IDE sessions. You can find the saved chats in the All Chats list.
![All Chats list All Chats list](https://resources.jetbrains.com/help/img/idea/2024.2/py_ai_all_chats.png)
Names of the chats are generated automatically and contain the summary of the initial query. Right-click the chat's name to rename it or delete it from the list.
To give more precise answers, AI Assistant has the smart chat mode enabled by default.
In this mode, AI Assistant might send additional details, such as file types, frameworks used, and any other information that may be necessary for providing context to the LLM.
To disable the smart chat mode, clear the Enable smart chat mode checkbox in Settings | Tools | AI Assistant.
note
Learn more about data sharing from How we handle your code and data.
You can create a new file with the AI-generated code right from the AI Assistant chat.
In the upper-right corner of the field with the generated code, click
Create File from Snippet.
AI Assistant will create a file with the AI-generated code.
If you have any file opened or selected in the Project tool window Alt01, the new file will be created in the same folder as the selected file.
In other cases, the new file will be created in the root project folder.
tip
If you want the new file to be added to a specific folder, select this folder in the Project tool window Alt01 before creating the new file.
note
This functionality relies on the Database Tools and SQL plugin, which you need to install and enable. For more information, refer to Install a plugin from Marketplace.
You can enhance the quality of generated SQL queries with the context of a database schema that you are working with. To do that, attach the schema in AI Assistant tool window. AI Assistant will get access to the structure of the attached schema, providing the LLM with information about it.
To use this feature, you need to grant AI Assistant consent to access the database schema.
Attaching a schema will also improve the results of the context menu AI Actions actions group, for example, Explain Code, Suggest Refactoring, and so on. For more information about those actions, refer to Use prompts to explain, refactor, and suggest changes to your code.
In the AI Assistant tool window input field, enter your prompt with
#
followed by the schema name. For example:Give me a query to get all actor names from #public
.Press Enter.
AI Assistant will analyze your schema and generate the result.
![AI generated code for the entered prompt that mentioned a schema AI generated code for the entered prompt that mentioned a schema](https://resources.jetbrains.com/help/img/idea/2024.2/schema_mention_result.png)
You can see which schema was attached to your message, and also navigate to that schema in Database tool window. To do that, click Attached elements in your message, then click the schema name.
If you want to allow AI Assistant to always attach the selected schemas, select the Always allow attaching database schemas checkbox in the Attach Schema dialog. Alternatively, enable the Allow attaching database schemas setting in Settings | Tools | AI Assistant.
Thanks for your feedback!