mirror of
https://github.com/SevaSk/ecoute.git
synced 2024-12-24 14:56:39 +00:00
Delete GPTResponder.py
This commit is contained in:
parent
919d56a2c1
commit
3b261acad1
@ -1,51 +0,0 @@
|
|||||||
import openai
|
|
||||||
from keys import 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
|
|
||||||
from prompts import create_prompt, INITIAL_RESPONSE
|
|
||||||
import time
|
|
||||||
|
|
||||||
openai.api_key = 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
|
|
||||||
|
|
||||||
def generate_response_from_transcript(transcript):
|
|
||||||
try:
|
|
||||||
response = openai.ChatCompletion.create(
|
|
||||||
model="gpt-3.5-turbo-0301",
|
|
||||||
messages=[{"role": "system", "content": create_prompt(transcript)}],
|
|
||||||
temperature = 0.0
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
return ''
|
|
||||||
full_response = response.choices[0].message.content
|
|
||||||
try:
|
|
||||||
return full_response.split('[')[1].split(']')[0]
|
|
||||||
except:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
class GPTResponder:
|
|
||||||
def __init__(self):
|
|
||||||
self.response = INITIAL_RESPONSE
|
|
||||||
self.response_interval = 2
|
|
||||||
|
|
||||||
def respond_to_transcriber(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(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 update_response_interval(self, interval):
|
|
||||||
self.response_interval = interval
|
|
Loading…
Reference in New Issue
Block a user