קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
במאמר הזה נסביר איך להשתמש בהתאמה אישית של קוד ב-Gemini Code Assist, ונספק כמה שיטות מומלצות. התכונה הזו מאפשרת לקבל המלצות לקוד, שמבוססות על הספריות הפנימיות, על ממשקי ה-API הפרטיים ועל סגנון הקוד של הארגון.
בטבלה הבאה מפורטות הנחיות ודוגמאות לשימוש בהתאמה אישית של קוד בתרחישי שימוש ספציפיים:
תרחיש לדוגמה
דברים שכדאי לנסות
כתיבת קוד חדש
כדי ליצור קוד בסביבת הפיתוח המשולבת (IDE) או בצ'אט של Gemini Code Assist:
יצירת קוד שמשתמש במונחים שכבר מוזכרים בקוד הבסיסי.
מדביקים את הקוד, למשל חתימה פונקציונלית או קוד עם הערות TODO, ומבקשים מ-Gemini Code Assist למלא או להחליף את הערות TODO בקוד. מוסיפים תגובות עם הסבר מההקשר.
אפשר לנסות ליצור קוד באמצעות ההנחיות הבאות בצ'אט של Gemini Code Assist:
"כותבים פונקציה ראשית שבה נוצר חיבור ל-DATABASE. כולל בדיקות תקינות".
"כותבים FUNCTION_OR_CLASS במבנה הבא:
EXPLAIN_STRUCTURE."
אחרי שיוצרים קוד, אפשר להשתמש בהנחיה נוספת כדי לשפר אותו:
"כדאי לנסות את הפקודה /fix כדי לשנות את הקוד שנוצר – לדוגמה, שגיאות תחביר."
"Add missing imports".
"אפשר לנסות את /fix בקוד שנוצר בצ'אט".
ניקוי, פישוט ושינוי מבנה הקוד
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"האם יש לך אפשרות למזג את IMPORTS_VARIABLES_OR_NOTE_EXPORTED_FUNCTIONS בקובץ הזה?"
"How would you simplify the
FUNCTION_NAME function?"
"האם אפשר למזג את FUNCTION_NAME_1 ו-FUNCTION_NAME_2 לפונקציה אחת?"
"אפשר להוסיף משתנים מסוימים בקוד של FUNCTION_NAME?"
"אפשר לפשט את שמות המשתנים בפונקציה
FUNCTION_NAME?"
ציון קריאוּת
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"כדאי לכתוב את הפונקציה FUNCTION_NAME בפחות שורות קוד, אם אפשר."
"Add comments to the function
FUNCTION_NAME."
"Remove unnecessary whitespaces in the function
FUNCTION_NAME".
"צריך לעצב את הפונקציה FUNCTION_NAME באופן דומה לשאר הקוד".
בדיקת קוד
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"פיצול הקוד לחלקים והסבר על כל חלק באמצעות קוד הבסיס שלנו".
"האם יש משתנים או מילות מפתח שאפשר לקצר ולהסביר בצורה ברורה יותר?"
"Can you give me useful code from the
REPOSITORY_NAME_PACKAGE_MODULE context for
this code?"
"What do you think about the function
FUNCTION_NAME?"
ניפוי באגים
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"מוצגת לי הודעת שגיאה כשאני מנסה לבצע פעולה X/להוסיף Y. למה?"
"האם שמת לב לשגיאה בפונקציה
FUNCTION_NAME?"
"איך מתקנים את הפונקציה FUNCTION_NAME בהתאם להודעת השגיאה הזו?"
למידה והכשרת עובדים חדשים
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"פיצול הקוד הזה לחלקים והסבר על כל אחד מהם באמצעות קוד הבסיס שלנו".
"Show how to call function
FUNCTION_NAME?"
"Show how to run the main function in the
ENVIRONMENT_NAME environment?"
"מהו השיפור הטכני העיקרי שאפשר לבצע כדי לשפר את הביצועים של הקוד הזה?"
"Show me the implementation of
FUNCTION_OR_CLASS_NAME to achieve better
results and add what that specific element is" – לדוגמה,
"Show me the implementation of function foo where foo is the name of
the function".
העברה
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"Give me a strategy for how I can migrate
FILE_NAME from
LANGUAGE_1 to
LANGUAGE_2" – לדוגמה, מ-Go ל-
Python.
"Given the function FUNCTION_NAME in
repository REPOSITORY_NAME, find me an
equivalent function in language
LANGUAGE_NAME that I can use."
נסו את תהליך העבודה הבא ליצירת קוד או לטרנספורמציה מבוססת צ'אט באמצעות הנחיות:
"Take FILENAME_COMPONENT code already written in LANGUAGE_1 and refactor and migrate it to LANGUAGE_2" – לדוגמה, מ-Go ל-Python.
אחרי שמעבירים קוד, כדאי לנסות את הפעולות הבאות:
בוחרים קטעים קטנים יותר ומשתמשים ב-/fix כדי להגיע למצב הרצוי.
אפשר לנסות את ההנחיות הבאות:
"Is there something which can be improved?"
"Give me possible pain points"
"איך אפשר לבדוק את הקוד הזה אם ההעברה נכונה?"
יצירת מסמכי עזרה
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"Summarize the code in package or folder
X and provide documentation for the five methods
important ביותר".
"יצירת מסמכי עזרה עבור FUNCTION_OR_CLASS_NAME".
"קיצור המסמכים תוך שמירה על המידע החשוב".
יצירת בדיקות יחידה
כדאי לנסות את ההנחיות הבאות בצ'אט של Gemini Code Assist:
"יצירת בדיקות יחידה עבור FILENAME".
"Add the most relevant test cases for the
פונקציה FUNCTION_NAME".
"הסרה של תרחישי בדיקה שלדעתכם לא תורמים הרבה ערך".
שיטות מומלצות
משתמשים בשמות רלוונטיים של משתנים ופונקציות או בקטעי קוד. כך תוכלו להתאים אישית את הקוד ולמצוא את דוגמאות הקוד הרלוונטיות ביותר.
משתמשים במאגרי אינדקסים שרוצים להתאים לעומס, ומשתדלים לא להוסיף פונקציונליות שהוצאה משימוש. התאמה אישית של קוד עוזרת להתאים את סגנון הקוד, התבניות, הסמנטיקה, הידע וההטמעות בקוד בסביבת הקוד.
דוגמאות לא טובות למאגרים להרחבה הן פונקציונליות שהוצאה משימוש, קוד שנוצר והטמעות מדור קודם.
בתרחישי לדוגמה של אחזור קוד, כדאי להשתמש בפונקציה של יצירת קוד במקום בהשלמת קוד. אפשר להשתמש בהנחיה כמו "Using the definition of
FUNCTION_NAME, generate the exact same function" (על סמך ההגדרה של FUNCTION_NAME, יוצרים את אותה פונקציה בדיוק) או "Generate the exact implementation of FUNCTION_NAME" (יוצרים את ההטמעה המדויקת של FUNCTION_NAME).
מומלץ לכלול או לייבא לקובץ את הקוד שרוצים לאחזר כדי לשפר את המודעוּת להקשר של Gemini.
מבצעים רק פעולה אחת לכל הנחיה. לדוגמה, אם רוצים לאחזר קוד ולהטמיע אותו בפונקציה חדשה, צריך לבצע את השלבים הבאים בשתי הנחיות.
בתרחישי שימוש שבהם אתם רוצים יותר מקוד (כמו הסבר על קוד, תוכנית העברה או הסבר על שגיאה), תוכלו להשתמש בהתאמה אישית של קוד בצ'אט, שבו תוכלו לנהל שיחה עם Gemini עם הקוד שלכם בהקשר.
לתשומת ליבכם: יצירת מודל AI היא לא דטרמיניסטית. אם התשובה לא עומדת בציפיות, כדאי להריץ שוב את אותה הנחיה כדי לקבל תוצאה טובה יותר.
הערה: יצירת בדיקות יחידה בדרך כלל פועלת טוב יותר אם פותחים את הקובץ באופן מקומי, ואז מבקשים בצ'אט ליצור בדיקות יחידה לקובץ הזה או לפונקציה ספציפית.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["התוכן קשה להבנה","hardToUnderstand","thumb-down"],["שגיאות בקוד לדוגמה או במידע","incorrectInformationOrSampleCode","thumb-down"],["חסרים לי פרטים או דוגמאות","missingTheInformationSamplesINeed","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-06-11 (שעון UTC)."],[[["\u003cp\u003eGemini Code Assist code customization allows users to receive tailored code recommendations based on their organization's internal libraries, private APIs, and coding style, but is exclusive to the Enterprise subscription.\u003c/p\u003e\n"],["\u003cp\u003eCode customization can be triggered via natural language chat, code generation, code transformation, and autocomplete features within the IDE.\u003c/p\u003e\n"],["\u003cp\u003eThe tool can be used for various coding tasks, including writing new code, refactoring, improving readability, code review, debugging, learning, migration, documentation generation, and unit test generation.\u003c/p\u003e\n"],["\u003cp\u003eBest practices include using relevant variable and function names, avoiding deprecated code in indexed repositories, utilizing code generation for code retrieval, and ensuring necessary includes or imports are present in the file.\u003c/p\u003e\n"],["\u003cp\u003eWhen seeking explanations, migration plans, or error insights, leveraging the chat feature for conversations within the context of the codebase is recommended.\u003c/p\u003e\n"]]],[],null,["# Use Gemini Code Assist code customization\n\n| **Note:** Gemini Code Assist code customization is available only in Gemini Code Assist Enterprise. For more information, see [Gemini Code Assist supported features](/gemini/docs/codeassist/overview#supported-features).\n\nThis document describes how to use\n\n[Gemini Code Assist code customization](/gemini/docs/codeassist/code-customization-overview)\n\nand provides a few best practices. This feature lets you receive code\nrecommendations, which draw from the internal libraries, private APIs, and the\ncoding style of your organization.\n\nBefore you begin\n----------------\n\n1. [Set up Gemini Code Assist](/gemini/docs/discover/set-up-gemini) with an [Enterprise subscription](/gemini/docs/codeassist/overview#supported-features).\n2. [Set up Gemini Code Assist code customization](/gemini/docs/codeassist/code-customization-console).\n\nHow to use code customization\n-----------------------------\n\nThe following table lists ways to use\nGemini Code Assist code customization:\n\nUse cases and prompt examples\n-----------------------------\n\nThe following table provides guidance and examples about using\ncode customization in specific use cases:\n\nBest practices\n--------------\n\n- **Use relevant variable and function names or code snippets.** This guides code customization towards the most pertinent code examples.\n- **Use index repositories that you want to scale, and avoid adding deprecated\n functionality.** Code customization helps to scale to the code style, patterns, code semantics, knowledge, and implementations across the codebase. Bad examples of repositories to scale are deprecated functionalities, generated code, and legacy implementations.\n- **For code retrieval use cases, use code generation functionality instead of\n code completion** . Prompt using language such as \"Using the definition of \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e, generate the exact same function,\" or \"Generate the exact implementation of \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e.\"\n- **Have includes or imports present in the file for the code that you want to\n retrieve** to improve Gemini contextual awareness.\n- **Execute only one action for each prompt.** For example, if you want to retrieve code and have this code be implemented in a new function, perform these steps over two prompts.\n- **For use cases where you want more than just code** (such as code explanation, migration plan, or error explanation), use code customization for chat, where you have a conversation with Gemini with your codebase in context.\n- **Note that AI model generation is non-deterministic**. If you aren't satisfied with the response, executing the same prompt again might achieve a better result.\n- **Note that generating unit tests** generally works better if you open the file locally, and then from chat, ask to generate unit tests for this file or a specific function.\n\n### **Get more relevant suggestions with remote repository context**\n\nYou can get more contextually aware and relevant code suggestions by directing Gemini Code Assist to focus on specific remote repositories. By using the \u003ckbd\u003e@\u003c/kbd\u003e symbol in the chat, you can select one or more repositories to be used as a primary source of context for your prompts. This is useful when you are working on a task that is mostly related to a specific set of microservices, libraries, or modules.\n\nTo use a remote repository as context, follow these steps in your IDE's chat:\n\n1. Start your prompt with the \u003ckbd\u003e@\u003c/kbd\u003e symbol. A list of available remote repositories that are indexed will appear.\n2. Select the repository you want to use for context from the list. You can also start typing the repository name to filter the list.\n3. After selecting the repository, write the rest of your prompt.\n\nGemini will then prioritize the selected repository when generating a response.\n\n#### **Example Prompts**\n\nHere are some examples of how you can use this feature:\n\n- **To understand a repository:**\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e What is the overall structure of this repository?\"\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e I'm a new team member. Can you give me an overview of this repository's purpose and key modules?\"\n- **For code generation and modification:**\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e Implement an authentication function similar to the one in this repository.\"\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e Refactor the following code to follow the conventions in the selected repository.\"\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_A_NAME\u003c/var\u003e How can I use the latest functions from this repository to improve my code in \u003cvar translate=\"no\"\u003eREPOSITORY_B_NAME\u003c/var\u003e?\"\n- **For testing:**\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eUNIT_TEST_FILE_NAME\u003c/var\u003e Generate unit tests for \u003cvar translate=\"no\"\u003eMODULE\u003c/var\u003e based on the examples in the selected file.\"\n\nBy using remote repositories as a focused source of context, you can get more accurate and relevant suggestions from Gemini Code Assist, which can help you code faster and more efficiently."]]