Hello.
In version 1.1.1 this does not work, because AttributeError: module ‘openai’ has no attribute ‘ChatCompletion’.
model_engine = "gpt-3.5-turbo"
def get_response(background_information, input_text):
current_time = datetime.datetime.now()
response = openai.ChatCompletion.create(
model=model_engine,
messages=[
{"role": "system", "content": "Keep your responses relatively short."},
{"role": "system", "content": "You are an AI language model that can understand and remember the information provided to you."},
{"role": "system", "content": "Please pay close attention to the background information in the user message and use it to answer the user's question."},
{"role": "system", "content": "Each line of the input contains a Date and Time. If prompted, use this to determine when a message was inputted. When saying a time, just say the hour and minute."},
{"role": "system", "content": "All time based responses should be given as HH:MM. Do not give the full output time unless requested."},
{"role": "user", "content": "2023-04-01 14:33:25.087262 - User: I've always wanted a pony"},
{"role": "user", "content": "2023-04-01 14:42:00.852956 - User: At what time did I say I have always wanted a pony?"},
{"role": "assistant", "content": "You told me you have always wanted a pony at 2:33 PM"},
{"role": "system", "content": "*ONLY* respond to the most recent question, based on the time at the beginning of the line."},
{"role": "user", "content": "Do not respond with the time the question was asked, unless requested."},
{"role": "user", "content": "When responding to a question, do not repeat it back. Just answer it."},
{"role": "user", "content": "Only respond to the most recent question"},
{"role": "user", "content": background_information + "\n" + input_text + str(current_time)}]
)
return response['choices'][0]['message']['content'].strip()
However this works.
client = OpenAI(
# defaults to os.environ.get("OPENAI_API_KEY")
api_key="key here",
)
# Function to speak the output
def speak(text):
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="onyx",
input=text,
)
response.stream_to_file(speech_file_path)
# Play the speech file using an appropriate media player library or command
# Example using pygame (you'll need to install pygame library first)
pygame.mixer.init()
pygame.mixer.music.load(speech_file_path)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy(): # Wait for the playback to finish
pygame.time.Clock().tick(10)
That being said, if I downgrade to a version where ChatCompletions endpoint is available, TTS does not function. How can I call ChatCompletions on the most recent version? (1.1.1)