Hızlı başlangıç kılavuzu: gcloud CLI'yı Developer Knowledge API ile kullanma

Bu hızlı başlangıç kılavuzunda, Google Cloud CLI'yı kullanarak Developer Knowledge API ile sorguları nasıl yanıtlayacağınız ve geliştirici belgelerini nasıl arayıp alacağınız gösterilmektedir.

Başlamadan önce

Developer Knowledge API'yi gcloud CLI ile kullanmaya başlamadan önce aşağıdaki adımları tamamlayın.

gcloud CLI'yı yükleme ve yapılandırma

gcloud CLI'yı yüklemek ve yapılandırmak için aşağıdaki adımları uygulayın:

  1. gcloud CLI'yı yüklemediyseniz gcloud CLI'yı yükleyin.

  2. En yeni sürüme sahip olduğunuzdan emin olmak için gcloud components update komutunu çalıştırın:

    gcloud components update
    
  3. gcloud auth login komutunu çalıştırarak Google Cloud hesabınızda oturum açın:

    gcloud auth login
    
  4. gcloud config set komutunu çalıştırarak etkin Google Cloud projenizi ayarlayın:

    gcloud config set project PROJECT_ID
    

    PROJECT_ID yerine Google Cloud projenizin kimliğini yazın.

API'yi etkinleştirme

Developer Knowledge API'yi etkinleştirmek için aşağıdaki adımları uygulayın:

  1. gcloud services enable komutunu çalıştırarak Google Cloud projenizde Developer Knowledge API'yi etkinleştirin:

    gcloud services enable developerknowledge.googleapis.com
    

    API'yi etkinleştirmek veya kullanmak için belirli Identity and Access Management (IAM) rollerine ihtiyacınız yoktur.

  2. gcloud services list komutunu çalıştırarak API'nin projeniz için etkinleştirildiğini doğrulayın:

    gcloud services list --enabled \
        --filter="name:developerknowledge.googleapis.com"
    

    Çıkışta API adı ve başlığı listelenir:

    NAME                                     TITLE
    developerknowledge.googleapis.com  Developer Knowledge API
    

Belgelerden yanıt oluşturma

gcloud developer-knowledge answer-query komutu, Google ürünleri hakkında soru sormanıza ve doğrudan, doğal dilde yanıtlar almanıza olanak tanır. Komut, resmi doküman kaynaklarından bilgi alır ve referans verilen sayfalara alıntılar ekler.

Soru sormak ve yanıt oluşturmak için aşağıdaki adımları uygulayın:

  1. Cloud Storage paketi oluşturma hakkında soru sormak için aşağıdaki komutu çalıştırın:

    gcloud developer-knowledge answer-query \
        --query="How do I create a Cloud Storage bucket?"
    
  2. Komutun, YAML biçiminde oluşturulmuş bir yanıt ve kaynak referansları döndürdüğünü doğrulayın:

    answer:
      answerText: |-
        To create a Cloud Storage bucket, you can use the Google Cloud console,
        the gcloud CLI (`gcloud storage buckets create`), client libraries, or
        the REST API...
      citations:
      - endIndex: 158
        sources:
        - referenceIndex: 0
        startIndex: 0
      references:
      - documentReference:
          documentChunk:
            content: |-
              This document shows you how to create a Cloud Storage
              [bucket](https://docs.cloud.google.com/storage/docs/buckets)...
            document:
              dataSource: docs.cloud.google.com
              name: documents/docs.cloud.google.com/storage/docs/creating-buckets
              title: Create a bucket
              uri: https://docs.cloud.google.com/storage/docs/creating-buckets
            parent: documents/docs.cloud.google.com/storage/docs/creating-buckets
    

    Çıkıştaki answer nesnesi aşağıdaki alanları içerir:

    • answerText: Sorgunuza doğal dilde oluşturulan yanıt.
    • citations: answerText içinde, referenceIndex ile references içindeki destekleyici girişlerle eşlenen bayt ofset aralıkları (startIndex ve endIndex).
    • references: Yanıtı oluşturmak için kullanılan kaynak doküman parçaları ve meta veriler (document ve parent dahil).

Doküman parçalarını arama

Google'ın geliştirici belgelerinde, üretilen bir yanıt yerine belirli metin alıntılarını bulmak için gcloud developer-knowledge documents search-chunks komutunu kullanın. Bu komut, doküman kümesini tarar ve eşleştirilen içerik parçalarını, üst dokümanlarının kaynak adlarıyla birlikte döndürür.

Doküman parçalarını aramak için aşağıdaki adımları uygulayın:

  1. Cloud Storage paketi oluşturmayla ilgili dokümanları aramak için aşağıdaki komutu çalıştırın:

    gcloud developer-knowledge documents search-chunks \
        --query="How do I create a Cloud Storage bucket?"
    
  2. Komutun, eşleşen doküman parçalarının listesini YAML biçiminde döndürdüğünü doğrulayın:

    ---
    content: |-
      This document shows you how to create a Cloud Storage
      [bucket](https://docs.cloud.google.com/storage/docs/buckets). If not otherwise
      specified in your request, buckets are created in the
      [US multi-region](https://docs.cloud.google.com/storage/docs/locations)...
    document:
      contentLengthBytes: 31842
      dataSource: docs.cloud.google.com
      description: World-wide storage and retrieval of data in Google Cloud.
      name: documents/docs.cloud.google.com/storage/docs/creating-buckets
      title: Create a bucket
      updateTime: '2026-09-10T20:05:41Z'
      uri: https://docs.cloud.google.com/storage/docs/creating-buckets
      view: DOCUMENT_VIEW_BASIC
    id: c1
    parent: documents/docs.cloud.google.com/storage/docs/creating-buckets
    relevanceScore: 0.856608
    

    Çıkıştaki her parça aşağıdaki alanları içerir:

    • content: Dokümantasyondan eşleşen metin snippet'i.
    • document: title, description, uri, dataSource ve updateTime dahil olmak üzere kaynak dokümanla ilgili meta veriler.
    • id: Dokümandaki parçanın tanımlayıcısı.
    • parent: Üst dokümanın kaynak adı. Belgenin tamamını almak için bu değeri describe komutuna iletebilirsiniz.
    • relevanceScore: Parçanın arama sorgusuyla alaka düzeyi puanı.

Belge alma

Alakalı bir doküman parçası bulduktan sonra, dokümanın tam Markdown içeriğini almak için bu arama sonuçlarındaki parent alanını kullanın.

Dokümanın kaynak adıyla gcloud developer-knowledge documents describe komutunu çalıştırın. Örneğin, Cloud Storage paketleri oluşturmayla ilgili dokümanı almak için aşağıdaki adımları uygulayın:

  1. Aşağıdaki komutu çalıştırın:

    gcloud developer-knowledge documents describe \
      documents/docs.cloud.google.com/storage/docs/creating-buckets
    
  2. Komutun, dokümanın meta verilerini ve tam Markdown içeriğini döndürdüğünü doğrulayın:

    content: |
      This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets). If not otherwise specified in your request, buckets are
      created in the [`US` multi-region](https://docs.cloud.google.com/storage/docs/locations)
      with a default storage class of [Standard storage](https://docs.cloud.google.com/storage/docs/storage-classes)
      and have a seven-day [soft delete](https://docs.cloud.google.com/storage/docs/soft-delete)
      retention duration...
    contentLengthBytes: 31842
    dataSource: docs.cloud.google.com
    description: World-wide storage and retrieval of data in Google Cloud.
    name: documents/docs.cloud.google.com/storage/docs/creating-buckets
    title: Create a bucket
    updateTime: '2026-09-10T20:05:41Z'
    uri: https://docs.cloud.google.com/storage/docs/creating-buckets
    view: DOCUMENT_VIEW_CONTENT
    

    Çıkış aşağıdaki alanları içerir:

    • content: Belgenin tam Markdown metni.
    • contentLengthBytes: Belge içeriğinin bayt cinsinden toplam boyutu.
    • dataSource: Dokümanı barındıran doküman alanı.
    • description: Belgenin kısa bir özeti.
    • name: Belgenin benzersiz kaynak adı.
    • title: Dokümanın başlığı.
    • updateTime: Belgenin son güncellendiği zaman damgası.
    • uri: Doküman sayfasının herkese açık URL'si.
    • view: Döndürülen belge görünümü (DOCUMENT_VIEW_CONTENT, DOCUMENT_VIEW_BASIC veya DOCUMENT_VIEW_FULL).

Sırada ne var?