Unable to make a bot do different action - rasa-nlu

I did this bot with starter-pack-rasa-stack which is able to make two kind of actions through get methods : jokes and booking rooms. If I am able to make him tell me jokes I have issues at making him register a reservations. That is to say it is able to call for the ActionJoke class in actions.py but not for ActionBookRoom class.
Indeed, even if every story call for action_room when provided all details like one can see in this one:
## Generated Story 7889435598882720442
* greet
- utter_greet
* book_room
- utter_ask_room
* book_room{"name_room": "blue"}
- slot{"name_room": "blue"}
- utter_ask_day
* book_room{"day": "tomorrow"}
- slot{"day": "tomorrow"}
- utter_ask_hour_start
* book_room{"hour_start": "10h"}
- slot{"hour_start": "10h"}
- utter_ask_duration
* book_room{"duration": "30 min"}
- slot{"duration": "30 min"}
- action_room
* goodbye
- utter_goodbye
- export
Yet it goes straight to goodbye and I don't know how I can retrain the model or train it online to make him take into account this new action.
So how can I make the bot doing this new action?

You should add the new stories to training stories file and retrain the model by running the train script again (e.g. make train-core)

Related

The model is unable to predict the proper action

I added the story,
story: interactive_story_1
steps:
intent: call
entities:
person: son
slot_was_set:
person: son
action: action_call
and when i am running this on rasa interactive, it identifies the intent correctly, sets the slot properly but it predicts action_default_fallback with 0.3 probability and asks to run that instead of action_call which is clearly mentioned in the story!
Ok, I solved it, there was a problem with my rasa core configuration, it was not trained properly so all the action predictions by the dialogue management model was faulty.

How to get only Tweet (only posts) from the timeline?

Whenever tweet is created, it's activity is added to getStream production app.
class Tweet(models.Model, Activity):
user = models.ForeignKey()
text = models.CharField()
class Follow(models.Model, Activity): <- This is adding new activity to the timeline
def follow_feed_lisnner(~)
signal.post_save.connect(~)
class Like(models.Model, Activity): <- Like is adding to activity so timeline automatically shows who liked this post,
My Expectation:
Feed: only shows Tweet on timeline (I don't want to see who started to follow me, or liked any post) - Just Like Instagram!
Notification: Who started to follow me, Who liked my post, Who commented on my post.
views.py
feeds = feed_manager.get_news_feeds(request.user.id)
# get the newsfeed for user.
activities = feeds.get('timeline').get()['results']
activities = enricher.enrich_activities(activities)
Possible Solutions
Use python-stream (more low level) to deal with this problem. (I don't know if it helps)
Maybe I'm missing a cool feature of stream-django
How can we get only Tweet (Not Like, Follow or other activities which should be in notification) on the timeline?
Thank you
UPDATE
If I understood correctly, this should work. Is this valid?
class Follow(models.Model, Activity):
follower =
following
#property
def activity_author_feed(self):
return 'notification'
Activity 1: user A follows user B.
Activity 1 goes to 'user' feed + 'notification' feed (not timeline feed)
//notification feed name already exists so I don't need to create follow feed group
Activity 2: user B creates Post
Activity 2 goes to 'user' feed + 'timeline' feed
Note: I'm assuming your Follow and Like models have a "user" field. If not, best update the question with the full Model classes and also confirm if you're setting up any other following relationships.
The stream-django integration provides an 'Activity' model Mixin and the FeedManager model Manager. They work together to add activities to a Feed Group and Feed whose unique "feed id" is derived from the Model instance.
By default, the feed id is determined by the application wide settings.USER_FEED setting. That should work well for your Tweet model but is probably not what you want for the Follow and Like models. The activities associated with those models ideally belong in separate feeds. This can be setup by overriding the Activity.activity_author_feed property function.
class Follow(models.Model, Activity):
# snipping fields
#property
def activity_author_feed(self):
return 'Follow' # Must match a Feed Group defined in the Stream dashboard
#property
def activity_actor_attr(self):
return self.author
To have to those activities copied into the notification feed, implement the Activity.activity_notify() function to return a list of target feeds.
#property
def activity_notify(self):
return [feed_manager.get_notification_feed(self.user.id)]

Rasa-core, Slots not getting Populated

I am trying to create simple printer support chat bot using rasa-core via nlu interpreter, bot should get the printer model, and printer type and post a issue.
I have used the printermodel and printertype variable in slot and entity, but the slots are not getting populated from the chat string.
Please help me on this.
Not very much information to go off of, but here are several things I would check if my slots weren't being filled correctly:
Is NLU parsing the entities correctly? Slots are usually filled from NLU entities. Send your text direct to the NLU and see if the entities are found.
Entity and Slot names are not consistent? The default method of filling slots without custom programming expects the slot name to match the entity name.
Are the slots defined correctly in the domain information?
If you're still having trouble I encourage you to create an issue or join us on gitter.
For example, we have to design simple conversation
User: I am Shivam
Bot: Hello Shivam
Here, we have to extract name and respond using it.
Step 1: In nlu.md file
## intent:told_name
- i am [shivam](name)
- my name is [shivam](name)
- hi, i am [shivam](name)
Step 2 In domain.yml file
intents:
- told_name
actions:
- utter_greet
entities:
- name
slots:
name:
type: text
templates:
utter_greet:
- text: "Hello {name}"
- text: "Hello {name}, happy to meet you."
Step 3 In stories.md file
# story_01
* told_name{"name": "Mayank"}
- utter_greet
I think, you are missing someting in step 3

Is there an easy way to generate sample FHIR resources?

Without using commercial tools, is there an easy way to generate sample FHIR resources?
I'm working an a project to store FHIR messages to Elasticsearch, and I need a tool to generate FHIR sample messages in real-time to ship over TCP/IP.
Did some digging and here is what I've found.
If you do not need a lot of samples, the easiest way is to grab a zip file with resource examples from hl7 website
http://hl7.org/fhir/downloads.html
IMHO the easiest way I've found to get more than a few samples is by using Synthea project. You can generate millions of records of synthetic realistic data
https://github.com/synthetichealth/synthea
They even run a public server. Here is an example to get a bundle with 100 patients - very neat!
https://syntheticmass.mitre.org/fhir/Patient?_offset=0&_count=100
You can also find examples of bulk FHIR API implementations - some of them have demo web sites you can use to download examples:
https://github.com/smart-on-fhir/fhir-bulk-data-docs/blob/master/implementations.md
Another generator in Python from SMART on FHIR project (looks outdated):
https://github.com/smart-on-fhir/sample-patients.
The only way I know to do this is to use a service provided by test.fhir.org. You call
http://test.fhir.org/r3/StructureDefinition/[resource]/$generate-template
e.g.
http://test.fhir.org/r3/StructureDefinition/Patient/$generate-template
An easy way to generate example resources (in 2022) is to use FHIR Shorthand (FSH). Here's a copy of the example on FSH School from which you easily create the JSON.
Link: https://fshschool.org/FSHOnline/#/share/3LH920m
Instance: PatientExample
InstanceOf: Patient
Description: "Example of Patient"
* name.family = "Anyperson"
* name.given[0] = "John"
* name.given[1] = "B."
// The first element [0] can also be represented as [+] if it is not preceded by any hard index
* contact.telecom[+].system = #phone
* contact.telecom[=].value = "555-555-5555"
* contact.telecom[=].use = #home
* gender = #male
* birthDate = "1951-01-20"
* address.line = "123 Main St"
* address.city = "Anytown"
* address.postalCode = "12345"
* address.country = "US"
Have a try at https://fshschool.org/
A bonus is that you can reverse JSON into FSH as well. And, templating is easy enough use in FSH (though it's not built-in.). For a worked example see https://github.com/intrahealth/bulk-fsh

Compare new field value with old before save

I am building a Ruby Sinatra app with Datamapper as the ORM. I have come across a point that I can't find a decent solution and thought to hit StackOverflow for a solution.
I am needing to compare the old value of a filed with the new value entered by the user to do a small computation.
For example
car = Listing.all(type: :car).first
car.price # 200
car.price = 100
car.save # ~> discount = ( 200 - 100 / 200 ) * 100 ~= 50% - alert watchers
How can I find the old value within the modal?
I have an idea to abstract all modals with custom classes. This will make such operation possible. But wonder if it will add complexity unnecessarily.
Thanks in advance.
You can pull out the old value via model.original_attributes. Something like this should work for your case:
car = Listing.all(type: :car).first
car.price = 100
old_price = car.original_attributes[Listing.properties[:price]] # => 200
You should be able to put that in a before save hook and run your calculations and notifications from there.
HTH :)
(BTW I tested this with DM 1.2.1. I imagine that is the version you are using as well since the DM project is kind of dead-ish these days, but just so you should be aware)

Resources