-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfalcon_hackathon.py
215 lines (172 loc) · 7.59 KB
/
falcon_hackathon.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# -*- coding: utf-8 -*-
"""Falcon Hackathon.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1XdP62c7gjAycCX0sTetkv4Sh4YSP4VW4
"""
!pip install ai71
from ai71 import AI71
hints = 0
Input = input("Enter Your Question.... ")
AI71_API_KEY = "api71-api-2fcb29da-a589-4632-9e26-47a71786cd25"
while hints<=3:
if hints == 0:
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for coding problems. Do not provide the exact code directly but give hints according the person question. If a person seems beginer than give more details hints and if advance give less concise hints. Judge the person is beginners or advance on the basis of way in which he ask questions"
},
{"role": "user", "content": Input +" Give hints only. Give only one line to explain it" },
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
elif hints == 1:
print("Real world example")
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for coding problems. Give only a real world example related to that question only and dont give code."},
{"role": "user", "content": Input + " Give only a real world example to solve it. Give only one line to explain it" },
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
elif hints == 2:
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for coding problems. Give the proper code solution."},
{"role": "user", "content": Input },
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
else:
print("Topics")
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for coding problems. Give the only topics name that user have to read to understand the particular problem. Dont give any code and hints just give topic that user has to study in order tounder the question he asked"
},
{"role": "user", "content": Input +"Give me the just name of the topics that i have to study to understand this question. Give only one line to explain it" },
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
hints+=1
from ai71 import AI71
hints = 0
Input = input("Enter Your Math Question.... ")
AI71_API_KEY = "api71-api-2fcb29da-a589-4632-9e26-47a71786cd25"
while hints <= 3:
if hints == 0:
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for math problems. Do not provide the exact solution but only give hints only."
},
{"role": "user", "content": Input + " Give hints only to solve it. Give only two to three line to explain it."},
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
elif hints == 1:
print("Real-world example")
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for math problems. Give only a real-world example related to that question and don't give the exact solution."
},
{"role": "user", "content": Input + " Give only a real-world example to solve it. Give only one line to explain it."},
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
elif hints == 2:
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for math problems. Give the proper solution to the problem."
},
{"role": "user", "content": Input},
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
else:
print("Topics")
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": "You are a helpful assistant for math problems. Give only the names of topics that the user has to read to understand the particular problem. Don't give any code or hints; just give the topics that the user has to study to understand the question they asked."
},
{"role": "user", "content": Input + " Give me just the names of the topics that I have to study to understand this question. Give only one line to explain it."},
],
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
hints += 1
"""Part 2 begins here"""
from ai71 import AI71
import re
Input = input("Enter Your Question.... ")
AI71_API_KEY = "api71-api-2fcb29da-a589-4632-9e26-47a71786cd25"
response = ""
for chunk in AI71(AI71_API_KEY).chat.completions.create(
model="tiiuae/falcon-180b-chat",
messages=[
{
"role": "system",
"content": '''You are a helpful assistant for coding problems.'''
},
{
"role": "user",
"content": Input + ''' First, judge whether the person is a beginner or advanced based on the way they ask questions. If the person is a beginner, give more detailed hints, and if advanced, give less concise hints. The answer you give must have the following sections:
1. Give hints to solve the question but do not give the coding solution. After it, give a two-line space.
2. Provide some real-world examples. Give only one example to explain it. Don't give the code. After it, give a two-line space.
3. If the question is of beginner level, then give some more hints that enhance the self-learning of the user, and if the question is advanced, then ignore this line. After it, give a two-line space.
4. Provide the code solution to the question. After it, give a two-line space.
5. Mention the topic name to study to understand the question. After it, give a two-line space.
Do not use the word "beginner" directly.'''
},
],
stream=True,
):
if chunk.choices[0].delta.content:
response += chunk.choices[0].delta.content
x = response.split("\n\n")
hint1 = x[0]
hint2 = x[1]
hint3 = x[2]
hint4 = x[3:-1]
hint5 = x[-1]
# print(hint1)
# print(hint2)
print(hint3)
# print(hint4)
# print(hint5)