استخدِم طريقة AnswerQuery للحصول على إجابات عن طلبات البحث المستندة إلى مجموعة مستندات Developer Knowledge.
قبل البدء
تأكَّد من أنّك فعّلت واجهة برمجة التطبيقات وأنشأت مفتاحًا لواجهة برمجة التطبيقات 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، بالإضافة إلى 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"
}
}
}
}
]
}
}