Skip to content

Commit

Permalink
'docs:使用novel_api_h5库,待测试'
Browse files Browse the repository at this point in the history
  • Loading branch information
passion2021 committed Jun 20, 2023
1 parent 2c1b04c commit 6148a1f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
12 changes: 12 additions & 0 deletions logs/novel_api.log
Original file line number Diff line number Diff line change
Expand Up @@ -6541,3 +6541,15 @@ INFO 2023-06-20 12:06:21,279 autoreload 250 E:\workspace2\novel_api\novel_api\ap
INFO 2023-06-20 12:06:22,396 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:09:58,596 autoreload 250 E:\workspace2\novel_api\novel_api\apps\chatbot\views.py changed, reloading.
INFO 2023-06-20 12:09:59,774 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:12:40,246 autoreload 250 E:\workspace2\novel_api\novel_api\apps\chatbot\views.py changed, reloading.
INFO 2023-06-20 12:12:42,023 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:12:46,472 autoreload 250 E:\workspace2\novel_api\novel_api\apps\chatbot\views.py changed, reloading.
INFO 2023-06-20 12:12:48,148 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:14:13,210 autoreload 250 E:\workspace2\novel_api\novel_api\apps\chatbot\views.py changed, reloading.
INFO 2023-06-20 12:14:14,828 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:22:42,067 autoreload 250 E:\workspace2\novel_api\novel_api\apps\chatbot\views.py changed, reloading.
INFO 2023-06-20 12:22:43,664 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:23:27,680 autoreload 250 E:\workspace2\novel_api\novel_api\apps\chatbot\views.py changed, reloading.
INFO 2023-06-20 12:23:29,324 autoreload 636 Watching for file changes with StatReloader
INFO 2023-06-20 12:26:09,724 autoreload 250 E:\workspace2\novel_api\novel_api\settings\dev.py changed, reloading.
INFO 2023-06-20 12:26:11,392 autoreload 636 Watching for file changes with StatReloader
12 changes: 2 additions & 10 deletions novel_api/apps/chatbot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ class Access_token_pool(mongoengine.Document):
@classmethod
def get_oldest_token(cls):
current_time = datetime.datetime.now()
oldest_token = cls.objects.order_by('now_time').first() # 未取到不会报错
oldest_token = cls.objects.order_by('now_time').first() # 取不到token则为None
if oldest_token:
oldest_token.now_time = current_time
oldest_token.save()
return oldest_token # 如果不存在会为None


class User(mongoengine.Document):
id = mongoengine.StringField(max_length=100)


class Paragraph(mongoengine.Document):
text = mongoengine.ListField()


class Choice(mongoengine.Document):
text = mongoengine.ListField()

# "novel_id": 1,
# "novel_title": "我对总裁大人有偏见",
# "novel_image": "https://cn.bing.com/images/search?view=detailV2&ccid=Bq5jD730&id=E91F2971887D91E927CE16AB8F45BEB8C1185543&thid=OIP.Bq5jD730RoSsMF3c1yWIWwHaJ4&mediaurl=https%3A%2F%2Fstatic.zongheng.com%2Fupload%2Fcover%2Fshucheng%2F16%2F15416195.jpg&exph=3200&expw=2400&q=%e5%b0%8f%e8%af%b4%e5%9b%be%e7%89%87&simid=608000767812436123&form=IRPRST&ck=ADD7A0A91334D779ECBD217BF7F86F67&selectedindex=2&ajaxhist=0&ajaxserp=0&vt=0&sim=11",
# "novel_tag": ["言情"],
# "novel_visit": '10.0万',

7 changes: 2 additions & 5 deletions novel_api/apps/chatbot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from utils.common_response import APIResponse
from .models import Access_token_pool, Paragraph, Choice

# 如下导入和算法相关
# 如下导入和get_memory算法相关
from sentence_transformers import SentenceTransformer
from sentence_transformers import util
import torch

os.environ["CUDA_VISIBLE_DEVICES"] = "1"
embedder = SentenceTransformer('multi-qa-mpnet-base-cos-v1')
# 如上导入和算法相关
# 如上导入和get_memory算法相关


# token_lock = threading.Lock() # 注释掉这两行代码,就变成了不加锁的版本
Expand Down Expand Up @@ -241,5 +240,3 @@ def get_memory(self, request, *args, **kwargs):
input_long_term_memory = "暂无参考"

return APIResponse(data=input_long_term_memory)


21 changes: 7 additions & 14 deletions novel_api/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
import sys
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.append(str(BASE_DIR)) # 导入小项目路径
sys.path.append(os.path.join(BASE_DIR, '../apps')) # 导入app路径
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-fw()pe=&#w&_p_uf*+27pg9ma4-oazvg1*^s@=az4#h(6hatb*'

# SECURITY WARNING: don't run with debug turned on in production!
Expand Down Expand Up @@ -76,9 +72,6 @@
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

# 数据库相关配置
# name = os.environ.get('LUFFY_NAME', 'luffy')
# password = os.environ.get('LUFFY_PASSWORD', 'Luffy123?')

DATABASES = {
'default': {
Expand All @@ -89,14 +82,14 @@
}

# mongodb配置
# from mongoengine import connect
# from urllib.parse import quote_plus
#
# connect('novel_api_h5', host="mongodb://%s:%s@%s" % (quote_plus("aiwaves"), quote_plus("bxzn2023"), "47.96.122.196"))

from mongoengine import connect
# 连接 MongoDB 数据库
connect('your_database_name')
from urllib.parse import quote_plus

connect('novel_api_h5', host="mongodb://%s:%s@%s" % (quote_plus("aiwaves"), quote_plus("bxzn2023"), "47.96.122.196"))

# from mongoengine import connect
# # 连接 MongoDB 数据库
# connect('your_database_name')

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand Down

0 comments on commit 6148a1f

Please sign in to comment.