שימוש ב-Gemini CLI

בדף הזה מוסבר איך להשתמש ב-Gemini Command Line Interface ‏ (CLI) עם מופע של Gemini Enterprise Agent Platform Workbench.

המסמך הזה מיועד למנתחי נתונים, למדעני נתונים ולמפתחי נתונים שעובדים עם Agent Platform Workbench. במסמך הזה אנחנו מניחים שיש לכם ידע בכתיבת קוד בסביבת נוטבוק.

סקירה כללית

‫Gemini CLI הוא סוכן AI בקוד פתוח שמאפשר גישה ל-Gemini ישירות בטרמינל. מידע נוסף זמין בכתובת geminicli.com.

‫Gemini CLI זמין במופעים של Agent Platform Workbench. אתם יכולים להשתמש ב-Gemini CLI כדי:

  • יוצרים מחברת חדשה.
  • הרצת תאים ב-notebook.
  • כתיבה ועריכה של קוד ותאי טקסט במחברת.
  • הסבר על קוד ועל מושגים טכניים.
  • אינטראקציה עם מערכת הקבצים המקומית של מופע של Agent Platform Workbench, כולל ביצוע פעולות קבצים מורכבות שמתפרסות על כמה קבצים על סמך הוראה אחת ברמה גבוהה.
  • להריץ פקודות Shell בסיסיות.
  • להריץ פקודות כדי ליצור אינטראקציה עם שירותים אחרים של Google Cloud , כמו פלטפורמת הסוכנים של Gemini Enterprise ו-BigQuery.

מגבלות

כשמשתמשים ב-Gemini CLI עם Agent Platform Workbench, חשוב להביא בחשבון את המגבלות הבאות:

  • ‫Gemini CLI הוא CLI בלבד. לא נכללים ממשק צ'אט גרפי וכלי עריכה מתקדמים.

  • כשמבקשים מ-Gemini CLI לשנות מחברת, Gemini CLI משנה את קובץ המחברת ישירות בדיסק של המופע. לכן, אי אפשר לבטל עריכות שבוצעו באמצעות Gemini CLI באמצעות הלחצן ביטול של עורך המחברות או באמצעות Control+Z (Command+Z ב-macOS). אבל אפשר לבקש מ-Gemini CLI לבטל שינוי באמצעות פקודה בשפה טבעית, כמו Undo your last change.

לפני שמתחילים

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Compute Engine, Notebooks, and Agent Platform APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Compute Engine, Notebooks, and Agent Platform APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

התפקידים הנדרשים

כדי להשתמש ב-Gemini CLI ב-Agent Platform Workbench, צריך להעניק הרשאות למשתמש של מופע Agent Platform Workbench ולחשבון השירות של המופע.

הענקת הרשאות למשתמש של המופע

כדי לקבל את ההרשאות שנדרשות לשימוש ב-Gemini CLI במופע של Agent Platform Workbench, צריך לבקש מהאדמין להקצות לכם את תפקיד ה-IAM‏ Agent Platform User (roles/aiplatform.user)) בפרויקט. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.

מתן הרשאה לחשבון השירות של המופע

כדי לוודא שלחשבון השירות של מופע Agent Platform Workbench יש את ההרשאה הנדרשת להפעלת Gemini CLI במופע Agent Platform Workbench, צריך לבקש מהאדמין להקצות לחשבון השירות של מופע Agent Platform Workbench את תפקיד ה-IAM‏ Agent Platform User (roles/aiplatform.user)) בפרויקט.

מידע נוסף על הקצאת תפקידים מופיע במאמר ניהול הגישה לפרויקטים, לתיקיות ולארגונים.

התפקיד שמוגדר מראש מכיל את ההרשאה aiplatform.endpoints.predict, שנדרשת כדי להפעיל את Gemini CLI במכונת עבודה של Agent Platform.

יכול להיות שהאדמין יוכל גם להעניק לחשבון השירות של מופע Agent Platform Workbench את ההרשאה הזו באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

שימוש ב-Gemini CLI

  1. נכנסים לדף Instances במסוף Google Cloud .

    כניסה לדף Instances

  2. לצד השם של מופע Agent Platform Workbench, לוחצים על Open JupyterLab.

    מופע של Agent Platform Workbench ייפתח ב-JupyterLab.

  3. ב-JupyterLab, לוחצים על File > New launcher.

  4. בכרטיסייה Launcher, בקטע Other, לוחצים על המשבצת Gemini CLI.

  5. אם זו הפעם הראשונה שאתם פותחים טרמינל של Gemini CLI, מזינים Y כדי להביע הסכמה לתנאים ולהגבלות.

    המופע של Agent Platform Workbench מתקין את Gemini CLI.

  6. בטרמינל של Gemini CLI, מזינים הנחיה.

    לדוגמה, אפשר להזין Create a new notebook named 'test-notebook'. כדי לראות דוגמאות להנחיות שיכולות לעזור, אפשר לעיין בהנחיות לדוגמה.

הנחיות לדוגמה

כדי לקבל רעיונות לשימוש ב-Gemini CLI, אפשר לעיין בהנחיות לדוגמה הבאות:

  • ‫"Create a new notebook that trains a model to predict 'income bracket' from bigquery-public-data.ml_datasets.census_adult_income, using BigQuery and Python."

  • ‫"Summarize the notebook named 'test-file', and propose next steps for the project."

  • "אני רוצה לקבל סקירה כללית של מחברות ה-Jupyter בספרייה הזו. לכל קובץ ‎ .ipynb, תציג לי את 5 השורות הראשונות של הקובץ".

  • ‫"Create a script using the contents of the 'test-file' notebook."

  • "תראה לי איך לגשת לנתונים מטבלאות BigQuery מתוך Agent Platform Workbench".

  • ‫"Query the bigquery-public-data.ml_datasets.census_adult_income table to find the number of people with an income bracket of > 50K."

  • ‫"Set my default Google Cloud project to my-project." ‏(הגדרת פרויקט ברירת המחדל שלי כ-my-project).

  • ‫"Create a Cloud Storage bucket, and upload all the CSV files from my current directory to it." (תצורת קטגוריה של Cloud Storage והעלאה של כל קובצי ה-CSV מהספרייה הנוכחית לקטגוריה).

  • ‫"Create a Compute Engine instance with a Debian 11 image and an n1-standard-4 machine type" (יצירת מכונה של Compute Engine עם תמונת Debian 11 וסוג מכונה n1-standard-4).

  • ‫"Create a notebook file that runs through the code in the 'test-script'. תוסיף תאי טקסט שמסבירים את הקוד".

שליטה בגישה ל-Gemini CLI

אפשר לשלוט בגישה ל-Gemini CLI ב-Agent Platform Workbench באמצעות השיטות הבאות:

  • אדמינים יכולים להגדיר מדיניות ארגונית כדי להגביל את השימוש במודלים ספציפיים של Gemini ברמת הארגון, התיקייה או הפרויקט. איך שולטים בגישה למודלים ב-Model Garden ‫Gemini CLI ממשיך להופיע ב-JupyterLab, אבל ה-CLI לא מגיב להנחיות.

  • אם לא מעניקים את ההרשאה aiplatform.endpoints.predict, אדמין יכול לחסום זהויות מסוימות כך שלא יוכלו להשתמש בנקודות הקצה של Gemini להסקת מסקנות.

שימוש בפקודה המיוחדת של Gemini CLI

כדי להשתמש ב-Gemini CLI ישירות בתא בקובץ המחברת, מבצעים את הפעולות הבאות:

  1. מוודאים ש-Gemini CLI מופעל ושהמשתמש או היוצר הסכימו לתנאים ולהגבלות.
  2. בשורה הראשונה של תא חדש, מזינים %%geminicli_magic.
  3. באותו תא, כותבים את ההנחיה בשורה הבאה.
  4. מריצים את התא.

‫Gemini CLI מוסיף תא חדש מתחת עם התשובה שלו.

פתרון בעיות

אם נתקלתם בבעיה בשימוש ב-Gemini CLI עם מופעים של Agent Platform Workbench, תוכלו להיעזר בפתרון בעיות ב-Agent Platform Workbench כדי לפתור בעיות נפוצות.

המאמרים הבאים