Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

python - set parameters in EventInput in Dialogflow V2 API

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:

  1. Pass a class named p yields:

    Parameter to MergeFrom() must be instance of same class: expected Struct got p. for field EventInput.parameters

  2. Pass a dict:

    parameters = {
        'given-name': 'Jeff',
        'last-name': 'Bridges'} 
    

    yields:

    Protocol message Struct has no "given-name" field.

  3. 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):

This is the parameter section if my intent

/EventInput

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...