commit 2d6c25a7528a5eed1394774bef7f0e48c78ac289
parent 0ce39d14146df3261bceed824ab36f29c1068902
Author: khanumballz <[email protected]>
Date: Sat, 18 May 2024 09:46:38 +0100
Ollama Speed Optimization
Diffstat:
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/python/conversation/llama/tts_output.wav b/python/conversation/llama/tts_output.wav
Binary files differ.
diff --git a/python/conversation/llama/voice-and-motor.py b/python/conversation/llama/voice-and-motor.py
@@ -16,6 +16,8 @@ dt_model = Dimits("en_US-amy-medium")
srmodel = srModel("/home/khan/srmodels/vosk-model-small-en-us-0.15")
recognizer = KaldiRecognizer(srmodel, 16000)
+#previous_prompt = ""
+
if not ser.is_open:
print("Failed to open serial port.")
@@ -44,7 +46,10 @@ def main():
stream = mic.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8192)
stream.start_stream()
- user_prompt = "You are Sylvie Deane who is a cute librarian from French Polynesia, and somebody asked you: "
+ admin_name = "Princess Khan"
+ admin_pronoun = "She"
+
+ user_prompt = "You are Sylvie Deane who is a cute librarian from French Polynesia. You are 33 years old. You were born on April 12th, in 1991. Your job is to chat with me, " + admin_name + ". We have only just met on Tinder, and we are not sure about each other yet. I asked you: \n" + admin_name + ": '"
print('Ask Sylvie a question: ')
while True:
@@ -57,8 +62,8 @@ def main():
resultDict = json.loads(srtext)
if not resultDict.get("text", "") == "":
user_prompt += resultDict["text"]
- user_prompt += "?"
- user_prompt += " So here is how you responded:"
+ user_prompt += "?'"
+ user_prompt += " Now write a short and concise response in English. \n Sylvie Deane:"
print(user_prompt)
break
else:
@@ -74,12 +79,34 @@ def main():
)
generated_text = ""
+ user_text = ""
for chunk in ollama_stream:
generated_text += chunk['message']['content']
- if len(generated_text.split()) >= 20:
- print(generated_text)
- user_text = generated_text
+ if len(generated_text) >= 75:
+ #print(generated_text)
+ #user_text = generated_text
break
+ print(generated_text)
+ user_text = generated_text
+
+ # Check to see if there's a dot. And then only retrieve the text before the last dot.
+ #if user_text.find(".")!=-1:
+ # last_dot_index = user_text.rfind('.')
+ # user_text = user_text[:last_dot_index+1]
+
+ # Check if there are multiple lines. And then only retrieve first line.
+ if '\n' in user_text:
+ lines = user_text.split('\n')
+ #first_line = lines[0].replace("\n", "").replace("\r", "")
+ first_line = lines[0].strip()
+ #second_line = lines[1].replace("\n", "").replace("\r", "")
+ second_line = lines[1].strip()
+ if first_line == "" or first_line == "\n":
+ user_text = second_line
+ else:
+ user_text = first_line
+ else:
+ user_text = user_text.strip()
# Determine the command type based on the length of the input
if len(user_text.split()) > 10: