Skip to content

Commit 132bb02

Browse files
LLM1 reasoning to db
1 parent 46b1d0e commit 132bb02

File tree

9 files changed

+345
-23
lines changed

9 files changed

+345
-23
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore .env file
2+
.env
3+
4+
# Ignore __pycache__ directories
5+
__pycache__/

calling.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import google.generativeai as genai
2+
from dotenv import load_dotenv
3+
import os
4+
5+
load_dotenv()
6+
api_key = os.getenv("GEMINI_API_KEY")
7+
genai.configure(api_key=api_key)
8+
def reasoning(prompt):
9+
model = genai.GenerativeModel("gemini-1.5-flash")
10+
response = model.generate_content(prompt)
11+
return response.text
12+

hello.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
from passlib.hash import sha256_crypt
88
from flask_cors import CORS
99
from dotenv import load_dotenv
10+
import prompting
11+
from calling import reasoning
12+
import time
1013

1114
load_dotenv()
1215

1316
app = Flask(__name__)
1417
CORS(app, resources={r"/*": {"origins": f"{os.getenv('CLIENT_URL')}"}}, supports_credentials=True)
1518
app.config["JWT_SECRET_KEY"] = f"{os.getenv('JWT_SECRET_KEY')}"
16-
1719
app.config['MONGO_URI'] = f"{os.getenv('MONGO_URI')}"
18-
1920
mongo = PyMongo(app)
2021
jwt = JWTManager(app)
2122

@@ -25,7 +26,7 @@ def login():
2526
return render_template("login.html")
2627

2728

28-
@app.route("/login", methods=['GET', 'POST'])
29+
@app.route("/login", methods=['POST'])
2930
def loginUser():
3031
username = request.json.get("username")
3132
password = request.json.get("password")
@@ -34,15 +35,13 @@ def loginUser():
3435

3536
_id = str(mongo.db.users.find_one({"username":username})["_id"])
3637
access_token = create_access_token(identity=str(_id))
37-
3838
response = make_response(jsonify({
3939
"message": "login successful",
40-
"access_token":access_token,
40+
"status": "logged_in",
4141
"redirect" : url_for("coding", username=username)
4242
}),201)
4343

44-
response.set_cookie('access_token', access_token, httponly=True, secure=False, samesite='None', domain='localhost', path='/')
45-
44+
response.set_cookie('access_token', access_token, httponly=False, secure=False, samesite='None', domain='localhost', path='/')
4645
return response
4746
else:
4847
response = make_response(jsonify({
@@ -62,6 +61,10 @@ def signupUser():
6261
password = request.json.get("password", None)
6362
email = request.json.get("email", None)
6463
answers = request.json.get("answers", None)
64+
prompt = prompting.prompt(answers)
65+
reasoning_gemini = reasoning(prompt)
66+
67+
time.sleep(5)
6568

6669

6770
if not username or not password or not email:
@@ -99,27 +102,20 @@ def signupUser():
99102
"sol3": answers[2],
100103
"sol4": answers[3],
101104
"sol5": answers[4],
102-
"reasoning": "None"
105+
"reasoning": str(reasoning_gemini)
103106
}).inserted_id
104107

105-
access_token = create_access_token(identity=str(_id))
106-
107-
print(access_token, flush=True)
108-
109108
response = make_response(jsonify({
110109
"message": f"user {username} created successfully",
111-
"access_token":access_token
110+
"status" : "created",
111+
"redirect" : url_for("login")
112112
}),201)
113113

114-
response.set_cookie('access_token', access_token, httponly=True, secure=True, samesite='strict')
115-
116-
print(response, flush=True)
117-
print(url_for("login"))
118-
119114
return response
120115

121116

122117
@app.route("/coding/<username>")
118+
# @jwt_required()
123119
def coding(username):
124120
return render_template('coding.html')
125121

masters_code.txt

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#include <bits/stdc++.h>
2+
3+
using i64 = long long;
4+
5+
void solve() {
6+
int n;
7+
std::cin >> n;
8+
9+
std::string s;
10+
std::cin >> s;
11+
12+
if (s[0] == s[n - 1]) {
13+
std::cout << "NO\n";
14+
} else {
15+
std::cout << "YES\n";
16+
}
17+
}
18+
19+
int main() {
20+
std::ios::sync_with_stdio(false);
21+
std::cin.tie(nullptr);
22+
23+
int t;
24+
std::cin >> t;
25+
26+
while (t--) {
27+
solve();
28+
}
29+
30+
return 0;
31+
}
32+
33+
-----
34+
/*
35+
Author: Altak
36+
*/
37+
#include <bits/stdc++.h>
38+
#define ll long long
39+
#define ff first
40+
#define ss second
41+
#define inf INT_MAX
42+
#define forn(i, a, b) for (int i = (a); i < (b); i++)
43+
#define forr(i, a, b) for (int i = (a); i >= (b); i--)
44+
#define all(x) (x.begin(), x.end())
45+
const int MOD = 1e9 + 7;
46+
using namespace std;
47+
void solve()
48+
{
49+
int n;
50+
cin >> n;
51+
if (n % 2 == 0)
52+
cout << "-1\n";
53+
else
54+
{
55+
forn(i, 0, n / 2) cout << n - i << " " << i + 1 << " ";
56+
cout << (n + 1) / 2 << endl;
57+
}
58+
}
59+
int main()
60+
{
61+
int T;
62+
cin >> T;
63+
while (T--)
64+
{
65+
solve();
66+
}
67+
return 2 / 11;
68+
}
69+
70+
-----
71+
#include <bits/stdc++.h>
72+
#define ll long long
73+
#define ff first
74+
#define ss second
75+
#define inf INT_MAX
76+
#define forn(i, a, b) for (int i = (a); i < (b); i++)
77+
#define forr(i, a, b) for (int i = (a); i >= (b); i--)
78+
#define all(x) (x.begin(), x.end())
79+
const int MOD = 1e9 + 7;
80+
using namespace std;
81+
void solve()
82+
{
83+
int n, sum = 0, mx = 0;
84+
cin >> n;
85+
int a[n];
86+
map<int, int> mp;
87+
forn(i, 0, n)
88+
{
89+
cin >> a[i];
90+
mp[a[i]]++;
91+
mx = max(mx, mp[a[i]]);
92+
}
93+
cout << n - mx << endl;
94+
}
95+
int main()
96+
{
97+
int T;
98+
cin >> T;
99+
while (T--)
100+
{
101+
solve();
102+
}
103+
return 2 / 11;
104+
}
105+
106+
-----
107+
#include <iostream>
108+
#include <fstream>
109+
#include <vector>
110+
#include <set>
111+
#include <map>
112+
#include <string>
113+
#include <cmath>
114+
#include <cassert>
115+
#include <ctime>
116+
#include <algorithm>
117+
#include <queue>
118+
#include <memory.h>
119+
#include <stack>
120+
#define mp make_pair
121+
#define pb push_back
122+
#define setval(a,v) memset(a,v,sizeof(a))
123+
124+
#if ( _WIN32 || __WIN32__ )
125+
#define LLD "%I64d"
126+
#else
127+
#define LLD "%lld"
128+
#endif
129+
130+
using namespace std;
131+
132+
typedef long long int64;
133+
typedef long double ld;
134+
135+
int main()
136+
{
137+
#ifndef ONLINE_JUDGE
138+
freopen("input.txt","r",stdin);
139+
freopen("output.txt","w",stdout);
140+
#endif
141+
int a,b,c;
142+
int a1,b1,c1;
143+
int n;
144+
cin>>n;
145+
a=b=c=0;
146+
for (int i=0;i<n;i++){
147+
cin>>a1>>b1>>c1;
148+
a+=a1;
149+
b+=b1;
150+
c+=c1;
151+
}
152+
if (a==0 && b==0 && c==0)
153+
cout << "YES" << endl;
154+
else
155+
cout << "NO" << endl;
156+
return 0;
157+
}
158+
159+
-----
160+
#include <iostream>
161+
#include <fstream>
162+
#include <cstdio>
163+
#include <set>
164+
#include <vector>
165+
#include <algorithm>
166+
#include <cmath>
167+
#include <cstdlib>
168+
#include <string>
169+
#include <map>
170+
#include <cstring>
171+
172+
using namespace std;
173+
174+
#define NextLine() { char c = getchar(); while (c != 10 && c != EOF) { c = getchar(); } }
175+
176+
string s;
177+
178+
void Load()
179+
{
180+
cin >> s;
181+
}
182+
183+
char ToLower(char c)
184+
{
185+
if ((c >= 'A') && (c <= 'Z')) return (char)((int)c - 'A' + 'a');
186+
else return c;
187+
}
188+
189+
int Vowel(char c)
190+
{
191+
c = ToLower(c);
192+
return (c == 'a') || (c == 'o') || (c == 'i') || (c == 'y') || (c == 'u') || (c == 'e');
193+
}
194+
195+
void Solve()
196+
{
197+
string t = "";
198+
int i;
199+
for (i = 0; i < s.length(); i++)
200+
{
201+
if (Vowel(s[i])) continue;
202+
t += ".";
203+
t += ToLower(s[i]);
204+
}
205+
cout << t;
206+
}
207+
208+
int main()
209+
{
210+
Load();
211+
Solve();
212+
return 0;
213+
}

prompting.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def refr(code):
2+
one_liner = code.replace('\n', '\\n').replace(' ', '\\t')
3+
return one_liner
4+
5+
6+
masters_code_li = []
7+
with open("./masters_code.txt", "r") as my_code:
8+
codes = my_code.read()
9+
code_li = codes.split('-----')
10+
for code in code_li:
11+
sample_code = ''''''
12+
sample_code += code
13+
masters_code_li.append(sample_code)
14+
15+
16+
def prompt(tester_list, master_list=masters_code_li):
17+
18+
prompt = f''''''
19+
20+
with open("./sample_prompt_LLM1.txt", "r") as my_file:
21+
prompt += my_file.read()
22+
23+
tc1 = refr(tester_list[0])
24+
tc2 = refr(tester_list[1])
25+
tc3 = refr(tester_list[2])
26+
tc4 = refr(tester_list[3])
27+
tc5 = refr(tester_list[4])
28+
mc1 = refr(master_list[0])
29+
mc2 = refr(master_list[1])
30+
mc3 = refr(master_list[2])
31+
mc4 = refr(master_list[3])
32+
mc5 = refr(master_list[4])
33+
34+
prompt = prompt.format(tc1=tc1, tc2=tc2, tc3=tc3, tc4=tc4, tc5=tc5, mc1=mc1, mc2=mc2, mc3=mc3, mc4=mc4, mc5=mc5)
35+
36+
return prompt

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ flask-pymongo==2.3.0
44
email-validator==1.3.1
55
passlib==1.7.4
66
flask-cors==3.0.10
7-
python-dotenv==1.0.0
7+
python-dotenv==1.0.0
8+
google-generativeai==0.8.3

0 commit comments

Comments
 (0)