From a9b223109c6100258eda8f6275c7be9dd06cb74d Mon Sep 17 00:00:00 2001 From: Guillaume David Date: Tue, 8 Oct 2024 14:46:15 +0200 Subject: [PATCH] Update --- .../__pycache__/actions.cpython-38.pyc | Bin 1231 -> 4676 bytes rasa/actions/actions.py | 157 ++++++++++++++++-- rasa/data/nlu.yml | 128 ++++---------- rasa/data/rules.yml | 26 ++- rasa/data/stories.yml | 54 ++---- rasa/domain.yml | 44 +---- 6 files changed, 213 insertions(+), 196 deletions(-) diff --git a/rasa/actions/__pycache__/actions.cpython-38.pyc b/rasa/actions/__pycache__/actions.cpython-38.pyc index 6b5a89e1468dbf5bd061bfa59a47aaf440f2c768..fb4c7d8305f7865b331583515795333504d0769a 100644 GIT binary patch literal 4676 zcmbuDO>Y~=8OQgPyIj7AlI8fNPP?%iD{5sjuIW-)d7uSqrs}-qcm9 z(?g?UHceHzqA-J*j}>P6`XjwrK)Jvylr34dP_|hS<)SRxC_Ai#a!HnpOkGlD%im%| zWpP%`3JYx!bR&4yQrHzszG%~}y&nyQOSs|_Fup=lYidko+GC}uGo2au#+1-)A*<%y zEyQcrLa*bsRXj5OkWbgoaK-f7R$; z`#f%}Bmo*F9iMp{0c*6bT)ov;y3ks<`S#fc_hPS+_ZE-8>%9k=5qTZorg7=VC~E)E z{(08vew*er{#4-5+mn<12b@$}RfZ~4H`Rf`w1LU=)L_O}+Mv+?tQ{sprKc4`gHP2~gS*Yks7TI840;;_Jq=*JP(&`uqArL=^;;qg#a)*q&} zESH$QslB5N?Dfm3x>`)_p|h#5^5?3mL?@_*RcNFy6;{P}=}YB_k>CAPi7pz7D6cvE z@2WB=t4ja4Y(F6?Y59?gmfE=G1?;Xt`C<8v@+&3M?kFn?USw@CGlYL%Y@fO(L~p*) z2)k`Byw{Dz{MobT&z*00y`Zt;M?Uw2zirExcCLPQOUukom-%5<=<#l+CvKs}SdF_; zR)_`nz0S9P#!_a=wwZ|KGZ!<1bt6BsxgYnsQS5K2oYwqbCt*J1+)ub0c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18HBjd+U14|JQGgf3aSMW4d`X z;Sw|2-hH;eU2>(QXlrbhUd7|8z@8))eGB$gA1|l!sx%okQlrv>v3KJ=+=Peqxd-1J zyxB=zia!D~;#gw=-0ED+ str: + return "action_swiss_zipcode" + + def run(self, dispatcher, tracker, domain): + zipcode = next(tracker.get_latest_entity_values("zipcode"), None) + with open('../logs.txt', 'a') as f: + f.write(zipcode + '\n') + + + if zipcode: + url = f"https://api.zippopotam.us/ch/{zipcode}" + response = requests.get(url) + + if response.status_code == 200: + data = response.json() + places = data.get("places", []) + if places: + place_info = places[0] + city = place_info.get("place name") + state = place_info.get("state") + message = f"Le code postal {zipcode} correspond à {city}, {state}." + else: + message = f"Aucune information trouvée pour le code postal {zipcode}." + else: + message = f"Erreur lors de l'appel à l'API : {response.status_code}." + else: + message = "Je n'ai pas pu extraire le code postal." + + dispatcher.utter_message(text=message) + return [] + +# Action to get the signification of a firstname and 3 famous people known from llama model +class ActionFirstnameSignificationLlama(Action): + def name(self): + return "action_firstname_signification_by_llama" + + def run(self, dispatcher, tracker, domain): + firstname = next(tracker.get_latest_entity_values("firstname"), None) + + with open('../logs.txt', 'a') as f: + f.write(firstname + '\n') + + user_input = "Quelle est la signification du prénom " + firstname + " ? Donne une courte signification. Puis liste 3 personnalités connues portant ce prénom." + + # Call API (Streaming) + url = "http://localhost:11434/api/generate" + payload = { + "model": "llama3.1", + "prompt": user_input + } + + try: + response = requests.post(url, json=payload, stream=True) + + if response.status_code == 200: + llm_response = "" + # Read the response line by line + for line in response.iter_lines(): + if line: + json_line = line.decode('utf-8') + json_data = json.loads(json_line) + + # Done flag for defining the end of the response + if json_data.get("done"): + break + llm_response += json_data.get("response", "") + dispatcher.utter_message(text=llm_response.strip()) + else: + dispatcher.utter_message(text=f"Erreur lors de l'appel à Ollama: {response.status_code} - {response.text}") + except Exception as e: + dispatcher.utter_message(text=f"Une exception est survenue : {str(e)}") + + return [] \ No newline at end of file diff --git a/rasa/data/nlu.yml b/rasa/data/nlu.yml index 53a5262..fb1e8ae 100644 --- a/rasa/data/nlu.yml +++ b/rasa/data/nlu.yml @@ -1,110 +1,40 @@ version: "3.1" nlu: -- intent: greet +- intent: intent_randomuser examples: | - - hey - - hello - - hi - - hello there - - good morning - - good evening - - moin - - hey there - - let's go - - hey dude - - goodmorning - - goodevening - - good afternoon + - Génère moi un profil utilisateur + - Crée un profil d'utilisateur + - Peux-tu me donner un profil utilisateur aléatoire ? + - J'ai besoin d'un profil utilisateur + - Donne-moi un exemple de profil utilisateur + - Fais-moi un profil utilisateur + - Génère un profil utilisateur au hasard + - Crée un utilisateur aléatoire pour moi + - Est-ce que tu peux créer un profil utilisateur ? -- intent: goodbye +- intent: intent_ask_llama examples: | - - cu - - good by - - cee you later - - good night - - bye - - goodbye - - have a nice day - - see you around - - bye bye - - see you later + - Qu'est-ce que tu sais sur les modèles de langage ? + - Comment fonctionne un ordinateur ? + - Quelle est la capitale de la France ? -- intent: affirm +- intent: intent_firstname_signification_by_llama examples: | - - yes - - y - - indeed - - of course - - that sounds good - - correct + - Que signifie mon prénom [Guillaume](firstname) ? + - Peux-tu me dire ce que signifie le prénom [Juliette](firstname) ? + - Quelle est la signification de [Emma](firstname) ? + - Explique-moi la signification du prénom [Lucas](firstname). + - Que veut dire le prénom [Sophie](firstname) ? + - Quelle est l'origine du prénom [Maxime](firstname) ? + - Dis-moi la signification de [Chloé](firstname). + - Que représente le prénom [Thomas](firstname) ? + - Je voudrais savoir ce que signifie le prénom [Camille](firstname). + - Que signifie le prénom [Alice](firstname) ? -- intent: deny +- intent: intent_swiss_zipcode examples: | - - no - - n - - never - - I don't think so - - don't like that - - no way - - not really + - Quel est le code postal en Suisse de ce numéro [1977](zipcode) + - Donne-moi le code postal de [1977](zipcode) + - Quel est le code postal pour [1977](zipcode) ? -- intent: mood_great - examples: | - - perfect - - great - - amazing - - feeling like a king - - wonderful - - I am feeling very good - - I am great - - I am amazing - - I am going to save the world - - super stoked - - extremely good - - so so perfect - - so good - - so perfect - -- intent: mood_unhappy - examples: | - - my day was horrible - - I am sad - - I don't feel very well - - I am disappointed - - super sad - - I'm so sad - - sad - - very sad - - unhappy - - not good - - not very good - - extremly sad - - so saad - - so sad - -- intent: bot_challenge - examples: | - - are you a bot? - - are you a human? - - am I talking to a bot? - - am I talking to a human? - - -- intent: send_email - examples: | - - Envoie-moi un email - - Je veux envoyer un mail - - Peux-tu envoyer un email ? - - Envoie un mail à mon ami - - Pourrais-tu m'envoyer un email ? - - Fais un mail - -- intent: get_weather - examples: | - - Quelle est la météo ? - - Récupère la météo - - Donne-moi la météo - - Quel temps fait-il ? - - Quelle est la météo pour aujourd'hui ? - - Quel temps fait-il à Paris ? \ No newline at end of file diff --git a/rasa/data/rules.yml b/rasa/data/rules.yml index a9987ee..7fa98c7 100644 --- a/rasa/data/rules.yml +++ b/rasa/data/rules.yml @@ -1,13 +1,21 @@ version: "3.1" - rules: + - rule: rule__randomuser + steps: + - intent: intent_randomuser + - action: action_randomuser -- rule: Say goodbye anytime the user says goodbye - steps: - - intent: goodbye - - action: utter_goodbye + - rule: rule_swiss_zipcode + steps: + - intent: intent_swiss_zipcode + - action: action_swiss_zipcode -- rule: Say 'I am a bot' anytime the user challenges - steps: - - intent: bot_challenge - - action: utter_iamabot + - rule: rule_firstname_signification_by_llama + steps: + - intent: intent_firstname_signification_by_llama + - action: action_firstname_signification_by_llama + + - rule: General question redirect to LLM + steps: + - intent: intent_ask_llama + - action: action_ask_llama \ No newline at end of file diff --git a/rasa/data/stories.yml b/rasa/data/stories.yml index 45b72db..b3a7a32 100644 --- a/rasa/data/stories.yml +++ b/rasa/data/stories.yml @@ -1,43 +1,21 @@ version: "3.1" - stories: + - story: request_randomuser + steps: + - intent: intent_randomuser + - action: action_randomuser -- story: happy path - steps: - - intent: greet - - action: utter_greet - - intent: mood_great - - action: utter_happy - -- story: sad path 1 - steps: - - intent: greet - - action: utter_greet - - intent: mood_unhappy - - action: utter_cheer_up - - action: utter_did_that_help - - intent: affirm - - action: utter_happy - -- story: sad path 2 - steps: - - intent: greet - - action: utter_greet - - intent: mood_unhappy - - action: utter_cheer_up - - action: utter_did_that_help - - intent: deny - - action: utter_goodbye - - -- story: Envoie un email - steps: - - intent: send_email - - action: action_send_email - -- story: Récupère la météo - steps: - - intent: get_weather - - action: action_get_weather + - story: request_ask_llama + steps: + - intent: intent_ask_llama + - action: action_ask_llama + - story: request_firstname_signification_by_llama + steps: + - intent: intent_firstname_signification_by_llama + - action: action_firstname_signification_by_llama + - story: request_swiss_zipcode + steps: + - intent: intent_swiss_zipcode + - action: action_swiss_zipcode diff --git a/rasa/domain.yml b/rasa/domain.yml index 636af27..cc84cb2 100644 --- a/rasa/domain.yml +++ b/rasa/domain.yml @@ -1,41 +1,13 @@ version: "3.1" intents: - - greet - - goodbye - - affirm - - deny - - mood_great - - mood_unhappy - - bot_challenge - - send_email - - get_weather + - intent_randomuser + - intent_ask_llama + - intent_swiss_zipcode + - intent_firstname_signification_by_llama actions: - - action_send_email - - action_get_weather - -responses: - utter_greet: - - text: "Salut ! Comment puis-je t'aider aujourd'hui ?" - - utter_cheer_up: - - text: "Here is something to cheer you up:" - image: "https://i.imgur.com/nGF1K8f.jpg" - - utter_did_that_help: - - text: "Did that help you?" - - utter_happy: - - text: "Great, carry on!" - - utter_goodbye: - - text: "Bye" - - utter_iamabot: - - text: "I am a bot, powered by Rasa." - -session_config: - session_expiration_time: 60 - carry_over_slots_to_new_session: true - + - action_randomuser + - action_ask_llama + - action_swiss_zipcode + - action_firstname_signification_by_llama \ No newline at end of file