Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (48 loc) · 1.75 KB
/
Copy pathmain.py
File metadata and controls
60 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from openai import OpenAI
from dotenv import load_dotenv, find_dotenv
import prompts
import random
import os
# Load environment variables
_ = load_dotenv(find_dotenv())
# Initialize OpenAI client
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# Model config
model = "gpt-3.5-turbo"
temperature = 0.7
max_tokens = 500
# Start with a random childhood question
initial_question = random.choice(prompts.CHILDHOOD_QUESTIONS)
print(f"AI: {initial_question}")
# Initialize message history
messages = [
prompts.SYSTEM_MESSAGE,
{"role": "assistant", "content": initial_question}
]
# Start chat loop
while True:
user_input = input("You: ").strip()
if user_input.lower() == "exit":
print("Goodbye!")
break
# Append user response
messages.append({"role": "user", "content": user_input})
# Let the AI both respond and generate the next question
assistant_prompt = (
"Responde de forma calorosa à última mensagem do utilizador em português de Portugal. "
"O teu objetivo é estimular a memória de um utilizador idoso. "
"Podes fazer perguntas sobre a sua infância, juventude ou momentos marcantes da vida. "
"Se for apropriado, também podes sugerir pequenos jogos de palavras, adivinhas, ou perguntas divertidas que o façam pensar ou sorrir. "
"Mantém um tom calmo, respeitoso e encorajador."
)
messages.append({"role": "assistant", "content": assistant_prompt})
# Generate the AI's response
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=temperature,
max_tokens=max_tokens
)
reply = response.choices[0].message.content.strip()
print(f"\nAI: {reply}\n")
messages.append({"role": "assistant", "content": reply})