-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (54 loc) · 1.82 KB
/
main.py
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
61
62
63
64
65
66
67
import os
import openai
from dotenv import load_dotenv
import prompts
load_dotenv()
client = openai.OpenAI()
if __name__ == "__main__":
choice_prompt_mapping = {
1: prompts.CONCEPT_PROMPT,
2: prompts.SOLUTION_PROMPT,
3: prompts.PROBLEM_GENERATION_PROMPT,
4: prompts.VERIFY_SOLUTION_PROMPT,
5: prompts.REAL_WORLD_APPLICATION_PROMPT,
6: prompts.SOLUTIONS_NEXT_STEP_PROMPT,
}
# 1) Listing available subjects
print(prompts.GREETING)
# 2) Choosing subject
_ = input(prompts.GREETING_INPUT)
while True:
try:
# 3) Listing available types of prompts
print(prompts.CHOOSE_OPTION)
# 4) Choosing prompt
try:
choice = int(input(prompts.CHOOSE_OPTION_INPUT))
except ValueError:
print("Input number from 1 to 6 next time (=")
continue
prompt = choice_prompt_mapping.get(choice)
# 5) Getting user question
user_input = input("Question: ")
# 6) Getting answer
answer = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": prompt,
},
{
"role": "user",
"content": user_input,
},
],
)
with open("message_history.log", "a") as log_file:
chat_completion_message = answer.choices[0].message
log_file.write(chat_completion_message.__str__() + "\n")
print(chat_completion_message)
except KeyboardInterrupt:
print(prompts.FAREWELL)
break
client.close()