googleapis/python-dialogflow-cx

Intent.training_phrases appears to not be a sequence although it should be

peturssonstefan-ikea opened this issue · 0 comments

Hi!

I'm trying to create intents through the API https://googleapis.dev/python/dialogflow-cx/latest/dialogflowcx_v3/services.html

I'm experiencing a problem when creating the training_phrases. The type of training_phrases is clearly stated to be a sequence of Sequence[google.cloud.dialogflowcx_v3.types.Intent.TrainingPhrase], but when I add a sequence (a list) of dialogflowcx_v3.types.Intent.TrainingPhrase I get back the error

TypeError: Parameter to MergeFrom() must be instance of same class: expected google.cloud.dialogflow.cx.v3.Intent.TrainingPhrase got list.

Even thought it clearly states from the docs that this should be a Sequence[...dialogflow.cx.v3.Intent.TrainingPhrase]

The code used to generate the error:

from google.cloud import dialogflowcx_v3

def getTrainingPhrase(training_phrases):
    phrases = []
    for phrase in training_phrases:
        trainingPhrase = dialogflowcx_v3.Intent.TrainingPhrase()
        part = dialogflowcx_v3.Intent.TrainingPhrase.Part()
        part.text = phrase
        trainingPhrase.parts = [part]
        trainingPhrase.repeat_count = 1
        phrases.append(trainingPhrase)
    
    return phrases

def createIntentObject(intentWord, training_phrases):
    intent = dialogflowcx_v3.Intent()
    intent.display_name = intentWord+"-intent" 
    intent.training_phrases = getTrainingPhrase(training_phrases),
    intent.description = "This is a test intent for " + intentWord
    return intent

createIntentObject("some-intent",["some","training", "phrases"])

Environment details

  • OS type and version: Ubuntu 20.04.4 LTS
  • Python version: 3.8.10
  • pip version: 20.0.2
  • google-cloud-dialogflow-cx version: 1.12.1

Steps to reproduce

  1. Run code snippet above

Stack trace

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [102], in <cell line: 213>()
    211 newIntents = readNewIntents()
    213 for intentWord, training_phrases in newIntents.items(): 
--> 214     intent = await sample_create_intent(agent, intentWord, training_phrases)
    215     page = await sample_create_page(flow, intentWord)
    216     transRoute = getTransitionRoutes(intent.name, page.name, intentWord)

Input In [102], in sample_create_intent(parent, intentword, training_phrases)
     55 async def sample_create_intent(parent, intentword, training_phrases):
     56     # Create a client
     57     client = dialogflowcx_v3.IntentsAsyncClient()
---> 58     intent = createIntentObject(intentword, training_phrases)
     59     # Initialize request argument(s)
     60 #    intent = dialogflowcx_v3.Intent()
     61 #    intent.display_name = "test intent"
     63     request = dialogflowcx_v3.CreateIntentRequest(
     64         parent=parent,
     65         intent=intent,
     66     )

Input In [102], in createIntentObject(intentWord, training_phrases)
     48 intent = dialogflowcx_v3.Intent()
     49 intent.display_name = intentWord+"-intent" 
---> 50 intent.training_phrases = getTrainingPhrase(training_phrases),
     51 intent.description = "This is a test intent for " + intentWord
     52 return intent

File ~/.local/lib/python3.8/site-packages/proto/message.py:643, in Message.__setattr__(self, key, value)
    641 # Merge in the value being set.
    642 if pb_value is not None:
--> 643     self._pb.MergeFrom(self._meta.pb(**{key: pb_value}))

TypeError: Parameter to MergeFrom() must be instance of same class: expected google.cloud.dialogflow.cx.v3.Intent.TrainingPhrase got list.

Thanks!