我正在从对话框流程API V1迁移到对话框流程API V2。
以下是对话流API v1与对话流API v2的示例
API v1:
headers = {
'Authorization': 'Bearer {}'.format('my_token'),
'Content-Type': 'application/json; charset=utf-8'
}
params = {
'query': "I want an audi at Hotel",
'entities': [
{
'name': 'car_type',
'entries': [
{
'value': 100,
'synonyms': [
'audi'
]
},
{
'value': 200,
'synonyms': [
'lamborghini'
]
},
{
'value': 300,
'synonyms': [
'ferrari'
]
}
]
}
],
'v': '20150910',
'lang': 'en',
'sessionId': '123'
}
res = requests.request('post', 'https://api.api.ai/v1/query', headers=headers, data=json.dumps(params))
res = res.json()
响应:: res ['result'] ['parameters']:
{'car_type':'100'}
API v2:
import dialogflow_v2
from google.oauth2 import service_account
session_id = '123'
credentials = service_account.Credentials.from_service_account_file("/home/my_credential.json")
session_client = dialogflow_v2.SessionsClient(credentials=credentials)
session = session_client.session_path(credentials.project_id, session_id)
textInput = dialogflow_v2.types.TextInput(text='I want an audi at Hotel', language_code='EN')
queryInput = dialogflow_v2.types.QueryInput(text=textInput)
response = session_client.detect_intent(session=session, query_input=queryInput)
响应: response.query_result.parameters:
{字段:{ 'key':'car_type', '值':{ 'string_value':'audi' } }}
在API V1中:我可以传递条目,因此我可以获取该项目的值作为响应。
在API V2中:我不知道如何像API V1那样传递条目。
API V2不再支持条目吗?