Gunakan metode AnswerQuery untuk mendapatkan jawaban atas kueri yang didasarkan pada
korpus Pengetahuan Developer.
Sebelum memulai
Pastikan Anda telah mengaktifkan API dan membuat kunci API Developer Knowledge, serta menyimpan kunci Anda ke variabel lingkungan:
export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"
Contoh penggunaan
Contoh berikut menanyakan "Bagaimana cara membuat set data 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?"}'
Respons berisi jawaban teks di kolom answer.answer_text, beserta citations dan references dalam objek 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"
}
}
}
}
]
}
}