Spaces:
Build error
Build error
Merge branch 'vlad' into feature-wormhole
Browse files- .env.sample +1 -0
- app.py +14 -13
- scripts/env_loader.py +9 -0
- scripts/logger.py +11 -0
.env.sample
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
SENTRY_URL=<sentry_url>
|
app.py
CHANGED
@@ -4,9 +4,10 @@ or
|
|
4 |
`python -m uvicorn app:app --reload --host localhost --port 7860`
|
5 |
"""
|
6 |
import ast
|
|
|
7 |
import mathactive.microlessons.num_one as num_one_quiz
|
|
|
8 |
import sentry_sdk
|
9 |
-
|
10 |
from fastapi import FastAPI, Request
|
11 |
from fastapi.responses import JSONResponse
|
12 |
from fastapi.staticfiles import StaticFiles
|
@@ -20,20 +21,22 @@ from mathtext_fastapi.conversation_manager import manage_conversation_response
|
|
20 |
from mathtext_fastapi.v2_conversation_manager import manage_conversation_response
|
21 |
from mathtext_fastapi.nlu import evaluate_message_with_nlu
|
22 |
from mathtext_fastapi.nlu import run_intent_classification
|
23 |
-
|
24 |
-
import os
|
25 |
from dotenv import load_dotenv
|
|
|
26 |
|
27 |
load_dotenv()
|
28 |
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
)
|
|
|
|
|
37 |
|
38 |
app = FastAPI()
|
39 |
|
@@ -183,12 +186,10 @@ async def num_one(request: Request):
|
|
183 |
'state': 'question'
|
184 |
}
|
185 |
"""
|
186 |
-
print("STEP 1")
|
187 |
data_dict = await request.json()
|
188 |
-
message_data =
|
189 |
user_id = message_data['user_id']
|
190 |
message_text = message_data['message_text']
|
191 |
-
print("STEP 2")
|
192 |
return num_one_quiz.process_user_message(user_id, message_text)
|
193 |
|
194 |
|
|
|
4 |
`python -m uvicorn app:app --reload --host localhost --port 7860`
|
5 |
"""
|
6 |
import ast
|
7 |
+
import json
|
8 |
import mathactive.microlessons.num_one as num_one_quiz
|
9 |
+
import os
|
10 |
import sentry_sdk
|
|
|
11 |
from fastapi import FastAPI, Request
|
12 |
from fastapi.responses import JSONResponse
|
13 |
from fastapi.staticfiles import StaticFiles
|
|
|
21 |
from mathtext_fastapi.v2_conversation_manager import manage_conversation_response
|
22 |
from mathtext_fastapi.nlu import evaluate_message_with_nlu
|
23 |
from mathtext_fastapi.nlu import run_intent_classification
|
|
|
|
|
24 |
from dotenv import load_dotenv
|
25 |
+
from sentry_sdk.utils import BadDsn
|
26 |
|
27 |
load_dotenv()
|
28 |
|
29 |
+
try:
|
30 |
+
sentry_sdk.init(
|
31 |
+
dsn=os.environ.get('SENTRY_DNS'),
|
32 |
|
33 |
+
# Set traces_sample_rate to 1.0 to capture 100%
|
34 |
+
# of transactions for performance monitoring.
|
35 |
+
# We recommend adjusting this value in production,
|
36 |
+
traces_sample_rate=0.20,
|
37 |
+
)
|
38 |
+
except BadDsn:
|
39 |
+
pass
|
40 |
|
41 |
app = FastAPI()
|
42 |
|
|
|
186 |
'state': 'question'
|
187 |
}
|
188 |
"""
|
|
|
189 |
data_dict = await request.json()
|
190 |
+
message_data = json.loads(data_dict.get('message_data', '').get('message_body', '').replace("'", '"'))
|
191 |
user_id = message_data['user_id']
|
192 |
message_text = message_data['message_text']
|
|
|
193 |
return num_one_quiz.process_user_message(user_id, message_text)
|
194 |
|
195 |
|
scripts/env_loader.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import dotenv
|
2 |
+
import os
|
3 |
+
|
4 |
+
dotenv.load_dotenv(".env")
|
5 |
+
envs = {}
|
6 |
+
|
7 |
+
|
8 |
+
for var in ["SENTRY_URL"]:
|
9 |
+
envs[var] = os.getenv(var)
|
scripts/logger.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sentry_sdk
|
2 |
+
from . import env_loader
|
3 |
+
|
4 |
+
sentry_sdk.init(
|
5 |
+
dsn=env_loader.envs.get("SENTRY_URL"),
|
6 |
+
|
7 |
+
# Set traces_sample_rate to 1.0 to capture 100%
|
8 |
+
# of transactions for performance monitoring.
|
9 |
+
# We recommend adjusting this value in production.
|
10 |
+
traces_sample_rate=1.0
|
11 |
+
)
|