Temellendirilmiş üretimle sorguları yanıtlama

Geliştirici Bilgisi derlemesine dayalı sorgulara yanıt almak için AnswerQuery yöntemini kullanın.

Başlamadan önce

API'yi etkinleştirdiğinizden ve bir Developer Knowledge API anahtarı oluşturduğunuzdan emin olun. Ardından anahtarınızı bir ortam değişkenine kaydedin:

export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"

Örnek kullanım

Aşağıdaki örnekte "BigQuery veri kümesini nasıl oluştururum?" sorusu soruluyor:

curl -X POST "https://developerknowledge.googleapis.com/v1alpha:answerQuery?key=$DEVELOPERKNOWLEDGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "How do I create a BigQuery dataset?"}'

Yanıtta, answer.answer_text alanında metin yanıtı, answer nesnesinde citations ve references ile birlikte yer alıyor:

{
  "answer": {
    "answerText": "To create a BigQuery dataset, you can use the Google Cloud Console, the bq command-line tool, or the BigQuery client libraries.",
    "citations": [
      {
        "startIndex": 0,
        "endIndex": 123,
        "sources": [
          {
            "referenceIndex": 0
          }
        ]
      }
    ],
    "references": [
      {
        "documentReference": {
          "documentChunk": {
            "parent": "documents/cloud.google.com/bigquery/docs/datasets",
            "content": "This page explains how to create BigQuery datasets...",
            "document": {
              "name": "documents/cloud.google.com/bigquery/docs/datasets",
              "title": "Introduction to datasets",
              "uri": "https://cloud.google.com/bigquery/docs/datasets"
            }
          }
        }
      }
    ]
  }
}