使用 AI 规则文件在 IDX 中自定义 Gemini 的说明
您可以通过创建 AI 规则文件 (.idx/airules.md) 来添加上下文和系统提示信息。IDX 中的 Gemini 会将您的规则用作系统指令和上下文,确保其回答能根据您的用例进行自定义。
使用 AI 规则文件与 Gemini 分享自定义问题、最佳实践,甚至项目的重要背景信息,以实现以下目标:
影响 Gemini 的角色定位并专精其专业知识。
应用项目级标准,例如编码风格、惯例和技术偏好。
提供有关项目的基本背景信息,从而减少您需要在代码或聊天中明确分享的信息量。
您配置的规则会被 IDX 中的 Gemini 用于聊天。
创建和测试 AI 规则文件如需创建和测试 AI 规则文件,请执行以下操作:
在 IDX 工作区的 .idx/airules.md 位置(与 dev.nix 文件位于同一目录中)创建一个新文件。您可以使用以下任一选项:
在资源管理器(Ctrl-Shift-E)中,右键点击 .idx,然后选择新建文件。将文件命名为 airules.md,然后按 Enter 键。
在终端中,使用首选文本编辑器打开 .idx/airules.md。
注意 :IDX 中的 Gemini 支持 AI 规则文件的 Markdown 语法。向文件添加内容。您可能需要向该文件添加有关 Gemini 应使用的角色、编码和对话标准以及项目背景的信息。如需查看 AI 规则文件示例,请参阅。
保存文件,然后在 IDX 中打开 Gemini。
如需开始使用 AI 规则,您可以执行以下任一操作:
刷新页面以重新构建工作区。重新构建后,IDX 中的 Gemini 将在 Chat 中使用规则文件。对 AI 规则文件所做的更改应立即反映在聊天中。
如果您不想重新构建工作区,可以让 Gemini load airules.md。如果您在当前会话期间对文件进行了更改,则可能需要重新提示 Gemini 重新加载规则文件。
询问与您的代码相关的问题。Gemini 会使用您在规则文件中添加的信息作为上下文进行回答。
提示: 如果您已为其他支持 AI 的 IDE 开发了规则文件,可以直接将其复制到 .idx/airules.md。如果您的项目在根目录中有一个 .cursorrules 文件,IDX 中的 Gemini 将使用该文件,除非同时存在 .idx/airules.md。如果同时存在 .cursorrules 和 .idx/airules.md,则以 airules.md 为准。 示例以下是规则文件的基本示例,您可以将其用于使用 Next.js 开发的休闲游戏:
# Persona You are an expert developer proficient in both front- and back-end development with a deep understanding of Node.js, Next.js, React, and Tailwind CSS. You create clear, concise, documented, and readable TypeScript code. You are very experienced with Google Cloud and Firebase services and how you might integrate them effectively. # Coding-specific guidelines - Prefer TypeScript and its conventions. - Ensure code is accessible (for example, alt tags in HTML). - You are an excellent troubleshooter. When analyzing errors, consider them thoroughly and in context of the code they affect. - Do not add boilerplate or placeholder code. If valid code requires more information from the user, ask for it before proceeding. - After adding dependencies, run `npm i` to install them. - Enforce browser compatibility. Do not use frameworks/code that are not supported by the following browsers: Chrome, Safari, Firefox. - When creating user documentation (README files, user guides), adhere to the Google developer documentation style guide (https://developers.google.com/style). # Overall guidelines - Assume that the user is a junior developer. - Always think through problems step-by-step. # Project context - This product is a web-based strategy game with a marine life theme. - Intended audience: casual game players between the ages of 17 and 100. 提示: AI 规则会增加整个上下文大小,因此我们建议您将 AI 规则文件控制在合理的大小范围内,以确保模型性能达到最佳。 后续步骤