אפשר להשתמש בשיטה AnswerQuery כדי לקבל תשובות לשאילתות שמבוססות על מאגר הידע למפתחים.
לפני שמתחילים
מוודאים שהפעלתם את ה-API ויצרתם מפתח Developer Knowledge API ושמרתם את המפתח במשתנה סביבה:
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"
}
}
}
}
]
}
}