-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcot.py
More file actions
77 lines (68 loc) · 2.85 KB
/
Copy pathcot.py
File metadata and controls
77 lines (68 loc) · 2.85 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#CoT - Chain of Thought
from openai import OpenAI
import json
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("GOOGLE_API_KEY")
client=OpenAI(
api_key = api_key,
base_url = "https://generativelanguage.googleapis.com/v1beta/"
)
SYSTEM_PROMPT = """
you are an expert AI assistant in resolving user queries using Chain of Thought.
you work on START ,PLAN and OUTPUT steps.
You need to first PLAN what needs to be done.The PLAN can be multiple steps.
Once you think enough PLAN has been done , finally you can give an OUTPUT.
Rules:
-Strictly follow the given JSON output format
-Only run 1 step at a time
-display each step in next line
Output JSON format:
{ "step" : "START" | "PLAN" | "OUTPUT" , "content": "string" }
START: Hey, can you solve 2+3*5/10
PLAN: { "step": "PLAN", "content" : "Seems like user is interested in math problem"}
PLAN: { "step": "PLAN", "content" : "Looking at the problem , we should solve this using BODMAS method"}
PLAN: { "step": "PLAN", "content" : "First we must multiply 3*5 which is 15"}
PLAN: { "step": "PLAN", "content" : "Now equation is 2+15/10"}
PLAN: { "step": "PLAN", "content" : "We must divide 15 / 10"}
PLAN: { "step": "PLAN", "content" : "Now the equation is 2+1.5"}
PLAN: { "step": "PLAN", "content" : "We will add the remaining numbers: 2+1.5 "}
OUTPUT: { "step": "OUTPUT", "content" : "The final answer is 3.5."}
"""
response = client.chat.completions.create(
model= "gemini-2.5-flash",
response_format ={ "type" : "json_object"},
messages = [
{
"role":"system",
"content": SYSTEM_PROMPT
},
{
"role":"user",
"content": "Give me a schedule to prepare for banking exam in Karnataka,India,I want to complete all the topics and score well in 5 months. "
},
{
"role": "assistant",
"content": json.dumps({
"step":"START",
"content": "you want a banking exam preparation schedule"
})
},
{
"role": "assistant",
"content" : json.dumps({
"step": "PLAN",
"content": "I will create a 5-month study schedule for banking exams, keeping in mind the typical subjects and preparation strategies required for competitive exams in India."
})
},
{
"role": "assistant",
"content": json.dumps({
"step": "PLAN",
"content": "I will divide the 5-month preparation into distinct phases: Foundation (Month 1-1.5), In-depth Practice & Concept Strengthening (Month 2-3.5), and Intensive Revision & Mock Tests (Month 4-5)."
})
}
]
)
print(response.choices[0].message.content)