在Dialogflow V2 API中的EventInput中设置参数 [英] set parameters in EventInput in Dialogflow V2 API
问题描述
我拼命尝试在
dialogflow.types.EventInput
在python中。
此
/ EventInput
这是我的操作方式:
从google.protobuf导入对话流
导入struct_pb2
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id,session_id)
参数= struct_pb2.Struct()
参数[给定名称] ='Jeff'
parameters [ last-name] ='Bridges'
query_input = {
'event':{
name: greetPerson ,
parameters:参数,
language_code: de
}
}
response = session_client.detect_intent(
session = session,
query_input = query_input)
注意:
在dialogflow控制台中,必须将参数的默认值指定为#even_name.parameter_name
。
在这种情况下,参数给定名称
则为 #greetPe rson.given-name
,对于 lastname
,它将是#greetPerson.last-name
。
文档参考:
我们正在使用 DetectIntent ,我们在其中使用 QueryInput ,最后我们在其中使用 EvenInput
希望它会有所帮助。
I desperatly try to set parameters in a
dialogflow.types.EventInput
in python.
This doc says the parameters need to be of type Struct
.
I read here that the parameters needs to be a google.protobuf.Struct. But it does not work for me.
Is there another Struct
type equivalent in python?
If i send the EventInput
without parameters, the intent is detected correctly.
I tried this so far:
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
parameters = struct_pb2.Struct()
parameters['given-name'] = 'Jeff'
parameters['last-name'] = 'Bridges'
event_input = dialogflow.types.EventInput(
name='greetPerson',
language_code='de',
parameters=parameters)
query_input = dialogflow.types.QueryInput(event=event_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
Anybody having experience with this usecase?
Things i also tried:
Pass a
class
named p yields:Parameter to MergeFrom() must be instance of same class: expected Struct got p. for field EventInput.parameters
Pass a dict:
parameters = { 'given-name': 'Jeff', 'last-name': 'Bridges'}
yields:
Protocol message Struct has no "given-name" field.
Generate Struct with constructor:
from google.protobuf.struct_pb2 import Struct, Value parameters = Struct(fields={ 'given-name':Value(string_value='Jeff'), 'last-name':Value(string_value='Bidges') })
yields sometimes:
Exception in thread ptvsd.stopping (most likely raised during interpreter shutdown):
/EventInput
This is how I did this:
import dialogflow
from google.protobuf import struct_pb2
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
parameters = struct_pb2.Struct()
parameters["given-name"] = 'Jeff'
parameters["last-name"] = 'Bridges'
query_input = {
'event': {
"name": "greetPerson",
"parameters": parameters,
"language_code": "de"
}
}
response = session_client.detect_intent(
session=session,
query_input=query_input)
Note:
In dialogflow console, you must give default values of parameters as #even_name.parameter_name
.
In this case for parameter given-name
it would be #greetPerson.given-name
and for last-name
it would be #greetPerson.last-name
.
Docs Reference:
We are using DetectIntent, in which we are using QueryInput, in which finally we are using EvenInput
Hope it helps.
这篇关于在Dialogflow V2 API中的EventInput中设置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!