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