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 객체에 citations 및 references와 함께 answer.answer_text 필드의 텍스트 답변이 포함됩니다.
{
"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"
}
}
}
}
]
}
}