Add a /api/v1/stop-stream API that allows the user to interrupt the generation (#2392)

This commit is contained in:
Yiximail 2023-05-31 09:03:40 +08:00 committed by GitHub
parent ebcadc0042
commit 4715123f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ from threading import Thread
from extensions.api.util import build_parameters, try_start_cloudflared from extensions.api.util import build_parameters, try_start_cloudflared
from modules import shared from modules import shared
from modules.chat import generate_chat_reply from modules.chat import generate_chat_reply
from modules.text_generation import encode, generate_reply from modules.text_generation import encode, generate_reply, stop_everything_event
class Handler(BaseHTTPRequestHandler): class Handler(BaseHTTPRequestHandler):
@ -78,6 +78,19 @@ class Handler(BaseHTTPRequestHandler):
self.wfile.write(response.encode('utf-8')) self.wfile.write(response.encode('utf-8'))
elif self.path == '/api/v1/stop-stream':
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
stop_everything_event()
response = json.dumps({
'results': 'success'
})
self.wfile.write(response.encode('utf-8'))
elif self.path == '/api/v1/token-count': elif self.path == '/api/v1/token-count':
self.send_response(200) self.send_response(200)
self.send_header('Content-Type', 'application/json') self.send_header('Content-Type', 'application/json')