Compare commits

...

2 Commits

Author SHA1 Message Date
be2bb856b0 add log for openai api request failure 2023-04-18 21:38:59 +08:00
489f6b223c ctrl+enter to send message 2023-04-18 21:38:34 +08:00
2 changed files with 21 additions and 5 deletions

View File

@ -4,9 +4,12 @@ from .models import User, Conversation
from . import db
from datetime import datetime, timedelta
import openai
import logging
main = Blueprint('main', __name__)
logger = logging.getLogger('waitress')
@main.route('/')
def index():
@ -99,8 +102,10 @@ def chat_post():
messages=messages
)
msg_resp = openai_resp['choices'][0]['message']['content']
except:
except Exception as e:
logger.error("OpenAI API request failed: %s", repr(e))
msg_resp = "请求错误,请尝试重发。如果持续错误,请联系管理员检查。"
if msg_resp:
response = {"message": msg_resp, "status": "success"}
else:

View File

@ -7,11 +7,16 @@
</ul>
</div>
<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"
class="btn btn-info"
type="button"
style="width: 10%;"
style="width: 10%"
onclick="send_message()"
disabled>
<svg xmlns="http://www.w3.org/2000/svg"
@ -37,8 +42,14 @@
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() {
var msgs
$.ajax({