diff --git a/config.ini b/config.ini deleted file mode 100644 index 536981d..0000000 --- a/config.ini +++ /dev/null @@ -1,14 +0,0 @@ -[app] -NAME=APP_NAME -SECRET_KEY=SOME_RANDOM_STRING -HOMEPAGE_NOTICE=1. 此网站基于openAI的API提供服务\n2. 为了限制滥用,注册后需要管理员激活才能使用\n3. 为了支持多轮对话,历史聊天会保存在服务端\n4. 网站不做关键词过滤,但请不要违反相关法律\n5. GPT生成的任何内容不保证准确性,请自行甄别 -SQLALCHEMY_DATABASE_URI=sqlite:///sqlite.db -#SQLALCHEMY_DATABASE_URI=mysql://username:password@server/db - -[network] -PROXY=http://127.0.0.1:7890 - -[openai] -API_KEY= -MODEL_NAME=gpt-3.5-turbo -PROMPT=你是一个有用的人工智能助理,你尽力确保回答的准确性,避免给出误导信息。 diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..addd9d9 --- /dev/null +++ b/config.yaml @@ -0,0 +1,20 @@ +app: + NAME: APP_NAME + SECRET_KEY: SOME_RANDOM_STRING + HOMEPAGE_NOTICE: | + 1. 此网站基于openAI的API提供服务 + 2. 为了限制滥用,注册后需要管理员激活才能使用 + 3. 为了支持多轮对话,历史聊天会保存在服务端 + 4. 网站不做关键词过滤,但请不要违反相关法律 + 5. GPT生成的任何内容不保证准确性,请自行甄别 + + SQLALCHEMY_DATABASE_URI: sqlite:///sqlite.db + # SQLALCHEMY_DATABASE_URI: mysql://username:password@server/db + +network: + PROXY: http://127.0.0.1:7890 + +openai: + API_KEY: + MODEL_NAME: gpt-3.5-turbo + PROMPT: 你是一个有用的人工智能助理,你尽力确保回答的准确性,避免给出误导信息。 diff --git a/project/__init__.py b/project/__init__.py index 3bf9a53..2038057 100644 --- a/project/__init__.py +++ b/project/__init__.py @@ -1,15 +1,15 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager -from configparser import ConfigParser +import yaml # init SQLAlchemy so we can use it later in our models db = SQLAlchemy() def create_app(): - conf = ConfigParser() - conf.read("./config.ini") + with open("./config.yaml") as config_file: + conf = yaml.safe_load(config_file) app = Flask(__name__) app.config['SECRET_KEY'] = conf['app']['SECRET_KEY'] diff --git a/project/main.py b/project/main.py index 8d11f8a..e79643b 100644 --- a/project/main.py +++ b/project/main.py @@ -12,8 +12,6 @@ main = Blueprint('main', __name__) def index(): notice = current_app.config['HOMEPAGE_NOTICE'] - if notice: - notice = notice.split("\\n") return render_template('index.html', user=current_user, homepage_notice=notice) diff --git a/project/templates/index.html b/project/templates/index.html index 99c4f30..3b99b3f 100644 --- a/project/templates/index.html +++ b/project/templates/index.html @@ -29,7 +29,8 @@ {% endwith %}
{% if homepage_notice %} - {% for notice in homepage_notice %}

{{ notice }}

{% endfor %} +

公告栏

+
{{ homepage_notice }}
{% endif %}
{% endblock content %}