mirror of
https://github.com/SevaSk/ecoute.git
synced 2024-12-19 20:57:53 +00:00
"Tell, don't ask" Principle
This commit is contained in:
parent
cee3e7e2df
commit
62bb4bb1af
@ -24,11 +24,23 @@ def generate_response_from_transcript(transcript):
|
||||
except:
|
||||
return ''
|
||||
|
||||
def generate_response_from_transcript_revChatGPT(transcript):
|
||||
try:
|
||||
response = ''
|
||||
for data in chatbot.ask(
|
||||
create_prompt(transcript)
|
||||
):
|
||||
response = data["message"]
|
||||
return response
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return ''
|
||||
|
||||
class GPTResponder:
|
||||
def __init__(self, revChatGPT):
|
||||
def __init__(self, revChatGPT=False):
|
||||
self.response = INITIAL_RESPONSE
|
||||
self.response_interval = 2
|
||||
self.revChatGPT = revChatGPT
|
||||
self.respond_to_transcriber = self.respond_to_transcriber_revChatGPT if revChatGPT else self.respond_to_transcriber
|
||||
|
||||
def respond_to_transcriber(self, transcriber):
|
||||
while True:
|
||||
@ -37,13 +49,28 @@ class GPTResponder:
|
||||
|
||||
transcriber.transcript_changed_event.clear()
|
||||
transcript_string = transcriber.get_transcript()
|
||||
if self.revChatGPT:
|
||||
for data in chatbot.ask(
|
||||
create_prompt(transcript_string)
|
||||
):
|
||||
response = data["message"]
|
||||
else:
|
||||
response = generate_response_from_transcript(transcript_string)
|
||||
response = generate_response_from_transcript(transcript_string)
|
||||
|
||||
end_time = time.time() # Measure end time
|
||||
execution_time = end_time - start_time # Calculate the time it took to execute the function
|
||||
|
||||
if response != '':
|
||||
self.response = response
|
||||
|
||||
remaining_time = self.response_interval - execution_time
|
||||
if remaining_time > 0:
|
||||
time.sleep(remaining_time)
|
||||
else:
|
||||
time.sleep(0.3)
|
||||
|
||||
def respond_to_transcriber_revChatGPT(self, transcriber):
|
||||
while True:
|
||||
if transcriber.transcript_changed_event.is_set():
|
||||
start_time = time.time()
|
||||
|
||||
transcriber.transcript_changed_event.clear()
|
||||
transcript_string = transcriber.get_transcript()
|
||||
response = generate_response_from_transcript_revChatGPT(transcript_string)
|
||||
|
||||
end_time = time.time() # Measure end time
|
||||
execution_time = end_time - start_time # Calculate the time it took to execute the function
|
||||
|
2
main.py
2
main.py
@ -92,7 +92,7 @@ def main():
|
||||
transcribe.daemon = True
|
||||
transcribe.start()
|
||||
|
||||
responder = GPTResponder(revChatGPT=True) if '--revChatGPT' in sys.argv else GPTResponder(revChatGPT=False)
|
||||
responder = GPTResponder(revChatGPT=True) if '--revChatGPT' in sys.argv else GPTResponder()
|
||||
respond = threading.Thread(target=responder.respond_to_transcriber, args=(transcriber,))
|
||||
respond.daemon = True
|
||||
respond.start()
|
||||
|
Loading…
Reference in New Issue
Block a user