Skip to content

Commit

Permalink
Merge pull request #14 from OVINC-CN/feat_remove_content
Browse files Browse the repository at this point in the history
feat: no longer record user content to db
  • Loading branch information
OrenZhang authored Oct 8, 2023
2 parents f061eee + 17d2390 commit ed3a0eb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def post_chat(self) -> None:
# save
self.log.finished_at = self.finished_at
self.log.save()
self.log.remove_content()

@classmethod
def list_models(cls) -> List[dict]:
Expand Down Expand Up @@ -166,6 +167,7 @@ def chat(self, *args, **kwargs) -> any:
return
self.log.finished_at = int(timezone.now().timestamp() * 1000)
self.log.save()
self.log.remove_content()

# pylint: disable=W0221,R1710
def record(self, response: HunYuanChuck) -> None:
Expand Down
22 changes: 22 additions & 0 deletions apps/chat/migrations/0003_remove_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pylint: disable=R0801,C0103

from django.conf import settings
from django.db import migrations

from apps.chat.models import ChatLog


def remove_content(*args, **kwargs) -> None:
if settings.RECORD_CHAT_CONTENT:
return
ChatLog.objects.all().update(messages=[], content="")


class Migration(migrations.Migration):
dependencies = [
("chat", "0002_alter_chatlog_model_modelpermission"),
]

operations = [
migrations.RunPython(remove_content),
]
8 changes: 8 additions & 0 deletions apps/chat/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from typing import List

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import Q, QuerySet
Expand Down Expand Up @@ -61,6 +62,13 @@ class Meta:
verbose_name_plural = verbose_name
ordering = ["-created_at"]

def remove_content(self) -> None:
if settings.RECORD_CHAT_CONTENT:
return
self.messages = []
self.content = ""
self.save(update_fields=["messages", "content"])


@dataclass
class Message:
Expand Down
3 changes: 3 additions & 0 deletions entry/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,6 @@
QCLOUD_HUNYUAN_API_URL = os.getenv(
"QCLOUD_HUNYUAN_API_DOMAIN", "https://hunyuan.cloud.tencent.com/hyllm/v1/chat/completions"
)

# Log
RECORD_CHAT_CONTENT = strtobool(os.getenv("RECORD_CHAT_CONTENT", "False"))

0 comments on commit ed3a0eb

Please sign in to comment.