master
parent
04f1586ddb
commit
d0ddb7c021
Binary file not shown.
@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WeChat-like Chat Interface</title>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<textarea id="hidep" style="display: none;"></textarea>
|
||||
<div class="container mt-5">
|
||||
<div class="chat-box border rounded">
|
||||
<div class="d-flex justify-content-between align-items-center p-3 bg-light">
|
||||
<span>Artemis</span>
|
||||
<button class="btn btn-secondary btn-sm" id="newChatButton">新聊天</button>
|
||||
</div>
|
||||
<div class="chat-content p-3" style="height: 400px; overflow-y: auto;">
|
||||
<!-- Messages will appear here -->
|
||||
</div>
|
||||
<div class="p-3">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="messageInput" placeholder="Enter your message...">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary" id="sendButton">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- jQuery and Bootstrap JS -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
|
||||
<script>
|
||||
$$(document).ready(function(){
|
||||
$$("#sendButton").click(function(){
|
||||
var message = $$("#messageInput").val().trim();
|
||||
|
||||
if (message) {
|
||||
$$(".chat-content").append(`<div class="text-right mb-2"><span class="badge badge-primary">$${message}</span></div>`);
|
||||
$$("#messageInput").val('');
|
||||
$$("#hidep").append("{'role': 'user', 'content':'"+message+"'},")
|
||||
allMessages=$$("#hidep").text()
|
||||
|
||||
$$("#sendButton").prop("disabled", true);
|
||||
|
||||
// Show loading spinner
|
||||
$$(".chat-content").append('<div id="loadingSpinner" class="text-left mb-2"><span class="spinner-border spinner-border-sm"></span> Loading...</div>');
|
||||
$$.post("/chat", { messages: allMessages }, function(response){
|
||||
if(response) {
|
||||
$$(".chat-content").append(`<div class="text-left mb-2"><span class="badge badge-secondary">$${response}</span></div>`);
|
||||
$$("#hidep").append("{'role': 'assistant', 'content':'"+response+"'},");
|
||||
$$("#sendButton").prop("disabled", false);
|
||||
$$('#loadingSpinner').remove();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$$("#newChatButton").click(function(){
|
||||
$$(".hidep").empty();
|
||||
$$(".chat-content").empty();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,47 @@
|
||||
import web
|
||||
import openai
|
||||
def chatgpt(mess):
|
||||
openai.api_key ="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"
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=mess
|
||||
)
|
||||
re=response['choices'][0]['message']['content']
|
||||
return re
|
||||
|
||||
urls = (
|
||||
'/', 'LoginPage',
|
||||
'/login', 'LoginAction',
|
||||
"/chat",'chat',
|
||||
)
|
||||
render=web.template.render('./')
|
||||
app = web.application(urls, globals())
|
||||
|
||||
class LoginPage:
|
||||
def GET(self):
|
||||
return render.index("")
|
||||
|
||||
class LoginAction:
|
||||
def POST(self):
|
||||
# 获取表单提交的数据
|
||||
i = web.input()
|
||||
username = i.get('PassID', '')
|
||||
password = i.get('Password', '')
|
||||
|
||||
# 打印提交的数据
|
||||
print(f"Username: {username}")
|
||||
print(f"Password: {password}")
|
||||
if (username=="myy" and password=="myy"):
|
||||
return render.chat()
|
||||
else :
|
||||
return render.index("密码错误!")
|
||||
class chat:
|
||||
def POST(self):
|
||||
i=web.input().messages
|
||||
i=list(eval(i))
|
||||
print(i)
|
||||
x=chatgpt(i)
|
||||
print(x)
|
||||
return x
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
@ -0,0 +1,48 @@
|
||||
$def with(e)
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bootstrap 实例</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
|
||||
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
|
||||
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row clearfix">
|
||||
<div class="col-md-12 column">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
Chat-Artemis<br><small> base on <br><s> 文心一言4.0 </s><br><s> 讯飞星火大模型2.0</s><br>
|
||||
华为盘古大模型!√</small>
|
||||
</h1>
|
||||
</div>
|
||||
<form class="form-horizontal" role="form" method="post" action="/login">
|
||||
<div class="form-group">
|
||||
<label for="PassID" class="col-sm-2 control-label">ID</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="PassID" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password" class="col-sm-2 control-label">Password</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" name="Password" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" value="inputPassword3" class="btn btn-default">Sign in</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<p>$e</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue