From a9156bf037aa9eedaa1938eab66e03c509c3fd29 Mon Sep 17 00:00:00 2001 From: jlj <3042504846@qq.com> Date: Fri, 23 May 2025 19:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat/consumers.py | 4 +++- apps/chat/views.py | 2 ++ .../migrations/0005_merge_20250523_1923.py | 14 ++++++++++++++ daren/settings.py | 19 +++++++------------ 4 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 apps/daren_detail/migrations/0005_merge_20250523_1923.py diff --git a/apps/chat/consumers.py b/apps/chat/consumers.py index a11941d..2a629c4 100644 --- a/apps/chat/consumers.py +++ b/apps/chat/consumers.py @@ -11,10 +11,12 @@ import uuid import aiohttp from urllib.parse import parse_qs from django.utils import timezone - +from rest_framework.permissions import IsAuthenticated +from apps.user.authentication import CustomTokenAuthentication logger = logging.getLogger(__name__) class ChatStreamConsumer(AsyncWebsocketConsumer): + # 固定知识库ID DEFAULT_KNOWLEDGE_BASE_ID = "b680a4fa-37be-11f0-a7cb-0242ac120002" diff --git a/apps/chat/views.py b/apps/chat/views.py index 32c4189..af9477c 100644 --- a/apps/chat/views.py +++ b/apps/chat/views.py @@ -12,6 +12,7 @@ from rest_framework.decorators import action from apps.user.models import User from apps.chat.models import ChatHistory from apps.chat.serializers import ChatHistorySerializer +from apps.user.authentication import CustomTokenAuthentication from apps.common.services.chat_service import ChatService from apps.chat.services.chat_api import ( ExternalAPIError, stream_chat_answer, get_chat_answer, @@ -22,6 +23,7 @@ logger = logging.getLogger(__name__) class ChatHistoryViewSet(viewsets.ModelViewSet): permission_classes = [IsAuthenticated] + authentication_classes = [CustomTokenAuthentication] serializer_class = ChatHistorySerializer queryset = ChatHistory.objects.all() diff --git a/apps/daren_detail/migrations/0005_merge_20250523_1923.py b/apps/daren_detail/migrations/0005_merge_20250523_1923.py new file mode 100644 index 0000000..ede4f24 --- /dev/null +++ b/apps/daren_detail/migrations/0005_merge_20250523_1923.py @@ -0,0 +1,14 @@ +# Generated by Django 5.1.5 on 2025-05-23 11:23 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('daren_detail', '0004_creatorprofile_avatar'), + ('daren_detail', '0004_creatorprofile_profile'), + ] + + operations = [ + ] diff --git a/daren/settings.py b/daren/settings.py index b8b9e4a..c18061c 100644 --- a/daren/settings.py +++ b/daren/settings.py @@ -49,8 +49,8 @@ INSTALLED_APPS = [ "apps.brands.apps.BrandsConfig", 'rest_framework', 'rest_framework_simplejwt', - 'apps.chat.apps.ChatConfig', - 'apps.common.apps.CommonConfig', + "apps.chat.apps.ChatConfig", + "apps.common.apps.CommonConfig", ] MIDDLEWARE = [ @@ -102,7 +102,7 @@ DATABASES = { 'NAME': 'daren_detail', 'USER': 'root', 'PASSWORD': '123456', - 'HOST': '192.168.31.138', + 'HOST': 'localhost', 'PORT': '3306', 'OPTIONS': { 'charset': 'utf8mb4', @@ -215,13 +215,9 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # REST Framework 设置 REST_FRAMEWORK = { - 'DEFAULT_AUTHENTICATION_CLASSES': [ - 'rest_framework_simplejwt.authentication.JWTAuthentication', - 'apps.user.authentication.CustomTokenAuthentication', - ], - 'DEFAULT_PERMISSION_CLASSES': [ - 'rest_framework.permissions.IsAuthenticated', - ], + 'DEFAULT_AUTHENTICATION_CLASSES': [], # 默认不需要认证 + 'DEFAULT_PERMISSION_CLASSES': [], # 默认不需要权限 + 'UNAUTHENTICATED_USER': None } # JWT 设置 @@ -241,5 +237,4 @@ SIMPLE_JWT = { } API_BASE_URL = 'http://81.69.223.133:48329' -SILICON_CLOUD_API_KEY = 'sk-xqbujijjqqmlmlvkhvxeogqjtzslnhdtqxqgiyuhwpoqcjvf' - +SILICON_CLOUD_API_KEY = 'sk-xqbujijjqqmlmlvkhvxeogqjtzslnhdtqxqgiyuhwpoqcjvf' \ No newline at end of file