use yaml for config file
This commit is contained in:
parent
152ce7a170
commit
2eecdbaf8f
14
config.ini
14
config.ini
@ -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=你是一个有用的人工智能助理,你尽力确保回答的准确性,避免给出误导信息。
|
|
20
config.yaml
Normal file
20
config.yaml
Normal file
@ -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: 你是一个有用的人工智能助理,你尽力确保回答的准确性,避免给出误导信息。
|
@ -1,15 +1,15 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
from configparser import ConfigParser
|
import yaml
|
||||||
|
|
||||||
# init SQLAlchemy so we can use it later in our models
|
# init SQLAlchemy so we can use it later in our models
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
conf = ConfigParser()
|
with open("./config.yaml") as config_file:
|
||||||
conf.read("./config.ini")
|
conf = yaml.safe_load(config_file)
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
app.config['SECRET_KEY'] = conf['app']['SECRET_KEY']
|
app.config['SECRET_KEY'] = conf['app']['SECRET_KEY']
|
||||||
|
@ -12,8 +12,6 @@ main = Blueprint('main', __name__)
|
|||||||
def index():
|
def index():
|
||||||
|
|
||||||
notice = current_app.config['HOMEPAGE_NOTICE']
|
notice = current_app.config['HOMEPAGE_NOTICE']
|
||||||
if notice:
|
|
||||||
notice = notice.split("\\n")
|
|
||||||
return render_template('index.html', user=current_user, homepage_notice=notice)
|
return render_template('index.html', user=current_user, homepage_notice=notice)
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
{% endwith %}
|
{% endwith %}
|
||||||
<div id="homepage-notice" class="row" style="margin-top: 100px;">
|
<div id="homepage-notice" class="row" style="margin-top: 100px;">
|
||||||
{% if homepage_notice %}
|
{% if homepage_notice %}
|
||||||
{% for notice in homepage_notice %}<p>{{ notice }}</p>{% endfor %}
|
<h3 class="subtitle">公告栏</h3>
|
||||||
|
<pre>{{ homepage_notice }}</pre>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Reference in New Issue
Block a user