Skip to content

Commit 2593c79

Browse files
author
James Melvin
committed
fix : incorporated review comments
1 parent 1644d5a commit 2593c79

File tree

6 files changed

+13
-95
lines changed

6 files changed

+13
-95
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ backend/openapi.json
1818
*.db
1919
# edit docs using obsidian.md, these files should not appear in the repo
2020
.obsidian/
21-

backend/main.py

+2-52
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
from oasst_backend.prompt_repository import PromptRepository, UserRepository
2323
from oasst_backend.task_repository import TaskRepository, delete_expired_tasks
2424
from oasst_backend.tree_manager import TreeManager, halt_prompts_of_disabled_users
25-
from oasst_backend.user_repository import User
2625
from oasst_backend.user_stats_repository import UserStatsRepository, UserStatsTimeFrame
27-
from oasst_backend.utils.database_utils import CommitMode, default_session_factory, managed_tx_function
26+
from oasst_backend.utils.database_utils import CommitMode, managed_tx_function
2827
from oasst_shared.exceptions import OasstError, OasstErrorCode
2928
from oasst_shared.schemas import protocol as protocol_schema
3029
from oasst_shared.utils import utcnow
3130
from prometheus_fastapi_instrumentator import Instrumentator
3231
from pydantic import BaseModel
33-
from sqlmodel import Session, select
32+
from sqlmodel import Session
3433
from starlette.middleware.cors import CORSMiddleware
3534

3635
# from worker.scheduled_tasks import create_task
@@ -139,8 +138,6 @@ async def http_callback(request: fastapi.Request, response: fastapi.Response, pe
139138
@app.on_event("startup")
140139
@managed_tx_function(auto_commit=CommitMode.COMMIT)
141140
def create_seed_data(session: Session):
142-
# logger.debug("create_seed_data...")
143-
# create_task.delay("create_seed_data",2,3)
144141
class DummyMessage(BaseModel):
145142
task_message_id: str
146143
user_message_id: str
@@ -289,53 +286,6 @@ def update_leader_board_total(session: Session) -> None:
289286
logger.exception("Error during user states update (total)")
290287

291288

292-
@app.on_event("startup")
293-
@repeat_every(seconds=3600, wait_first=False)
294-
def update_user_streak() -> None:
295-
logger.debug("update_user_streak...")
296-
try:
297-
with default_session_factory() as session:
298-
current_time = utcnow()
299-
timedelta = current_time - startup_time
300-
if timedelta.days > 0:
301-
# Update only greater than 24 hours . Do nothing
302-
logger.debug("Process timedelta greater than 24h")
303-
statement = select(User)
304-
result = session.exec(statement).all()
305-
if result is not None:
306-
for user in result:
307-
last_activity_date = user.last_activity_date
308-
streak_last_day_date = user.streak_last_day_date
309-
# set NULL streak_days to 0
310-
if user.streak_days is None:
311-
user.streak_days = 0
312-
# if the user had completed a task
313-
if last_activity_date is not None:
314-
lastactitvitydelta = current_time - last_activity_date
315-
# if the user missed consecutive days of completing a task
316-
# reset the streak_days to 0 and set streak_last_day_date to the current_time
317-
if lastactitvitydelta.days > 1 or user.streak_days is None:
318-
user.streak_days = 0
319-
user.streak_last_day_date = current_time
320-
# streak_last_day_date has a current timestamp in DB. Idealy should not be NULL.
321-
if streak_last_day_date is not None:
322-
streak_delta = current_time - streak_last_day_date
323-
# if user completed tasks on consecutive days then increment the streak days
324-
# update the streak_last_day_date to current time for the next calculation
325-
if streak_delta.days > 0:
326-
user.streak_days += 1
327-
user.streak_last_day_date = current_time
328-
session.add(user)
329-
session.commit()
330-
331-
else:
332-
logger.debug("Not yet 24hours since the process started! ...")
333-
334-
except Exception as e:
335-
logger.error(str(e))
336-
return
337-
338-
339289
@app.on_event("startup")
340290
@repeat_every(seconds=60 * 60) # 1 hour
341291
@managed_tx_function(auto_commit=CommitMode.COMMIT)

backend/oasst_backend/tree_manager.py

+2-34
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
managed_tx_function,
3030
managed_tx_method,
3131
)
32-
33-
# from oasst_backend.utils.hugging_face import HfClassificationModel, HfEmbeddingModel, HfUrl, HuggingFaceAPI
3432
from oasst_backend.utils.ranking import ranked_pairs
3533
from oasst_shared.exceptions.oasst_api_error import OasstError, OasstErrorCode
3634
from oasst_shared.schemas import protocol as protocol_schema
@@ -735,48 +733,18 @@ async def handle_interaction(self, interaction: protocol_schema.AnyInteraction)
735733
hf_feature_extraction.delay(interaction.text, message.id, pr.api_client.dict())
736734
logger.debug("Extract Embedding")
737735
except OasstError:
738-
logger.debug(
736+
logger.error(
739737
f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}."
740738
)
741-
742-
# try:
743-
# hugging_face_api = HuggingFaceAPI(
744-
# f"{HfUrl.HUGGINGFACE_FEATURE_EXTRACTION.value}/{HfEmbeddingModel.MINILM.value}"
745-
# )
746-
# embedding = await hugging_face_api.post(interaction.text)
747-
# pr.insert_message_embedding(
748-
# message_id=message.id, model=HfEmbeddingModel.MINILM.value, embedding=embedding
749-
# )
750-
# except OasstError:
751-
# logger.error(
752-
# f"Could not fetch embbeddings for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}."
753-
# )
754739
if not settings.DEBUG_SKIP_TOXICITY_CALCULATION:
755740
try:
756741
toxicity.delay(interaction.text, message.id, pr.api_client.dict())
757742
logger.debug("Sent Toxicity")
758743
except OasstError:
759-
logger.debug(
744+
logger.error(
760745
f"Could not compute toxicity for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}."
761746
)
762747

763-
# try:
764-
# model_name: str = HfClassificationModel.TOXIC_ROBERTA.value
765-
# hugging_face_api: HuggingFaceAPI = HuggingFaceAPI(
766-
# f"{HfUrl.HUGGINGFACE_TOXIC_CLASSIFICATION.value}/{model_name}"
767-
# )
768-
769-
# toxicity: List[List[Dict[str, Any]]] = await hugging_face_api.post(interaction.text)
770-
# toxicity = toxicity[0][0]
771-
# pr.insert_toxicity(
772-
# message_id=message.id, model=model_name, score=toxicity["score"], label=toxicity["label"]
773-
# )
774-
775-
# except OasstError:
776-
# logger.error(
777-
# f"Could not compute toxicity for text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}."
778-
# )
779-
780748
case protocol_schema.MessageRating:
781749
logger.info(
782750
f"Frontend reports rating of message_id={interaction.message_id} by user={interaction.user}."

docker-compose.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ services:
110110
- "8080:8080"
111111

112112
# The oassist backend celery worker service.
113-
backend-cworker:
113+
backend-worker:
114114
build:
115-
dockerfile: docker/Dockerfile.backendworker
115+
dockerfile: docker/Dockerfile.backend-worker
116116
context: .
117117
command: celery -A celery_worker worker -l info
118-
image: oasst-backend-cworker
118+
image: oasst-backend-worker
119119
environment:
120120
- CELERY_BROKER_URL=redis://redis:6379/0
121121
- CELERY_RESULT_BACKEND=redis://redis:6379/0
@@ -130,12 +130,12 @@ services:
130130
profiles: ["frontend-dev", "ci"]
131131

132132
# The oassist backend celery worker service.
133-
backend-cworker-beat:
133+
backend-worker-beat:
134134
build:
135-
dockerfile: docker/Dockerfile.backendworker
135+
dockerfile: docker/Dockerfile.backend-worker
136136
context: .
137137
command: celery -A celery_worker beat -l info
138-
image: oasst-backend-cworker-beat
138+
image: oasst-backend-worker-beat
139139
environment:
140140
- CELERY_BROKER_URL=redis://redis:6379/0
141141
- CELERY_RESULT_BACKEND=redis://redis:6379/0
File renamed without changes.

backend/start_worker.sh scripts/backend-development/start_worker.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ then
55
kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1
66

77
fi
8+
cd ../../backend/oasst_backend
89
celery -A celery_worker beat -l info &
910
celery -A celery_worker worker -l info &
10-
# celery -A oasst_backend beat -l info --logfile=celery.beat.log --detach
11-
# celery -A oasst_backend worker -l info --logfile=celery.log --detach
11+
# celery -A celery_worker beat -l info --logfile=celery.beat.log --detach
12+
# celery -A celery_worker worker -l info --logfile=celery.log --detach

0 commit comments

Comments
 (0)