有效提示

應用程式藍圖的成效和生成的程式碼品質,取決於提示的清晰度和詳細程度。使用 App Prototyping agent 時,請參考下列有效提示的指引,生成及偵錯應用程式:

只要遵循這些指南,就能大幅提升 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就能瞭解你想問什麼。

    如果重新措辭後仍無法解決迴圈問題,請嘗試下列技巧:

    • 展開新對話:如果你是在 Firebase 工作區的 Code Chat 中使用 Gemini,請展開新的對話工作階段,重設 Gemini 的背景資訊。這有助於擺脫Gemini在先前對話中可能產生的任何誤解或假設。

    • 提供反例:如果 Gemini 做出錯誤假設,請提供反例,協助瞭解正確行為。

後續步驟