การเขียนพรอมต์ที่มีประสิทธิภาพ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ประสิทธิภาพของพิมพ์เขียวแอปและคุณภาพของโค้ดที่สร้างขึ้น
ขึ้นอยู่กับความชัดเจนและรายละเอียดของพรอมต์ เมื่อใช้ App Prototyping agent โปรดพิจารณาหลักเกณฑ์ต่อไปนี้เพื่อการแจ้งพรอมต์ที่มีประสิทธิภาพเมื่อสร้างและแก้ไขข้อบกพร่องของแอป
- ระบุรายละเอียด: ระบุฟีเจอร์ การโต้ตอบของผู้ใช้ และ
ข้อกำหนดด้านข้อมูลของแอปอย่างชัดเจน ขอเทคโนโลยีที่เฉพาะเจาะจงหากเป็นไปได้
เช่น หากพยายามสร้างเว็บแอปที่มีองค์ประกอบ 3 มิติ
คุณอาจต้องการขอให้ Gemini ใช้
three.js
- สอบถามเกี่ยวกับงานเพิ่มเติมในการตั้งค่าบริการ: Gemini สามารถเขียนโค้ดสำหรับแอปของคุณได้ แต่ไม่สามารถตั้งค่าบริการ เปิดใช้ API หรือจัดสรรทรัพยากร (เช่น บัคเก็ต Cloud Storage หรือบัญชี Stripe) ได้
อย่าลืมบอก Gemini ว่าหากเขียนโค้ดสำหรับบริการที่เฉพาะเจาะจง
ก็ควรบอกวิธีตั้งค่าบริการเหล่านั้นด้วย
- ขอโปรเจ็กต์ Firebase: หากคุณขอให้ App Prototyping agent ช่วยตั้งค่าบริการ Firebase App Prototyping agent จะจัดสรรโปรเจ็กต์ Firebase ในนามของคุณ เช่น คุณสามารถถามว่า "ช่วยฉันเพิ่ม Firestore หน่อย" หรือ "เชื่อมต่อ
แอปของฉันกับ Firebase หน่อย"
- ใช้ Gemini เพื่อปรับแต่งพรอมต์: ใช้ Gemini สำหรับ
Google
แชทกับ
Gemini ใน Firebase ใน
Code มุมมอง หรือแพลตฟอร์มอื่นๆ ของ
Gemini เพื่อปรับแต่งและเพิ่มประสิทธิภาพพรอมต์
- ระบุบริบท: ใส่ข้อมูลพื้นฐานเกี่ยวกับ
วัตถุประสงค์ กลุ่มเป้าหมาย และประสบการณ์ของผู้ใช้ที่คุณต้องการของแอป
- ใช้ตัวอย่าง: หากเป็นไปได้ ให้ระบุตัวอย่างวิธีที่ผู้ใช้ควรโต้ตอบกับแอปหรือข้อมูลที่ควรแสดง
- ทำซ้ำและปรับปรุง: พัฒนาแอปแบบวนซ้ำ ลองเริ่มด้วยคำขอพื้นฐาน จากนั้นเพิ่มฟีเจอร์ ทดสอบ ปรับแต่ง แล้ว
เพิ่มฟีเจอร์อื่น
การทำตามหลักเกณฑ์เหล่านี้จะช่วยปรับปรุงคุณภาพและความเกี่ยวข้องของพิมพ์เขียวของแอปที่ Firebase Studio สร้างขึ้นได้อย่างมาก รวมถึงช่วยให้การแก้ไขข้อบกพร่องของแอปประสบความสำเร็จ
ใช้พรอมต์เพิ่มเติมเพื่อปรับแต่งคำตอบ
หากผลลัพธ์เริ่มต้นไม่เป็นไปตามที่คาดไว้ คุณสามารถปรับแต่งพรอมต์ได้โดย
เพิ่มรายละเอียดหรือระบุคำสั่งที่เฉพาะเจาะจง
- เพิ่มข้อจํากัด: ระบุข้อจํากัดใน UI, โมเดลข้อมูล หรือ
ฟีเจอร์
- ระบุตัวอย่าง: ระบุตัวอย่างวิธีที่ผู้ใช้ควรโต้ตอบกับแอปและข้อมูลที่ควรปรากฏ
- ใช้คีย์เวิร์ด: ใช้คีย์เวิร์ดเพื่ออธิบายฟีเจอร์หรือความสามารถที่คุณต้องการ ซึ่ง 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 (มาร์กดาวน์):
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.
เคล็ดลับในการแก้ไขข้อบกพร่อง
คุณสามารถใช้ Gemini ใน Firebase เพื่อช่วยดีบักโค้ดด้วยการแชทในพื้นที่ทำงาน Code
หรือ App Prototyping agent
แม้ว่า Gemini จะเขียนโค้ดให้คุณได้ แต่บางครั้งก็อาจ
สร้างข้อผิดพลาดได้เช่นกัน เมื่อตรวจพบข้อผิดพลาด ระบบจะพยายาม
แก้ไข หากพบว่าเครื่องมือไม่สามารถแก้ปัญหาได้เนื่องจากข้อความแสดงข้อผิดพลาด ให้ลองใช้เทคนิคต่อไปนี้
อธิบายปัญหา: ในอินเทอร์เฟซแชท ให้อธิบายปัญหาที่คุณพบให้ชัดเจนและกระชับที่สุด
แม้ว่า Gemini อาจมีสิทธิ์เข้าถึงบริบท เช่น ข้อความแสดงข้อผิดพลาด
และบันทึก แต่ก็อาจไม่เข้าใจบริบททั้งหมด การอธิบายลักษณะการทำงานพร้อมกับข้อความแสดงข้อผิดพลาดจะช่วยให้ Gemini แก้ไขข้อผิดพลาด
ได้เร็วขึ้น
ถามคำถามที่เจาะจง: ถามคำถามเกี่ยวกับโค้ดของคุณได้เลย ไม่ต้องเกรงใจGemini
เช่น "อะไรอาจทำให้เกิด
ข้อยกเว้นตัวชี้ Null ในฟังก์ชันนี้" หรือ "ฉันจะป้องกัน
สภาวะแข่งขันนี้ได้อย่างไร"
แบ่งปัญหาที่ซับซ้อนออกเป็นส่วนๆ: หากคุณกำลังเผชิญกับปัญหาที่ซับซ้อน
ให้แบ่งปัญหาออกเป็นส่วนย่อยๆ เพื่อให้จัดการได้ง่ายขึ้น ขอให้ Gemini ช่วยคุณแก้ไขข้อบกพร่องของแต่ละส่วนแยกกันและคิด
แก้ปัญหาทีละขั้นตอน
ใช้บล็อกโค้ด: เมื่อแชร์ข้อมูลโค้ด ให้ใช้บล็อกโค้ด
เพื่อให้มั่นใจว่าโค้ดได้รับการจัดรูปแบบอย่างถูกต้อง ซึ่งจะช่วยให้ Gemini อ่านและทำความเข้าใจโค้ดของคุณได้ง่ายขึ้น
ทำซ้ำและปรับแต่ง: Gemini อาจไม่ได้ให้โซลูชันที่สมบูรณ์แบบเสมอไปในครั้งแรก ตรวจสอบคำตอบ ถามคำถามเพื่อขอข้อมูลเพิ่มเติม
และให้ข้อมูลเพิ่มเติมตามที่จำเป็น
หลีกเลี่ยงการวนลูปของพรอมต์: หาก Gemini ติดอยู่ในลูปหรือตอบคำถามไม่ได้ ให้ลองเปลี่ยนคำพรอมต์หรือให้บริบทเพิ่มเติม บางครั้งเพียงแค่เปลี่ยนคำถามก็ช่วยให้ Gemini เข้าใจสิ่งที่คุณถามได้
หากการเรียบเรียงพรอมต์ใหม่ไม่ช่วยแก้ปัญหาลูป ให้ลองใช้เทคนิคต่อไปนี้
เริ่มแชทใหม่: หากคุณใช้ Gemini ในFirebase
แชทในพื้นที่ทำงาน Code
ให้เริ่มเซสชันแชทใหม่เพื่อรีเซ็ตบริบทของ Gemini
ซึ่งจะช่วยให้คุณหลุดพ้นจากความเข้าใจผิดหรือสมมติฐานที่ Gemini อาจมี
ในการสนทนาก่อนหน้า
ระบุตัวอย่างที่ขัดแย้ง: หาก Gemini กำลังตั้งสมมติฐานที่ไม่ถูกต้อง
ให้ระบุตัวอย่างที่ขัดแย้งเพื่อช่วยให้เข้าใจ
ลักษณะการทำงานที่ถูกต้อง
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],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)."]]