भरोसेमंद सोर्स से मिली जानकारी के आधार पर जवाब जनरेट करना

डेवलपर के नॉलेज कॉर्पस में मौजूद जानकारी के आधार पर जवाब पाने के लिए, AnswerQuery तरीके का इस्तेमाल करें.

शुरू करने से पहले

पक्का करें कि आपने एपीआई चालू किया हो और Developer Knowledge API का पासकोड जनरेट किया हो. साथ ही, अपने पासकोड को एनवायरमेंट वैरिएबल में सेव करें:

export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"

इस्तेमाल से जुड़ा उदाहरण

यहां दिए गए उदाहरण में पूछा गया है कि "मैं BigQuery डेटासेट कैसे बनाऊं?":

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

जवाब में, answer.answer_text फ़ील्ड में टेक्स्ट वाला जवाब शामिल होता है. साथ ही, answer ऑब्जेक्ट में citations और references शामिल होते हैं:

{
  "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"
            }
          }
        }
      }
    ]
  }
}