Created
December 15, 2021 13:09
-
-
Save ylxdzsw/4cc04792b085422cd3ce0563ad580998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bminf | |
import threading | |
from flask import Flask | |
model = bminf.models.EVA() | |
# model = bminf.models.CPM2(memory_limit=10<<30) | |
context = [] | |
lock = threading.Lock() | |
app = Flask(__name__) | |
@app.route('/', methods=["GET"]) | |
def index(): | |
return """ | |
<script> | |
async function submit() { | |
console.log("fuck") | |
const q = document.querySelector("#input").value | |
const res = await fetch("/chat/" + encodeURIComponent(q)) | |
const txt = await res.text() | |
document.querySelector("#result").textContent = txt | |
} | |
</script> | |
<div>接口:GET https://cpm.ylxdzsw.com/chat/聊天内容</div> | |
<textarea id="input" rows="10" cols="50"></textarea> | |
<button onclick="submit()">run</button> | |
<div id="result" /> | |
""" | |
@app.route('/chat/<query>', methods=["GET"]) | |
def chat(query): | |
if len(query) > 256: | |
return "too long" | |
# if lock.locked(): | |
# return "busy" | |
lock.acquire() | |
global context | |
context = context[-4:] | |
context.append(query) | |
result = model.dialogue(context) | |
# result = model.generate(query, max_tokens=256, top_p=1.0, top_n=10, temperature=0.8, frequency_penalty=0, presence_penalty=0)[0] | |
context.append(result) | |
lock.release() | |
return result | |
app.run("127.0.0.1", port=3903) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment