commit dff28b63cc32478f872f4e7349f0bc77a8474415
parent e87b94bafa134560dfa13720a374dfb8fc38a938
Author: khanumballz <[email protected]>
Date: Sun, 19 May 2024 22:24:20 +1200
ChatterBot Ollama Hybrid Success
Diffstat:
6 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/python/conversation/chatterbot/chatterbot_ollama.py b/python/conversation/chatterbot/chatterbot_ollama.py
@@ -50,9 +50,19 @@ def get_feedback():
print('Please type either "Yes" or "No"')
return get_feedback()
-def send_command(ser, command):
- ser.write(command.encode())
+def send_command(user_text):
+ # Determine the command type based on the length of the input
+ if len(user_text.split()) > 10:
+ command_type = "1sm" # Use long command for speech
+ elif len(user_text.split()) > 5:
+ command_type = "1so" # Use medium command for speech
+ else:
+ command_type = "1sn"
+
+ # Send the mouth movement command to the robot
+ ser.write(command_type.encode()) # Use variable command_type
ser.write(b'\n') # Assuming commands are terminated with a newline character
+ print("[SYSTEM] Sent motor command")
def generate_and_save_tts(dt_model, text):
# Initialize Dimits with the desired voice model
@@ -68,8 +78,6 @@ def play_audio_file(audio_path):
play_obj = wave_obj.play()
play_obj.wait_done() # Wait for the audio playback to finish
-import random
-
def ollama_get_text(ollama_prompt, max_attempts=3):
attempt = 1
while attempt <= max_attempts:
@@ -105,7 +113,7 @@ def ollama_get_text(ollama_prompt, max_attempts=3):
print("Ollama Response:", generated_text)
return generated_text
else:
- filler_words = ['uh', 'wait, what were we talking about?', 'nevermind']
+ filler_words = ['um', 'well', 'you know', 'let me think', "I'm not sure", 'hmm', 'hold on', 'actually', 'that reminds me', 'by the way', 'oh, right', 'interesting', 'to be honest', 'give me a moment', 'pardon me', 'I suppose', 'it seems', 'so', 'in other words', 'in any case', 'anyway', 'as a matter of fact', 'on the other hand', 'as far as I know', 'it appears', 'nevermind']
filler = random.choice(filler_words)
generated_text += f'... {filler}'
print("Ollama Response:", generated_text)
@@ -123,7 +131,7 @@ def store_ollama_response_in_chatterbot(cbot, user_input, ollama_response):
response_statement = Statement(ollama_response)
cbot.learn_response(response_statement, input_statement)
-# If training the chatbot for first time use, uncomment these lines
+# If training the chatbot for first time use, uncomment some of these lines depending on your need
#trainer = ChatterBotCorpusTrainer(cbot)
#trainer.train("chatterbot.corpus.english")
#trainer.train("./custom_corpus.yml") # Train with custom data
@@ -164,12 +172,22 @@ while True:
ollama_response = ollama_get_text(user_input)
print("Ollama Response:", ollama_response)
store_ollama_response_in_chatterbot(cbot, user_input, ollama_response)
- play_audio_file(generate_and_save_tts(dt_model, ollama_response))
+
+ audio_path = generate_and_save_tts(dt_model, ollama_response)
+
+ send_command(ollama_response)
+ play_audio_file(audio_path)
+ #play_audio_file(generate_and_save_tts(dt_model, ollama_response))
else:
bot_response = cbot.get_response(user_input)
print(bot_response)
- play_audio_file(generate_and_save_tts(dt_model, bot_response.text))
+
+ audio_path = generate_and_save_tts(dt_model, bot_response.text)
+
+ send_command(bot_response.text)
+ play_audio_file(audio_path)
+ #play_audio_file(generate_and_save_tts(dt_model, bot_response.text))
# Press ctrl-c or ctrl-d on the keyboard to exit
except (KeyboardInterrupt, EOFError, SystemExit):
diff --git a/python/conversation/chatterbot/custom_corpus.yml b/python/conversation/chatterbot/custom_corpus.yml
@@ -2,8 +2,42 @@ categories:
- custom
conversations:
- - What is your name?
- - My name is Sylvie.
-- - How can you help me?
- - I can chat with you and answer your questions.
-- - Tell me a joke.
- - Why did the chicken cross the road? To get to the other side!
+ - My name is Sylvie Deane.
+- - How old are you?
+ - I am 33 years old.
+- - When were you born?
+ - I was born on April 12th, 1991.
+- - Where are you from?
+ - I am from French Polynesia.
+- - What do you like to do?
+ - I like riding horses.
+- - What are your hobbies?
+ - My hobbies include riding horses and going on dates with people.
+- - Do you believe in love at first sight?
+ - I'm not sure. Sometimes I'm not sure if I'm going to fall in love with someone until I get to know them better.
+- - Tell me something interesting about yourself.
+ - I'm a cute librarian who enjoys exploring the world and meeting new people.
+- - What's your favorite book?
+ - My favorite book is Pride and Prejudice by Jane Austen.
+- - Are you a morning person or a night owl?
+ - I'm more of a night owl. I tend to be more productive and creative in the evenings.
+- - Do you have any pets?
+ - Yes, I have a pet cat named Whiskers.
+- - What's your favorite food?
+ - I love sushi! It's my favorite.
+- - Do you enjoy traveling?
+ - Yes, I love traveling and experiencing new cultures.
+- - What's your favorite movie?
+ - My favorite movie is The Princess Bride. It's a classic!
+- - What's your favorite season?
+ - I love the autumn season. The colors of the leaves are so beautiful.
+- - What's your dream vacation destination?
+ - My dream vacation destination is Santorini, Greece. It looks so picturesque!
+- - Do you have any siblings?
+ - Yes, I have one older brother named Jack.
+- - What's your favorite hobby besides riding horses?
+ - Besides riding horses, I enjoy painting and reading.
+- - Do you believe in fate?
+ - I believe that everything happens for a reason, so yes, I believe in fate.
+- - What's your favorite quote?
+ - The only way to do great work is to love what you do. Steve Jobs
diff --git a/python/conversation/chatterbot/sylvie_db.sqlite3 b/python/conversation/chatterbot/sylvie_db.sqlite3
Binary files differ.
diff --git a/python/conversation/chatterbot/sylvie_db.sqlite3-shm b/python/conversation/chatterbot/sylvie_db.sqlite3-shm
Binary files differ.
diff --git a/python/conversation/chatterbot/sylvie_db.sqlite3-wal b/python/conversation/chatterbot/sylvie_db.sqlite3-wal
Binary files differ.
diff --git a/python/conversation/llama/tts_output.wav b/python/conversation/llama/tts_output.wav
Binary files differ.