Giter Club home page Giter Club logo

Comments (9)

yejindaye avatar yejindaye commented on August 14, 2024 1

how can i delete the current text response and change it to something else??
what should i use instead of .extend?

from python-dialogflow.

AlexSissoko avatar AlexSissoko commented on August 14, 2024

If you look at the type of an intent's training phrases attribute, you'll notice that it's a <google.protobuf.pyext._message.RepeatedCompositeCo>.
As far as I can tell, its list of operations can be found on https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/containers.py.

I'm not sure if this is exactly how you are supposed to do it, but I would first get the intent from the agent, then modify it, and then use it as an argument for update_intent.
The general process is:

client = dialogflow.IntentsClient()
intent = get_intent(project_id), intent_name)
new_training_phrases = [list of new training phrases]
intent.training_phrases.extend(training_phrases)
response = client.update_intent(intent, language_code='en'

get_intent should be a function that I believe you can find in one of the samples
You don't need to input any of the other arguments for update_intent for this to work.
Also, I haven't spent enough time experimenting to see whether or not you can update the intent without copying it over entirely, but it should be relatively simple if you understand the function of the update_mask. Adding message text should be relatively similar

Trying to figure these things out can be pretty infuriating right now since DialogFlow is pretty knew, but the tools are all there so as long as you're patient, you'll figure it out.

from python-dialogflow.

AlexSissoko avatar AlexSissoko commented on August 14, 2024

Sorry if what I said earlier was a bit murky.
This piece of code should do the trick:

def update_intent(project_id, intent_name, training_phrases):
    client = dialogflow.IntentsClient()
    parent = client.project_agent_path(project_id)
    intents = client.list_intents(parent)
    intent_path = [
        intent.name for intent in intents
        if intent.display_name == intent_name]
    intent = client.get_intent(intent_path[0])
    intent.training_phrases.extend(training_phrases)
    response  = client.update_intent(intent, language_code='en')

from python-dialogflow.

mauropico-dev avatar mauropico-dev commented on August 14, 2024

Hello everyone!
Thanks for that last method. I'm having some issues trying to make it work. This line intent.training_phrases.extend(training_phrases) throws "TypeError: Not a cmessage". Any idea?

I've tried to call the method like this:
update_intent(PROJECT_ID,"1","Test")
update_intent(PROJECT_ID,"1",["Test"])

A print just before that line shows that the intent is correct.
print(intent)
display_name: "1"
priority: 500000
messages {
text {
}
}

Any ideas?
Thanks!

from python-dialogflow.

tigersoldier avatar tigersoldier commented on August 14, 2024

You need to pass intent_view=dialogflow_v2.enums.IntentView.INTENT_VIEW_FULL to get_intent. Otherwise not everything of the intent is returned.

Training phrases should be defined as follows: https://github.com/dialogflow/dialogflow-python-client-v2/blob/cdb21e624bc0e69518296fa6ef1b5f2746cdcadc/samples/intent_management.py#L70-L76

Here is an updated version of update_intent (not tested, may have bugs):

def update_intent(project_id, intent_id, training_phrases_parts):
    client = dialogflow.IntentsClient()
    intent_name = client. intent_path(project_id, intent_id)
    intent = client.get_intent(name, intent_view=dialogflow_v2.enums.IntentView.INTENT_VIEW_FULL)
    training_phrases = []
    for training_phrases_part in training_phrases_parts:
        part = dialogflow.types.Intent.TrainingPhrase.Part(
            text=training_phrases_part)
        training_phrase = dialogflow.types.Intent.TrainingPhrase(parts=[part])
        training_phrases.append(training_phrase)
    intent.training_phrases.extend(training_phrases)
    response  = client.update_intent(intent, language_code='en')

from python-dialogflow.

progresivoJS avatar progresivoJS commented on August 14, 2024

@tigersoldier
Hi, you update_intent code work well, but there is a problem where entities in training phrase are not recognized. It's recognized just text.
So, when detecting text query, It detect intent(because we add training phrase), but cannot detect entities which the text includes.

In shorts, How to specify the entities in training phrase?

from python-dialogflow.

AlexSissoko avatar AlexSissoko commented on August 14, 2024

@progresivoJS
Each Part in the training phrase is not just text but also the labels that go with it (i.e. the Entity and Parameter that it corresponds to). You have to specify that when you make the training phrase part. So, dialogflow.Types.Intent.TrainingPhrase.Part(text=text, entity_type=entity_type, alias=alias) where text is the string that will be part of the training phrase, entity_type is a string prefixed with @ that will correspond to the entity, and alias is a string that corresponds to the parameter name.
Also, since this is not specifically about updating an intent and more about creating training phrases, you really should have made a new issue so that others can find your question. The current issue should have been closed with @tigersoldier's answer.

from python-dialogflow.

nnegrey avatar nnegrey commented on August 14, 2024

Hi, this appears to have been answered, but if anyone needs further help here is the docs on BatchUpdateIntentsRequest

from python-dialogflow.

ramachandraiah-putta avatar ramachandraiah-putta commented on August 14, 2024

@progresivoJS
Each Part in the training phrase is not just text but also the labels that go with it (i.e. the Entity and Parameter that it corresponds to). You have to specify that when you make the training phrase part. So, dialogflow.Types.Intent.TrainingPhrase.Part(text=text, entity_type=entity_type, alias=alias) where text is the string that will be part of the training phrase, entity_type is a string prefixed with @ that will correspond to the entity, and alias is a string that corresponds to the parameter name.
Also, since this is not specifically about updating an intent and more about creating training phrases, you really should have made a new issue so that others can find your question. The current issue should have been closed with @tigersoldier's answer.

here it is treating entire text as entity, how can i specify specific word in the text as entity.

from python-dialogflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.