Spaces:
Paused
Paused
Added error signaling
Browse files
app.py
CHANGED
@@ -9,25 +9,28 @@ DEFAULT_TEMPERATURE = 0.7
|
|
9 |
DEFAULT_TOP_P = 0.95
|
10 |
|
11 |
def generate_journal_suggestion(current_page):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
@app.route("/", methods=["POST", "GET"])
|
|
|
9 |
DEFAULT_TOP_P = 0.95
|
10 |
|
11 |
def generate_journal_suggestion(current_page):
|
12 |
+
try:
|
13 |
+
suggestion_prompt = (
|
14 |
+
f"""Pe baza înregistrării din jurnal: '{current_page}', generează o singură întrebare pe care utilizatorul ar putea să și-o pună în jurnalul său.
|
15 |
+
Întrebarea ar trebui să încurajeze reflecția personală mai profundă, explorarea sentimentelor sau clarificarea obiectivelor."""
|
16 |
+
)
|
17 |
+
suggestion_response = ""
|
18 |
+
|
19 |
+
for message in client.chat_completion(
|
20 |
+
[
|
21 |
+
{"role": "user", "content": suggestion_prompt}
|
22 |
+
],
|
23 |
+
max_tokens=150,
|
24 |
+
stream=True,
|
25 |
+
temperature=DEFAULT_TEMPERATURE,
|
26 |
+
top_p=DEFAULT_TOP_P,
|
27 |
+
):
|
28 |
+
token = message.choices[0].delta.content
|
29 |
+
suggestion_response += token
|
30 |
+
|
31 |
+
return suggestion_response
|
32 |
+
except Exception as e:
|
33 |
+
return jsonify({"error": str(e)}), 500
|
34 |
|
35 |
|
36 |
@app.route("/", methods=["POST", "GET"])
|