डेवलपर नॉलेज कॉर्पस पर आधारित क्वेरी के जवाब पाने के लिए, AnswerQuery तरीके का इस्तेमाल करें.
शुरू करने से पहले
पक्का करें कि आपने एपीआई चालू किया हो और डेवलपर नॉलेज एपीआई पासकोड जनरेट किया हो, साथ ही, अपने पासकोड को एनवायरमेंट वैरिएबल में सेव करें:
export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"
इस्तेमाल से जुड़ा उदाहरण
यहां दिए गए उदाहरण में, यह सवाल पूछा गया है: "मैं BigQuery डेटासेट कैसे बनाऊं?":
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?"}'
रिस्पॉन्स में, answer.answer_text फ़ील्ड में टेक्स्ट के तौर पर जवाब शामिल होता है. इसके अलावा, citations और references भी answer ऑब्जेक्ट में शामिल होते हैं:
{
"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"
}
}
}
}
]
}
}