25 lines
684 B
Python
25 lines
684 B
Python
import os
|
|
import openai
|
|
|
|
def chat(message, openai_key, shortAnswer=True):
|
|
print("###################")
|
|
openai.api_key = openai_key
|
|
if shortAnswer:
|
|
message = message + " - eine kurze Antwort bitte!"
|
|
|
|
print(f"Asking ChatGPT for an answer to: \n {message} \n ...")
|
|
completion = openai.ChatCompletion.create(
|
|
model="gpt-3.5-turbo",
|
|
messages=[
|
|
{"role": "user", "content": message}
|
|
]
|
|
)
|
|
first_answer = completion.choices[0].message.content
|
|
print(f"Got answer from ChatGPT:\n {first_answer}")
|
|
return first_answer
|
|
|
|
if __name__ == "__main__":
|
|
answer = chat("Erzähle mir was über Murnau")
|
|
print(answer)
|
|
|
|
|