Comments (9)
how can i delete the current text response and change it to something else??
what should i use instead of .extend?
from python-dialogflow.
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.
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.
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.
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.
@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.
@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.
Hi, this appears to have been answered, but if anyone needs further help here is the docs on BatchUpdateIntentsRequest
from python-dialogflow.
@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)
wheretext
is the string that will be part of the training phrase,entity_type
is a string prefixed with @ that will correspond to the entity, andalias
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)
- Exporting Agent Bytes Then Fails to Import HOT 13
- Migrate to main branch
- samples.snippets.participant_management_test: test_analyze_content_text failed HOT 11
- samples.snippets.participant_management_test: test_analyze_content_text failed HOT 1
- Dependency Dashboard
- samples.snippets.create_document_test: test_create_document failed HOT 5
- samples.snippets.create_knowledge_base_test: test_create_knowledge_base failed HOT 5
- participant_management.py test failed.
- Segmentation fault with multiprocessing HOT 2
- Increase code coverage from 99% to 100% HOT 1
- No DesignTimeAgent found for project `python-docs-samples-*` HOT 2
- AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key' HOT 9
- Resolve sphinx docs warnings and enable warnings as errors HOT 1
- seminar HOT 1
- Warning: a recent release failed
- AttributeError: module 'google.cloud.dialogflow_v2' has no attribute 'Entity' HOT 1
- Add sample code for StreamingAnalyzeContent with audio live transcription HOT 1
- Add Code Snippet for Pulling Session ID from WebhookRequests HOT 1
- AttributeError: 'dict' object has no attribute 'index' HOT 2
- unable to import name "common_pb2" from "google.cloud.dialogflow_v2.types" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-dialogflow.