有效提示
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
應用程式藍圖的成效和生成的程式碼品質,取決於提示的清晰度和詳細程度。使用 App Prototyping agent 時,請參考下列有效提示的指引,生成及偵錯應用程式:
- 具體說明:清楚定義應用程式的功能、使用者互動和資料需求。盡可能要求使用特定技術。舉例來說,如果想建立含有 3D 元素的網頁應用程式,可以要求 Gemini 使用
three.js
。
- 詢問設定服務的其他工作: Gemini 可以為應用程式編寫程式碼,但無法實際設定服務、啟用 API 或佈建資源 (例如 Cloud Storage 值區或 Stripe 帳戶)。請務必告知 Gemini,如果為特定服務編寫程式碼,也應說明如何設定這些服務。
- 要求建立 Firebase 專案:如果您要求 App Prototyping agent 協助設定 Firebase 服務,系統會代您佈建 Firebase 專案。例如,你可以要求「幫我新增 Firestore」或「將我的應用程式連結至 Firebase」。
- 使用 Gemini 修正提示:使用 Gemini 存取 Google、在 Firebase 中與 Gemini 對話、在 Code 檢視畫面中,或在其他 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.
遊戲應用程式提示 (Markdown):Gemini
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就能瞭解你想問什麼。
如果重新措辭後仍無法解決迴圈問題,請嘗試下列技巧:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],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)."]]