גישה למודלים של Gemini מתהליך עבודה באמצעות Vertex AI

‫AI גנרטיבי ב-Vertex AI (שנקרא גם AI גנרטיבי או GenAI) מאפשר לכם לגשת למודלים של AI גנרטיבי של Google למגוון רחב של מודאליות (טקסט, קוד, תמונות, דיבור). אתם יכולים לבדוק ולכוונן את מודלי השפה הגדולים (LLM) האלה, ואז לפרוס אותם לשימוש באפליקציות מבוססות-AI. מידע נוסף זמין במאמר סקירה כללית על AI גנרטיבי ב-Vertex AI.

ב-Vertex AI יש מגוון של מודלים בסיסיים של AI גנרטיבי שאפשר לגשת אליהם דרך API, כולל המודלים שבהם נעשה שימוש במדריך הזה. מידע נוסף על בחירת מודל זמין במאמר מודלים של Google.

כל מודל נחשף דרך נקודת קצה של בעל תוכן דיגיטלי שספציפית לGoogle Cloud פרויקט שלכם, כך שאין צורך לפרוס את מודל הבסיס אלא אם אתם צריכים לכוונן אותו לתרחיש שימוש ספציפי. אפשר לשלוח הנחיה לנקודת הקצה של בעל התוכן הדיגיטלי. הנחיה היא בקשה בשפה טבעית שנשלחת ל-LLM כדי לקבל תגובה.

במדריך הזה נדגים תהליכי עבודה שיוצרים תגובות ממודלים של Vertex AI על ידי שליחת הנחיות טקסט לנקודות הקצה (endpoint) של המוציא לאור באמצעות מחבר Workflows או בקשת HTTP ‏POST. מידע נוסף זמין במאמרים סקירה כללית על Vertex AI API connector ושליחת בקשת HTTP.

שימו לב: אפשר לפרוס ולהריץ כל תהליך עבודה בנפרד.

מטרות

במדריך הזה תלמדו:

  1. מפעילים את Vertex AI API ואת Workflows API, ומקצים לחשבון השירות את התפקיד 'משתמש Vertex AI' (roles/aiplatform.user). התפקיד הזה מאפשר גישה לרוב היכולות של Vertex AI. מידע נוסף על הגדרת Vertex AI זמין במאמר הגדרת פרויקט וסביבת פיתוח.
  2. פריסה והרצה של תהליך עבודה שמנחה מודל Vertex AI לתאר תמונה שזמינה לכולם דרך Cloud Storage. מידע נוסף זמין במאמר בנושא הגדרת גישה ציבורית לנתונים.
  3. פריסה והפעלה של תהליך עבודה שחוזר על עצמו בלולאה ברשימה של מדינות במקביל, ומבקש ממודל Vertex AI ליצור ולהחזיר את ההיסטוריה של המדינות. שימוש בענפים מקבילים מאפשר לקצר את זמן הביצוע הכולל, כי הוא מתחיל את הקריאות למודל השפה הגדול בו-זמנית ומחכה שכולן יסתיימו לפני שהוא משלב את התוצאות. מידע נוסף על הפעלת שלבים בתהליך עבודה במקביל
  4. פריסת תהליך עבודה שיכול לסכם מסמך ארוך. יש מגבלה על חלון ההקשר, שמגדיר כמה זמן אחורה המודל בודק במהלך האימון (ובתחזיות). לכן, תהליך העבודה מחלק את המסמך לחלקים קטנים יותר, ואז מנחה מודל של Vertex AI לסכם כל חלק במקביל. מידע נוסף זמין במאמרים סקירה כללית של אסטרטגיות לכתיבת הנחיות ואופק התחזית, חלון ההקשר וחלון התחזית.

עלויות

במסמך הזה משתמשים ברכיבים הבאים של Google Cloud, והשימוש בהם כרוך בתשלום:

כדי להעריך את ההוצאות בהתאם לתחזית השימוש שלכם, אתם יכולים להיעזר במחשבון העלויות.

משתמשים חדשים של Google Cloud ? יכול להיות שאתם זכאים לתקופת ניסיון בחינם.

כשמסיימים את המשימות שמתוארות במסמך הזה אפשר למחוק את המשאבים שיצרתם כדי להימנע מחיובים נוספים. מידע נוסף זמין בקטע הסרת המשאבים.

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

לפני שמנסים את הדוגמאות במדריך הזה, חשוב לוודא שביצעתם את הפעולות הבאות.

המסוף

  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 Vertex AI and Workflows APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Vertex AI > Vertex AI User role to the service account.

      To grant the role, find the Select a role list, then select Vertex AI > Vertex AI User.

    7. Click Continue.
    8. Click Done to finish creating the service account.

  6. 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

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

  8. Enable the Vertex AI and Workflows APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  9. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role (roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles.
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    5. Click Create and continue.
    6. Grant the Vertex AI > Vertex AI User role to the service account.

      To grant the role, find the Select a role list, then select Vertex AI > Vertex AI User.

    7. Click Continue.
    8. Click Done to finish creating the service account.

gcloud

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. התקינו את ה-CLI של Google Cloud.

  3. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  4. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  5. יוצרים או בוחרים Google Cloud פרויקט.

    תפקידים שנדרשים כדי לבחור או ליצור פרויקט

    • Select a project: כדי לבחור פרויקט לא צריך תפקיד IAM ספציפי – אפשר לבחור כל פרויקט שקיבלתם בו תפקיד.
    • יצירת פרויקט: כדי ליצור פרויקט, צריך את התפקיד Project Creator (יצירת פרויקטים) (roles/resourcemanager.projectCreator), שכולל את ההרשאה resourcemanager.projects.create. איך מקצים תפקידים
    • יוצרים Google Cloud פרויקט:

      gcloud projects create PROJECT_ID

      מחליפים את PROJECT_ID בשם של פרויקט Google Cloud שיוצרים.

    • בוחרים את הפרויקט שיצרתם: Google Cloud

      gcloud config set project PROJECT_ID

      מחליפים את PROJECT_ID בשם הפרויקט ב- Google Cloud .

  6. מוודאים שהחיוב מופעל בפרויקט Google Cloud .

  7. מפעילים את ממשקי ה-API של Vertex AI ו-Workflows:

    תפקידים שנדרשים להפעלת ממשקי API

    כדי להפעיל ממשקי API, צריך את תפקיד ה-IAM 'אדמין של Service Usage' (roles/serviceusage.serviceUsageAdmin), שכולל את ההרשאה serviceusage.services.enable. איך מקצים תפקידים

    gcloud services enable aiplatform.googleapis.com workflows.googleapis.com
  8. מגדירים את האימות:

    1. מוודאים שיש לכם את תפקיד ה-IAM ‏Create Service Accounts ‏(roles/iam.serviceAccountCreator) ואת תפקיד ה-IAM ‏Project Admin ‏(roles/resourcemanager.projectIamAdmin). איך מקצים תפקידים
    2. יוצרים את חשבון השירות:

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

      מחליפים את הערך SERVICE_ACCOUNT_NAME בשם שרוצים לתת לחשבון השירות.

    3. מקצים לחשבון השירות את התפקיד roles/aiplatform.user ב-IAM:

      gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=roles/aiplatform.user

      מחליפים את מה שכתוב בשדות הבאים:

      • SERVICE_ACCOUNT_NAME: השם של חשבון השירות
      • PROJECT_ID: מזהה הפרויקט שבו יצרתם את חשבון השירות
  9. התקינו את ה-CLI של Google Cloud.

  10. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  11. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  12. יוצרים או בוחרים Google Cloud פרויקט.

    תפקידים שנדרשים כדי לבחור או ליצור פרויקט

    • Select a project: כדי לבחור פרויקט לא צריך תפקיד IAM ספציפי – אפשר לבחור כל פרויקט שקיבלתם בו תפקיד.
    • יצירת פרויקט: כדי ליצור פרויקט, צריך את התפקיד Project Creator (יצירת פרויקטים) (roles/resourcemanager.projectCreator), שכולל את ההרשאה resourcemanager.projects.create. איך מקצים תפקידים
    • יוצרים Google Cloud פרויקט:

      gcloud projects create PROJECT_ID

      מחליפים את PROJECT_ID בשם של פרויקט Google Cloud שיוצרים.

    • בוחרים את הפרויקט שיצרתם: Google Cloud

      gcloud config set project PROJECT_ID

      מחליפים את PROJECT_ID בשם הפרויקט ב- Google Cloud .

  13. מוודאים שהחיוב מופעל בפרויקט Google Cloud .

  14. מפעילים את ממשקי ה-API של Vertex AI ו-Workflows:

    תפקידים שנדרשים להפעלת ממשקי API

    כדי להפעיל ממשקי API, צריך את תפקיד ה-IAM 'אדמין של Service Usage' (roles/serviceusage.serviceUsageAdmin), שכולל את ההרשאה serviceusage.services.enable. איך מקצים תפקידים

    gcloud services enable aiplatform.googleapis.com workflows.googleapis.com
  15. מגדירים את האימות:

    1. מוודאים שיש לכם את תפקיד ה-IAM ‏Create Service Accounts ‏(roles/iam.serviceAccountCreator) ואת תפקיד ה-IAM ‏Project Admin ‏(roles/resourcemanager.projectIamAdmin). איך מקצים תפקידים
    2. יוצרים את חשבון השירות:

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

      מחליפים את הערך SERVICE_ACCOUNT_NAME בשם שרוצים לתת לחשבון השירות.

    3. מקצים לחשבון השירות את התפקיד roles/aiplatform.user ב-IAM:

      gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=roles/aiplatform.user

      מחליפים את מה שכתוב בשדות הבאים:

      • SERVICE_ACCOUNT_NAME: השם של חשבון השירות
      • PROJECT_ID: מזהה הפרויקט שבו יצרתם את חשבון השירות

פריסת תהליך עבודה שמתאר תמונה

פריסת תהליך עבודה שמשתמש בשיטת מחבר (generateContent) כדי לשלוח בקשה לנקודת קצה של מפרסם מודל. השיטה מספקת תמיכה ביצירת תוכן עם קלט רב-אופני.

תהליך העבודה מספק הנחיה טקסטואלית ואת ה-URI של תמונה שזמינה באופן ציבורי בקטגוריה של Cloud Storage. אפשר לראות את התמונה ובמסוף אפשר לראות את פרטי האובייקט. Google Cloud

תהליך העבודה מחזיר תיאור של התמונה מהתשובה שנוצרה על ידי המודל.

למידע נוסף על הפרמטרים של גוף בקשת ה-HTTP שמשמשים כשמזינים הנחיה למודל LLM, ועל רכיבי גוף התגובה, אפשר לעיין במאמר יצירת תוכן באמצעות Gemini API ב-Vertex AI.

המסוף

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

    כניסה לדף Workflows

  2. לוחצים על Create.

  3. מזינים שם לתהליך העבודה החדש: describe-image.

  4. ברשימה Region, בוחרים באפשרות us-central1 (Iowa).

  5. בקטע Service account, בוחרים את חשבון השירות שיצרתם קודם.

  6. לוחצים על הבא.

  7. בעורך תהליכי העבודה, מזינים את ההגדרה הבאה לתהליך העבודה:

    main:
        params: [args]
        steps:
        - init:
            assign:
                - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                - location: "us-central1"
                - model: "gemini-2.5-flash"
                - text_combined: ""
        - ask_llm:
            call: googleapis.aiplatform.v1.projects.locations.endpoints.generateContent
            args:
                model: ${"projects/" + project + "/locations/" + location + "/publishers/google/models/" + model}
                region: ${location}
                body:
                    contents:
                        role: user
                        parts:
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: ${args.image_url}
                        - text: Describe this picture in detail
                    generation_config:
                        temperature: 0.4
                        max_output_tokens: 2048
                        top_p: 1
                        top_k: 32
            result: llm_response
        - return_result:
            return:
                image_url: ${args.image_url}
                image_description: ${llm_response.candidates[0].content.parts[0].text}
  8. לוחצים על פריסה.

gcloud

  1. יוצרים קובץ קוד מקור לתהליך העבודה:

    touch describe-image.yaml
  2. בכלי לעריכת טקסט, מעתיקים את זרימת העבודה הבאה לקובץ קוד המקור:

    main:
        params: [args]
        steps:
        - init:
            assign:
                - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                - location: "us-central1"
                - model: "gemini-2.5-flash"
                - text_combined: ""
        - ask_llm:
            call: googleapis.aiplatform.v1.projects.locations.endpoints.generateContent
            args:
                model: ${"projects/" + project + "/locations/" + location + "/publishers/google/models/" + model}
                region: ${location}
                body:
                    contents:
                        role: user
                        parts:
                        - fileData:
                            mimeType: image/jpeg
                            fileUri: ${args.image_url}
                        - text: Describe this picture in detail
                    generation_config:
                        temperature: 0.4
                        max_output_tokens: 2048
                        top_p: 1
                        top_k: 32
            result: llm_response
        - return_result:
            return:
                image_url: ${args.image_url}
                image_description: ${llm_response.candidates[0].content.parts[0].text}
  3. מריצים את הפקודה הבאה כדי לפרוס את תהליך העבודה:

    gcloud workflows deploy describe-image \
        --source=describe-image.yaml \
        --location=us-central1 \
        --service-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com

ביצוע תהליך העבודה

כשמריצים תהליך עבודה, מופעלת ההגדרה הנוכחית של תהליך העבודה שמשויכת ל-workflow.

המסוף

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

    כניסה לדף Workflows

  2. בדף Workflows, בוחרים את זרימת העבודה describe-image כדי לעבור לדף הפרטים שלה.

  3. בדף פרטי תהליך העבודה, לוחצים על הפעלה.

  4. בשדה Input (קלט), מזינים את הפרטים הבאים:

    {"image_url":"gs://generativeai-downloads/images/scones.jpg"}
  5. לוחצים שוב על Execute.

  6. תוצאות תהליך העבודה מוצגות בחלונית Output.

    הפלט אמור להיראות כך:

    {
      "image_description": "There are three pink peony flowers on the right side of the picture[]...]There is a white napkin on the table.",
      "image_url": "gs://generativeai-downloads/images/scones.jpg"
    }

gcloud

  1. פותחים טרמינל.

  2. מריצים את תהליך העבודה:

    gcloud workflows run describe-image \
        --data='{"image_url":"gs://generativeai-downloads/images/scones.jpg"}'

    תוצאות ההרצה צריכות להיות דומות לתוצאות הבאות:

      Waiting for execution [258b530e-a093-46d7-a4ff-cbf5392273c0] to complete...done.
      argument: '{"image_url":"gs://generativeai-downloads/images/scones.jpg"}'
      createTime: '2024-02-09T13:59:32.166409938Z'
      duration: 4.174708484s
      endTime: '2024-02-09T13:59:36.341118422Z'
      name: projects/1051295516635/locations/us-central1/workflows/describe-image/executions/258b530e-a093-46d7-a4ff-cbf5392273c0
      result: "{\"image_description\":\"The picture shows a rustic table with a white surface,\
        \ on which there are several scones with blueberries, as well as two cups of coffee\
        [...]
        \ on the table. The background of the table is a dark blue color.\",\"image_url\"\
        :\"gs://generativeai-downloads/images/scones.jpg\"}"
      startTime: '2024-02-09T13:59:32.166409938Z'
      state: SUCCEEDED

פריסת תהליך עבודה שיוצר היסטוריות של מדינות

פריסת תהליך עבודה שחוזר על עצמו ברשימת קלט של מדינות במקביל ומשתמש בשיטת מחבר (generateContent) כדי לשלוח בקשה לנקודת קצה של מפרסם מודל. השיטה מספקת תמיכה ביצירת תוכן עם קלט רב-אופני.

תהליך העבודה מחזיר את ההיסטוריה של המדינות שנוצרה על ידי המודל, ומשלב אותן במפה.

למידע נוסף על הפרמטרים של גוף בקשת ה-HTTP שמשמשים כשמזינים הנחיה למודל LLM, ועל רכיבי גוף התגובה, אפשר לעיין במאמר יצירת תוכן באמצעות Gemini API ב-Vertex AI.

המסוף

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

    כניסה לדף Workflows

  2. לוחצים על Create.

  3. מזינים שם לתהליך העבודה החדש: gemini-pro-country-histories.

  4. ברשימה Region, בוחרים באפשרות us-central1 (Iowa).

  5. בקטע Service account, בוחרים את חשבון השירות שיצרתם קודם.

  6. לוחצים על הבא.

  7. בעורך תהליכי העבודה, מזינים את ההגדרה הבאה לתהליך העבודה:

    main:
        params: [args]
        steps:
        - init:
            assign:
                - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                - location: "us-central1"
                - model: "gemini-2.5-flash"
                - histories: {}
        - loop_over_countries:
            parallel:
                shared: [histories]
                for:
                    value: country
                    in: ${args.countries}
                    steps:
                        - ask_llm:
                            call: googleapis.aiplatform.v1.projects.locations.endpoints.generateContent
                            args:
                                model: ${"projects/" + project + "/locations/" + location + "/publishers/google/models/" + model}
                                region: ${location}
                                body:
                                    contents:
                                        role: "USER"
                                        parts:
                                            text: ${"Can you tell me about the history of " + country}
                                    generation_config:
                                        temperature: 0.5
                                        max_output_tokens: 2048
                                        top_p: 0.8
                                        top_k: 40
                            result: llm_response
                        - add_to_histories:
                            assign:
                                - histories[country]: ${llm_response.candidates[0].content.parts[0].text}
        - return_result:
            return: ${histories}
  8. לוחצים על פריסה.

gcloud

  1. יוצרים קובץ קוד מקור לתהליך העבודה:

    touch gemini-pro-country-histories.yaml
  2. בכלי לעריכת טקסט, מעתיקים את זרימת העבודה הבאה לקובץ קוד המקור:

    main:
        params: [args]
        steps:
        - init:
            assign:
                - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                - location: "us-central1"
                - model: "gemini-2.5-flash"
                - histories: {}
        - loop_over_countries:
            parallel:
                shared: [histories]
                for:
                    value: country
                    in: ${args.countries}
                    steps:
                        - ask_llm:
                            call: googleapis.aiplatform.v1.projects.locations.endpoints.generateContent
                            args:
                                model: ${"projects/" + project + "/locations/" + location + "/publishers/google/models/" + model}
                                region: ${location}
                                body:
                                    contents:
                                        role: "USER"
                                        parts:
                                            text: ${"Can you tell me about the history of " + country}
                                    generation_config:
                                        temperature: 0.5
                                        max_output_tokens: 2048
                                        top_p: 0.8
                                        top_k: 40
                            result: llm_response
                        - add_to_histories:
                            assign:
                                - histories[country]: ${llm_response.candidates[0].content.parts[0].text}
        - return_result:
            return: ${histories}
  3. מריצים את הפקודה הבאה כדי לפרוס את תהליך העבודה:

    gcloud workflows deploy gemini-pro-country-histories \
        --source=gemini-pro-country-histories.yaml \
        --location=us-central1 \
        --service-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com

ביצוע תהליך העבודה

כשמריצים תהליך עבודה, מופעלת ההגדרה הנוכחית של תהליך העבודה שמשויכת ל-workflow.

המסוף

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

    כניסה לדף Workflows

  2. בדף Workflows, בוחרים את זרימת העבודה gemini-pro-country-histories כדי לעבור לדף הפרטים שלה.

  3. בדף פרטי תהליך העבודה, לוחצים על הפעלה.

  4. בשדה Input (קלט), מזינים את הפרטים הבאים:

    {"countries":["Argentina", "Bhutan", "Cyprus", "Denmark", "Ethiopia"]}
  5. לוחצים שוב על Execute.

  6. תוצאות תהליך העבודה מוצגות בחלונית Output.

    הפלט אמור להיראות כך:

    {
      "Argentina": "The history of Argentina is a complex and fascinating one, marked by periods of prosperity and decline, political [...]
      "Bhutan": "The history of Bhutan is a rich and fascinating one, dating back to the 7th century AD. Here is a brief overview: [...]
      "Cyprus": "The history of Cyprus is a long and complex one, spanning over 10,000 years. The island has been ruled by a succession [...]
      "Denmark": "1. **Prehistory and Early History (c. 12,000 BC - 800 AD)**\\n   - The earliest evidence of human habitation in Denmark [...]
      "Ethiopia": "The history of Ethiopia is a long and complex one, stretching back to the earliest human civilizations. The country is [...]
    }

gcloud

  1. פותחים טרמינל.

  2. מריצים את תהליך העבודה:

    gcloud workflows run gemini-pro-country-histories \
        --data='{"countries":["Argentina", "Bhutan", "Cyprus", "Denmark", "Ethiopia"]}' \
        --location=us-central1

    תוצאות ההרצה צריכות להיות דומות לתוצאות הבאות:

      Waiting for execution [7ae1ccf1-29b7-4c2c-99ec-7a12ae289391] to complete...done.
      argument: '{"countries":["Argentina","Bhutan","Cyprus","Denmark","Ethiopia"]}'
      createTime: '2024-02-09T16:25:16.742349156Z'
      duration: 12.075968673s
      endTime: '2024-02-09T16:25:28.818317829Z'
      name: projects/1051295516635/locations/us-central1/workflows/gemini-pro-country-histories/executions/7ae1ccf1-29b7-4c2c-99ec-7a12ae289391
      result: "{\"Argentina\":\"The history of Argentina can be traced back to the arrival\
        [...]
        n* 2015: Argentina elects Mauricio Macri as president.\",\"Bhutan\":\"The history\
        [...]
        \ natural beauty, ancient monasteries, and friendly people.\",\"Cyprus\":\"The history\
        [...]
        ,\"Denmark\":\"The history of Denmark can be traced back to the Stone Age, with\
        [...]
        \ a high standard of living.\",\"Ethiopia\":\"The history of Ethiopia is long and\
        [...]
      startTime: '2024-02-09T16:25:16.742349156Z'
      state: SUCCEEDED

פריסת תהליך עבודה שמסכם מסמך ארוך

פריסת תהליך עבודה שמחלק מסמך גדול לחלקים קטנים יותר, ושולח http.post בקשות לנקודת קצה של מפרסם מודל במקביל, כדי שהמודל יוכל לסכם כל חלק בו-זמנית. בסופו של דבר, תהליך העבודה משלב את כל התקצירים החלקיים לתקציר מלא.

למידע נוסף על הפרמטרים של גוף בקשת ה-HTTP שמשמשים כשמזינים הנחיה למודל LLM, ועל רכיבי גוף התגובה, אפשר לעיין במאמר יצירת תוכן באמצעות Gemini API ב-Vertex AI.

הגדרת תהליך העבודה מניחה שיצרתם קטגוריית Cloud Storage שאליה אפשר להעלות קובץ טקסט. מידע נוסף על מחבר Workflows (googleapis.storage.v1.objects.get) שמשמש לאחזור אובייקטים מקטגוריית Cloud Storage זמין במאמר הפניה למחברים.

אחרי שפורסים את תהליך העבודה, אפשר להפעיל אותו על ידי יצירת טריגר מתאים של Eventarc, ואז על ידי העלאת קובץ לקטגוריה. מידע נוסף זמין במאמר בנושא העברת אירועים מ-Cloud Storage אל Workflows. שימו לב שצריך להפעיל ממשקי API נוספים ולהעניק תפקידים נוספים, כולל התפקיד Storage Object User ‏(roles/storage.objectUser) לחשבון השירות, כדי לתמוך בשימוש באובייקטים של Cloud Storage. מידע נוסף זמין בקטע הכנה ליצירת טריגר.

המסוף

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

    כניסה לדף Workflows

  2. לוחצים על Create.

  3. מזינים שם לתהליך העבודה החדש: gemini-pro-summaries.

  4. ברשימה Region, בוחרים באפשרות us-central1 (Iowa).

  5. בקטע Service account, בוחרים את חשבון השירות שיצרתם קודם.

  6. לוחצים על הבא.

  7. בעורך תהליכי העבודה, מזינים את ההגדרה הבאה לתהליך העבודה:

    main:
        params: [input]
        steps:
        - assign_file_vars:
            assign:
                - file_size: ${int(input.data.size)}
                - chunk_size: 64000
                - n_chunks: ${int(file_size / chunk_size)}
                - summaries: []
                - all_summaries_concatenated: ""
        - loop_over_chunks:
            parallel:
                shared: [summaries]
                for:
                    value: chunk_idx
                    range: ${[0, n_chunks]}
                    steps:
                        - assign_bounds:
                            assign:
                                - lower_bound: ${chunk_idx * chunk_size}
                                - upper_bound: ${(chunk_idx + 1) * chunk_size}
                                - summaries: ${list.concat(summaries, "")}
                        - dump_file_content:
                            call: http.get
                            args:
                                url: ${"https://storage.googleapis.com/storage/v1/b/" + input.data.bucket + "/o/" + input.data.name + "?alt=media"}
                                auth:
                                    type: OAuth2
                                headers:
                                    Range: ${"bytes=" + lower_bound + "-" + upper_bound}
                            result: file_content
                        - assign_chunk:
                            assign:
                                - chunk: ${file_content.body}
                        - generate_chunk_summary:
                            call: ask_gemini_for_summary
                            args:
                                textToSummarize: ${chunk}
                            result: summary
                        - assign_summary:
                            assign:
                                - summaries[chunk_idx]: ${summary}
        - concat_summaries:
            for:
                value: summary
                in: ${summaries}
                steps:
                    - append_summaries:
                        assign:
                            - all_summaries_concatenated: ${all_summaries_concatenated + "\n" + summary}
        - reduce_summary:
            call: ask_gemini_for_summary
            args:
                textToSummarize: ${all_summaries_concatenated}
            result: final_summary
        - return_result:
            return:
                - summaries: ${summaries}
                - final_summary: ${final_summary}
    
    ask_gemini_for_summary:
        params: [textToSummarize]
        steps:
            - init:
                assign:
                    - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                    - location: "us-central1"
                    - model: "gemini-2.5-pro"
                    - summary: ""
            - call_gemini:
                call: http.post
                args:
                    url: ${"https://" + location + "-aiplatform.googleapis.com" + "/v1/projects/" + project + "/locations/" + location + "/publishers/google/models/" + model + ":generateContent"}
                    auth:
                        type: OAuth2
                    body:
                        contents:
                            role: user
                            parts:
                                - text: '${"Make a summary of the following text:\n\n" + textToSummarize}'
                        generation_config:
                            temperature: 0.2
                            maxOutputTokens: 2000
                            topK: 10
                            topP: 0.9
                result: gemini_response
            # Sometimes, there's no text, for example, due to safety settings
            - check_text_exists:
                switch:
                - condition: ${not("parts" in gemini_response.body.candidates[0].content)}
                  next: return_summary
            - extract_text:
                assign:
                    - summary: ${gemini_response.body.candidates[0].content.parts[0].text}
            - return_summary:
                return: ${summary}
  8. לוחצים על פריסה.

gcloud

  1. יוצרים קובץ קוד מקור לתהליך העבודה:

    touch gemini-pro-summaries.yaml
  2. בכלי לעריכת טקסט, מעתיקים את זרימת העבודה הבאה לקובץ קוד המקור:

    main:
        params: [input]
        steps:
        - assign_file_vars:
            assign:
                - file_size: ${int(input.data.size)}
                - chunk_size: 64000
                - n_chunks: ${int(file_size / chunk_size)}
                - summaries: []
                - all_summaries_concatenated: ""
        - loop_over_chunks:
            parallel:
                shared: [summaries]
                for:
                    value: chunk_idx
                    range: ${[0, n_chunks]}
                    steps:
                        - assign_bounds:
                            assign:
                                - lower_bound: ${chunk_idx * chunk_size}
                                - upper_bound: ${(chunk_idx + 1) * chunk_size}
                                - summaries: ${list.concat(summaries, "")}
                        - dump_file_content:
                            call: http.get
                            args:
                                url: ${"https://storage.googleapis.com/storage/v1/b/" + input.data.bucket + "/o/" + input.data.name + "?alt=media"}
                                auth:
                                    type: OAuth2
                                headers:
                                    Range: ${"bytes=" + lower_bound + "-" + upper_bound}
                            result: file_content
                        - assign_chunk:
                            assign:
                                - chunk: ${file_content.body}
                        - generate_chunk_summary:
                            call: ask_gemini_for_summary
                            args:
                                textToSummarize: ${chunk}
                            result: summary
                        - assign_summary:
                            assign:
                                - summaries[chunk_idx]: ${summary}
        - concat_summaries:
            for:
                value: summary
                in: ${summaries}
                steps:
                    - append_summaries:
                        assign:
                            - all_summaries_concatenated: ${all_summaries_concatenated + "\n" + summary}
        - reduce_summary:
            call: ask_gemini_for_summary
            args:
                textToSummarize: ${all_summaries_concatenated}
            result: final_summary
        - return_result:
            return:
                - summaries: ${summaries}
                - final_summary: ${final_summary}
    
    ask_gemini_for_summary:
        params: [textToSummarize]
        steps:
            - init:
                assign:
                    - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                    - location: "us-central1"
                    - model: "gemini-2.5-pro"
                    - summary: ""
            - call_gemini:
                call: http.post
                args:
                    url: ${"https://" + location + "-aiplatform.googleapis.com" + "/v1/projects/" + project + "/locations/" + location + "/publishers/google/models/" + model + ":generateContent"}
                    auth:
                        type: OAuth2
                    body:
                        contents:
                            role: user
                            parts:
                                - text: '${"Make a summary of the following text:\n\n" + textToSummarize}'
                        generation_config:
                            temperature: 0.2
                            maxOutputTokens: 2000
                            topK: 10
                            topP: 0.9
                result: gemini_response
            # Sometimes, there's no text, for example, due to safety settings
            - check_text_exists:
                switch:
                - condition: ${not("parts" in gemini_response.body.candidates[0].content)}
                  next: return_summary
            - extract_text:
                assign:
                    - summary: ${gemini_response.body.candidates[0].content.parts[0].text}
            - return_summary:
                return: ${summary}
  3. מריצים את הפקודה הבאה כדי לפרוס את תהליך העבודה:

    gcloud workflows deploy gemini-pro-summaries \
        --source=gemini-pro-summaries.yaml \
        --location=us-central1 \
        --service-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com

הסרת המשאבים

כדי להימנע מחיובים בחשבון Google Cloud בגלל השימוש במשאבים שנעשה במסגרת המדריך הזה, אפשר למחוק את הפרויקט שמכיל את המשאבים, או להשאיר את הפרויקט ולמחוק את המשאבים בנפרד.

מחיקת הפרויקט

המסוף

  1. במסוף Google Cloud , נכנסים לדף Manage resources.

    כניסה לדף Manage resources

  2. ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
  3. כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.

gcloud

כדי למחוק Google Cloud פרויקט:

gcloud projects delete PROJECT_ID

מחיקת משאבים בודדים

מחיקת תהליכי העבודה שיצרתם במדריך הזה.

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