Compare commits
2 Commits
6f3df5fc51
...
be2bb856b0
Author | SHA1 | Date | |
---|---|---|---|
be2bb856b0 | |||
489f6b223c |
@ -4,9 +4,12 @@ from .models import User, Conversation
|
|||||||
from . import db
|
from . import db
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import openai
|
import openai
|
||||||
|
import logging
|
||||||
|
|
||||||
main = Blueprint('main', __name__)
|
main = Blueprint('main', __name__)
|
||||||
|
|
||||||
|
logger = logging.getLogger('waitress')
|
||||||
|
|
||||||
|
|
||||||
@main.route('/')
|
@main.route('/')
|
||||||
def index():
|
def index():
|
||||||
@ -99,8 +102,10 @@ def chat_post():
|
|||||||
messages=messages
|
messages=messages
|
||||||
)
|
)
|
||||||
msg_resp = openai_resp['choices'][0]['message']['content']
|
msg_resp = openai_resp['choices'][0]['message']['content']
|
||||||
except:
|
except Exception as e:
|
||||||
|
logger.error("OpenAI API request failed: %s", repr(e))
|
||||||
msg_resp = "请求错误,请尝试重发。如果持续错误,请联系管理员检查。"
|
msg_resp = "请求错误,请尝试重发。如果持续错误,请联系管理员检查。"
|
||||||
|
|
||||||
if msg_resp:
|
if msg_resp:
|
||||||
response = {"message": msg_resp, "status": "success"}
|
response = {"message": msg_resp, "status": "success"}
|
||||||
else:
|
else:
|
||||||
|
@ -7,11 +7,16 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="fixed-bottom form-inline">
|
<div class="fixed-bottom form-inline">
|
||||||
<textarea id="msgbox" class="form-control" style="width:85%; float: left; margin-bottom: 20px;" placeholder="说点什么吧"></textarea>
|
<textarea id="msgbox"
|
||||||
|
class="form-control"
|
||||||
|
style="width:85%;
|
||||||
|
float: left;
|
||||||
|
margin-bottom: 20px"
|
||||||
|
placeholder="说点什么吧"></textarea>
|
||||||
<button id="btn-send"
|
<button id="btn-send"
|
||||||
class="btn btn-info"
|
class="btn btn-info"
|
||||||
type="button"
|
type="button"
|
||||||
style="width: 10%;"
|
style="width: 10%"
|
||||||
onclick="send_message()"
|
onclick="send_message()"
|
||||||
disabled>
|
disabled>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg"
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
@ -37,8 +42,14 @@
|
|||||||
btn_send.disabled = true;
|
btn_send.disabled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
<script>
|
var textarea = document.getElementById("msgbox")
|
||||||
|
textarea.addEventListener('keydown', function(e) {
|
||||||
|
if (e.ctrlKey && e.keyCode == 13) {
|
||||||
|
send_message()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function get_history() {
|
function get_history() {
|
||||||
var msgs
|
var msgs
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
Reference in New Issue
Block a user