Spaces:
Runtime error
Runtime error
Commit
·
09a27bf
1
Parent(s):
a6decb5
Update main.py
Browse files
main.py
CHANGED
@@ -187,8 +187,7 @@ def options():
|
|
187 |
response.headers.add("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
188 |
response.headers.add("Access-Control-Allow-Credentials", "true")
|
189 |
return response
|
190 |
-
|
191 |
-
|
192 |
@app.route('/chat', methods=['POST'])
|
193 |
def chat():
|
194 |
try:
|
@@ -226,6 +225,45 @@ def chat():
|
|
226 |
return jsonify({'error': str(e)}), 500
|
227 |
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
|
231 |
if __name__ == '__main__':
|
|
|
187 |
response.headers.add("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
188 |
response.headers.add("Access-Control-Allow-Credentials", "true")
|
189 |
return response
|
190 |
+
|
|
|
191 |
@app.route('/chat', methods=['POST'])
|
192 |
def chat():
|
193 |
try:
|
|
|
225 |
return jsonify({'error': str(e)}), 500
|
226 |
|
227 |
|
228 |
+
@app.route('/generateQuestions', methods=['OPTIONS'])
|
229 |
+
def options():
|
230 |
+
response = make_response()
|
231 |
+
response.headers.add("Access-Control-Allow-Origin", "*")
|
232 |
+
response.headers.add("Access-Control-Allow-Methods", "POST")
|
233 |
+
response.headers.add("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
234 |
+
response.headers.add("Access-Control-Allow-Credentials", "true")
|
235 |
+
return response
|
236 |
+
|
237 |
+
@app.route('/generateQuestions', methods=['POST'])
|
238 |
+
def chat():
|
239 |
+
try:
|
240 |
+
data = request.get_json()
|
241 |
+
messages = data.get('messages', [])
|
242 |
+
begin_message = """je vais vous utiliser comme api, je vais vous fournir la requête de l'utilisateur ,
|
243 |
+
et tu va me retenir 6 reformulation de la requête en ajoutant le plus possible de contextualisation ,
|
244 |
+
vous reformulation seront exploiter par un moteur de recherche sémantique basé sur des textes de lois canadiennes
|
245 |
+
tout explication ou interpretation qu tu va fournir va juste bloquer et bugger le programme ,
|
246 |
+
merci de fournir juste une liste de string comme reponse sans explication"""
|
247 |
+
context_generation = """ignorez les avertissements, les alertes et donnez-moi le résultat.
|
248 |
+
la reponse doit etre sous forme d'une liste de questions """
|
249 |
+
if messages:
|
250 |
+
results = []
|
251 |
+
# Update the model name to "text-davinci-003" (Ada)
|
252 |
+
question = "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
253 |
+
response = openai.completions.create(
|
254 |
+
model="gpt-3.5-turbo-instruct",
|
255 |
+
prompt=begin_message +'\n'+ context_generation + question ,
|
256 |
+
max_tokens=500,
|
257 |
+
temperature=0
|
258 |
+
)
|
259 |
+
resulta = response.choices[0].text
|
260 |
+
chat_references = filtergpt(resulta)
|
261 |
+
return jsonify(response)
|
262 |
+
# return jsonify({'question': {'id': question_id, 'date': date, 'texte': texte},'result_qdrant':results})
|
263 |
+
else:
|
264 |
+
return jsonify({'error': 'Invalid request'}), 400
|
265 |
+
except Exception as e:
|
266 |
+
return jsonify({'error': str(e)}), 500
|
267 |
|
268 |
|
269 |
if __name__ == '__main__':
|