有效提示
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
应用蓝图的有效性和生成代码的质量取决于提示的清晰度和详细程度。使用 App Prototyping agent 生成和调试应用时,请参考以下提示编写准则:
- 明确具体内容:明确定义应用的功能、用户互动和数据要求。尽可能要求使用特定技术。例如,如果您尝试创建包含 3D 元素的 Web 应用,则可能需要让 Gemini 使用
three.js
。
- 询问有关设置服务的其他任务:Gemini 可以为您的应用编写代码,但实际上无法设置服务、启用 API 或预配资源(例如 Cloud Storage 存储桶或 Stripe 账号)。请务必告知 Gemini,如果它为特定服务编写代码,还应告知您如何设置这些服务。
- 请求创建 Firebase 项目:如果您请求 App Prototyping agent 帮助您设置 Firebase 服务,它会代表您预配一个 Firebase 项目。例如,您可以说:“帮我添加 Firestore”或“将我的应用连接到 Firebase。”
- 使用 Gemini 优化提示:使用 Gemini for Google、Code 视图中的 与 Gemini in Firebase 聊天或其他 Gemini 界面优化提示。
- 提供背景信息:提供有关应用用途、目标受众群体和您希望提供的用户体验的背景信息。
- 使用示例:如果可能,请提供示例,说明用户应如何与应用互动或应显示哪些数据。
- 迭代和优化:采用迭代的方式进行开发。不妨先从基本请求开始,然后添加功能、测试并优化功能,然后再添加其他功能。
遵循这些准则,您可以大幅提升 Firebase Studio 生成的应用蓝图质量和相关性,并提高调试成功率。
使用其他提示来优化回答
如果初始结果未达预期,您可以通过添加更多细节或具体指示来优化提示:
- 添加限制条件:指定界面、数据模型或功能的限制条件。
- 提供示例:提供示例,说明用户应如何与应用互动以及应显示哪些数据。
- 使用关键字:使用关键字描述您希望 LLM 与所需输出类别相关联的功能或能力。例如,您可以在提示中使用 Material Design,以表明您希望应用遵循 Google 设计标准。
- 请求进行特定更改:请求对生成的代码或蓝图进行特定更改。请在单独的请求中添加每项功能请求。
- 让模型进行推理:如果您无法获得理想结果,请尝试要求模型通过提示进行推理。例如,您可以这样提示:“请分步思考。我想为任务应用创建一个输入框,其中包含‘添加任务’按钮和‘取消’按钮。”
通过使用这些方法,您可以迭代优化提示,获取更符合预期的结果。
应用蓝图有效提示示例
以下是一些针对不同类型应用的有效提示示例:
简单任务跟踪器:
Create a simple web app that displays a list of to-do items.
Users should be able to add new items to the list and mark items as complete.
Provide a way to delete items and export the list as a text file.
Use a clean and modern UI using Google Material Design principles.
预算管理应用:
A budgeting and expense tracking app with spending categories, charts, and
budget goals. Include a clean dashboard with key insights. It should include
spending categories, charts, and budget goals. The app should allow users to
manually add expenses or upload csv files. The app should also allow users to
upload receipts, then use AI to convert the receipt into an expense entry that
users can edit. Data should be stored in browser cache, with download and
delete options.
游戏应用提示,并辅以 Gemini (Markdown):
Generate a delightful sliding number puzzle game (15-puzzle) with Javascript,
HTML, and CSS.
- **Setup:** Create a 4x4 grid with numbers 1-15 and one empty space. Use a
**solvable shuffling algorithm** to randomize the start.
- **Gameplay:** Allow clicking tiles **adjacent to the empty space** to slide
them. Count and display the number of moves.
- **Timer:** Include a **countdown timer** starting at **120 seconds**
(2 minutes).
- **End Conditions:**
- If solved (numbers 1-15 in order): Alert with an encouraging winning
statement generated by AI.
- If timer reaches 0: Alert with a funny retort generated by AI.
调试技巧
您可以在 Firebase 中使用 Gemini,以便在 Code 工作区或 App Prototyping agent 中通过聊天功能调试代码。
虽然 Gemini 可以为您编写代码,但有时也可能会产生错误。检测到错误时,它会尝试进行修正。如果您发现无法根据错误消息解决问题,可以尝试以下一些方法:
描述问题:在聊天界面中,尽可能简明扼要地描述您遇到的问题。虽然 Gemini 可能能访问错误消息和日志等上下文,但可能无法完全理解全部内容。同时描述行为和错误消息,有助于 Gemini 更快定位并修复错误。
提出具体问题:请大胆直接向 Gemini 询问您的代码相关问题。例如,“此函数中可能导致空指针异常的原因是什么?”或“如何防止这个竞态条件?”
分解复杂问题:如果您面临复杂问题,请将其拆分为更小、更易管理的部分。请 Gemini 帮助您逐一调试每个部分,并逐步分析问题。
使用代码块:分享代码片段时,请使用代码块格式,以确保代码排版正确。这样有助于 Gemini 更好地阅读和理解您的代码。
迭代和优化:Gemini 可能无法在第一次尝试时就提供最佳解决方案。请查看回答,提出澄清性问题,并根据需要提供更多信息。
避免提示循环:如果 Gemini 陷入循环或无法回答您的问题,请尝试重新表述提示或提供更多上下文信息。有时,仅仅换种说法提出问题,就能帮助 Gemini 更好地理解您的意图。
如果换种说法重复提示无法解决循环问题,请尝试以下方法:
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-22。
[null,null,["最后更新时间 (UTC):2025-08-22。"],[],[],null,["The effectiveness of your app blueprint and the quality of the generated code\ndepend on the clarity and detail of your prompts. When using\nthe App Prototyping agent, consider the following guidelines for effective\nprompting when generating and debugging apps:\n\n- **Be specific:** Clearly define the features, user interactions, and data requirements of your app. Ask for specific technologies, where possible. For example, if trying to create a web app with 3D elements, you may want to ask Gemini to use `three.js`.\n- **Ask about additional tasks to set up services:** Gemini can write code for your app, but it cannot actually set up services, enable APIs, or provision resources (like a Cloud Storage bucket or a Stripe account). Make sure to tell Gemini that if it writes code for specific services that it should also tell you how to set up those services.\n- **Request a Firebase project:** If you ask the App Prototyping agent to help you set up Firebase services, it will provision a Firebase project on your behalf. For example, you can ask \"Help me add Firestore,\" or \"Connect my app to Firebase.\"\n- **Use Gemini to refine your prompt:** Use [Gemini for\n Google](https://gemini.google.com), [chat with\n Gemini in Firebase](/docs/studio/try-gemini) in Code view, or other Gemini surfaces to refine and optimize your prompt.\n- **Provide context:** Include background information about your app's purpose, target audience, and the user experience you want.\n- **Use examples:** If possible, provide examples of how users should interact with the app or what data should be displayed.\n- **Iterate and refine:** Approach your development *iteratively*. Consider starting with a basic request, then add a feature, test it, refine it, then add another feature.\n\nBy following these guidelines, you can significantly improve the quality and\nrelevance of the app blueprints generated by Firebase Studio and its\nsuccess when debugging your app.\n\nUse additional prompts to refine responses\n\nIf the initial results aren't what you expect, you can refine your prompts by\nadding more detail or providing specific instructions:\n\n- **Add constraints:** Specify constraints on the UI, data model, or features.\n- **Provide examples:** Provide examples of how users should interact with the app and what data should appear.\n- **Use keywords:** Use keywords to describe the features or capabilities you want that the LLM might associate with the class of output you want. For example, you might use *Material Design* in a prompt where you indicate that you want your app to adhere to Google design standards.\n- **Ask for specific changes:** Ask for specific changes to the generated code or blueprint. Add each feature request in a separate request.\n- **Ask the model to reason:** If you're having trouble getting the results you want, try asking the model to reason through the prompt. For example, you could say \"Think step by step. I want to create an input box for my task app. It should contain an 'Add task' button and a 'Cancel' button.\"\n\nBy using these techniques, you can iteratively refine your prompts to get the\nresults you want.\n\nExamples of effective prompts for app blueprints\n\nHere are some examples of effective prompts for different types of apps:\n\n**Simple task tracker:** \n\n Create a simple web app that displays a list of to-do items.\n Users should be able to add new items to the list and mark items as complete.\n Provide a way to delete items and export the list as a text file.\n Use a clean and modern UI using Google Material Design principles.\n\n**Budgeting app:** \n\n A budgeting and expense tracking app with spending categories, charts, and\n budget goals. Include a clean dashboard with key insights. It should include\n spending categories, charts, and budget goals. The app should allow users to\n manually add expenses or upload csv files. The app should also allow users to\n upload receipts, then use AI to convert the receipt into an expense entry that\n users can edit. Data should be stored in browser cache, with download and\n delete options.\n\n**Game app prompt with assistance from Gemini (Markdown):** \n\n Generate a delightful sliding number puzzle game (15-puzzle) with Javascript,\n HTML, and CSS.\n\n - **Setup:** Create a 4x4 grid with numbers 1-15 and one empty space. Use a\n **solvable shuffling algorithm** to randomize the start.\n - **Gameplay:** Allow clicking tiles **adjacent to the empty space** to slide\n them. Count and display the number of moves.\n - **Timer:** Include a **countdown timer** starting at **120 seconds**\n (2 minutes).\n - **End Conditions:**\n - If solved (numbers 1-15 in order): Alert with an encouraging winning\n statement generated by AI.\n - If timer reaches 0: Alert with a funny retort generated by AI.\n\nTips for debugging\n\nYou can use Gemini in Firebase to help you debug your code with\nchat in your **Code** workspace\nor the App Prototyping agent.\n\nWhile Gemini can write code for you, it might sometimes also\nproduce errors. When it detects an error, it will attempt\nto fix it. If you find that it isn't able to resolve the issue given\nthe error message, you can try some of the following techniques:\n\n- **Describe the issue:** In the chat interface, describe the\n problem you're encountering as clearly and concisely as possible.\n While Gemini might have access to context like error messages\n and logs, it might not understand the full context. Describing the behavior\n along with the error message can help Gemini fix errors\n faster.\n\n- **Ask specific questions:** Don't be afraid to ask Gemini\n direct questions about your code. For example, \"What could be causing a\n null pointer exception in this function?\" or \"How can I prevent\n this race condition?\"\n\n- **Break down complex problems:** If you're dealing with a complex\n issue, break it down into smaller, more manageable parts. Ask\n Gemini to help you debug each part separately and think\n through problems step-by-step.\n\n- **Use code fences:** When sharing code snippets, use code fences\n to ensure that the code is properly formatted. This makes it easier\n for Gemini to read and understand your code.\n\n- **Iterate and refine:** Gemini may not always provide the perfect\n solution on the first try. Review the responses, ask clarifying\n questions, and provide additional information as needed.\n\n- **Avoid prompting loops:** If Gemini gets stuck in a loop or is\n unable to answer your question, try rephrasing your prompt or\n providing additional context. Sometimes, just rewording your\n question can help Gemini understand what you're asking.\n\n If rephrasing your prompt doesn't resolve the loop, try\n the following techniques:\n - **Start a new chat:** If you're using Gemini in Firebase\n chat in your Code\n workspace, start a new chat session to reset\n Gemini's context. This can help break free from any\n misconceptions or assumptions that Gemini may have made\n in the previous conversation.\n\n - **Provide counter-examples:** If Gemini is making incorrect\n assumptions, provide counter-examples to help it understand\n the correct behavior.\n\nNext steps\n\n- [Get started with the App Prototyping agent](/docs/studio/get-started-ai).\n- [Develop, publish, and monitor an app following a guided tour of the App Prototyping agent](/docs/studio/solution-build-with-ai).\n- [Develop applications in a\n Firebase Studio workspace](/docs/studio/get-started-workspace)."]]