Câu lệnh hiệu quả
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Mức độ hiệu quả của bản thiết kế ứng dụng và chất lượng của mã được tạo phụ thuộc vào độ rõ ràng và chi tiết của câu lệnh. Khi sử dụng App Prototyping agent, hãy cân nhắc các nguyên tắc sau để đưa ra lời nhắc hiệu quả khi tạo và gỡ lỗi ứng dụng:
- Cụ thể: Xác định rõ các tính năng, hoạt động tương tác của người dùng và yêu cầu về dữ liệu của ứng dụng. Yêu cầu các công nghệ cụ thể (nếu có thể). Ví dụ: nếu đang cố gắng tạo một ứng dụng web có các phần tử 3D, bạn có thể yêu cầu Gemini sử dụng
three.js
.
- Hỏi về các việc cần làm khác để thiết lập dịch vụ: Gemini có thể viết mã cho ứng dụng của bạn, nhưng không thể thiết lập dịch vụ, bật API hoặc cung cấp tài nguyên (chẳng hạn như một vùng chứa Cloud Storage hoặc tài khoản Stripe).
Nhớ yêu cầu Gemini cho bạn biết cách thiết lập các dịch vụ cụ thể nếu nó viết mã cho các dịch vụ đó.
- Yêu cầu một dự án Firebase: Nếu bạn yêu cầu App Prototyping agent giúp bạn thiết lập các dịch vụ của Firebase, thì App Prototyping agent sẽ cung cấp một dự án Firebase thay cho bạn. Ví dụ: bạn có thể yêu cầu "Giúp tôi thêm Firestore" hoặc "Kết nối ứng dụng của tôi với Firebase".
- Sử dụng Gemini để tinh chỉnh câu lệnh: Sử dụng Gemini cho Google, trò chuyện với Gemini trên Firebase ở chế độ xem Code hoặc các nền tảng Gemini khác để tinh chỉnh và tối ưu hoá câu lệnh.
- Cung cấp bối cảnh: Thêm thông tin cơ bản về mục đích, đối tượng mục tiêu và trải nghiệm người dùng mà bạn muốn mang lại cho ứng dụng.
- Sử dụng ví dụ: Nếu có thể, hãy cung cấp ví dụ về cách người dùng nên tương tác với ứng dụng hoặc dữ liệu nào nên được hiển thị.
- Lặp lại và tinh chỉnh: Tiếp cận quá trình phát triển theo cách lặp lại. Hãy cân nhắc bắt đầu bằng một yêu cầu cơ bản, sau đó thêm một tính năng, kiểm thử, tinh chỉnh rồi thêm một tính năng khác.
Bằng cách làm theo các nguyên tắc này, bạn có thể cải thiện đáng kể chất lượng và mức độ liên quan của bản thiết kế ứng dụng do Firebase Studio tạo cũng như mức độ thành công khi gỡ lỗi ứng dụng.
Sử dụng thêm câu lệnh để tinh chỉnh câu trả lời
Nếu kết quả ban đầu không như mong đợi, bạn có thể tinh chỉnh câu lệnh bằng cách thêm thông tin chi tiết hoặc đưa ra hướng dẫn cụ thể:
- Thêm các quy tắc ràng buộc: Chỉ định các quy tắc ràng buộc trên giao diện người dùng, mô hình dữ liệu hoặc các tính năng.
- Cung cấp ví dụ: Cung cấp ví dụ về cách người dùng nên tương tác với ứng dụng và dữ liệu nào sẽ xuất hiện.
- Sử dụng từ khoá: Sử dụng từ khoá để mô tả các tính năng hoặc chức năng mà bạn muốn LLM có thể liên kết với lớp đầu ra mà bạn muốn. Ví dụ: bạn có thể sử dụng Material Design trong một câu lệnh để cho biết rằng bạn muốn ứng dụng của mình tuân thủ các tiêu chuẩn thiết kế của Google.
- Yêu cầu thay đổi cụ thể: Yêu cầu thay đổi cụ thể đối với mã hoặc bản thiết kế được tạo. Thêm từng yêu cầu về tính năng trong một yêu cầu riêng.
- Yêu cầu mô hình suy luận: Nếu bạn gặp khó khăn trong việc nhận được kết quả mong muốn, hãy thử yêu cầu mô hình suy luận thông qua câu lệnh. Ví dụ: bạn có thể nói "Hãy suy nghĩ từng bước. Tôi muốn tạo một hộp nhập cho ứng dụng quản lý việc cần làm của mình. Hộp này phải có nút "Thêm việc cần làm" và nút "Huỷ"."
Bằng cách sử dụng các kỹ thuật này, bạn có thể tinh chỉnh câu lệnh một cách lặp đi lặp lại để nhận được kết quả mong muốn.
Ví dụ về câu lệnh hiệu quả cho bản thiết kế ứng dụng
Sau đây là một số ví dụ về câu lệnh hiệu quả cho nhiều loại ứng dụng:
Công cụ theo dõi nhiệm vụ đơn giản:
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.
Ứng dụng lập ngân sách:
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.
Câu lệnh cho ứng dụng trò chơi có sự trợ giúp của 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.
Mẹo gỡ lỗi
Bạn có thể sử dụng Gemini trong Firebase để gỡ lỗi mã bằng cách trò chuyện trong không gian làm việc Code hoặc App Prototyping agent.
Mặc dù Gemini có thể viết mã cho bạn, nhưng đôi khi công cụ này cũng có thể tạo ra lỗi. Khi phát hiện lỗi, hệ thống sẽ cố gắng khắc phục. Nếu thấy rằng cách này không giải quyết được vấn đề dựa trên thông báo lỗi, bạn có thể thử một số kỹ thuật sau:
Mô tả vấn đề: Trong giao diện trò chuyện, hãy mô tả vấn đề bạn đang gặp phải một cách rõ ràng và ngắn gọn nhất có thể.
Mặc dù Gemini có thể truy cập vào các ngữ cảnh như thông báo lỗi và nhật ký, nhưng có thể không hiểu được toàn bộ ngữ cảnh. Việc mô tả hành vi cùng với thông báo lỗi có thể giúp Gemini khắc phục lỗi nhanh hơn.
Đặt câu hỏi cụ thể: Đừng ngại đặt Gemini
câu hỏi trực tiếp về mã của bạn. Ví dụ: "Điều gì có thể gây ra một ngoại lệ con trỏ rỗng trong hàm này?" hoặc "Làm cách nào để ngăn chặn điều kiện xung đột này?"
Chia nhỏ các vấn đề phức tạp: Nếu bạn đang phải đối mặt với một vấn đề phức tạp, hãy chia nhỏ vấn đề đó thành các phần nhỏ hơn và dễ quản lý hơn. Yêu cầu Gemini trợ giúp bạn gỡ lỗi từng phần riêng biệt và suy nghĩ từng bước về các vấn đề.
Sử dụng hàng rào mã: Khi chia sẻ đoạn mã, hãy sử dụng hàng rào mã để đảm bảo mã được định dạng đúng cách. Điều này giúp Gemini dễ dàng đọc và hiểu mã của bạn hơn.
Lặp lại và tinh chỉnh: Gemini không phải lúc nào cũng đưa ra giải pháp hoàn hảo ngay từ lần đầu tiên. Xem xét các câu trả lời, đặt câu hỏi làm rõ và cung cấp thêm thông tin nếu cần.
Tránh vòng lặp câu lệnh: Nếu Gemini bị mắc kẹt trong một vòng lặp hoặc không thể trả lời câu hỏi của bạn, hãy thử diễn đạt lại câu lệnh hoặc cung cấp thêm bối cảnh. Đôi khi, bạn chỉ cần diễn đạt lại câu hỏi để giúp Gemini hiểu rõ hơn về câu hỏi của bạn.
Nếu việc diễn đạt lại câu lệnh không giải quyết được vòng lặp, hãy thử các kỹ thuật sau:
Bắt đầu một cuộc trò chuyện mới: Nếu bạn đang sử dụng Gemini trong Firebase cuộc trò chuyện trong không gian làm việc Code của mình, hãy bắt đầu một phiên trò chuyện mới để đặt lại ngữ cảnh của Gemini. Điều này có thể giúp bạn thoát khỏi mọi quan niệm sai lầm hoặc giả định mà Gemini có thể đã đưa ra trong cuộc trò chuyện trước đó.
Đưa ra ví dụ phản biện: Nếu Gemini đưa ra giả định không chính xác, hãy đưa ra ví dụ phản biện để giúp Gemini hiểu được hành vi chính xác.
Các bước tiếp theo
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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)."]]