fixup /stop api (#2012)

Co-authored-by: mayue <mayue05@qiyi.com>
This commit is contained in:
killpanda 2024-01-12 19:10:42 +08:00 committed by GitHub
parent f877d19c6a
commit 3ebec8fa41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,7 @@ from core.application_queue_manager import ApplicationQueueManager
from core.entities.application_entities import InvokeFrom from core.entities.application_entities import InvokeFrom
from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError
from core.model_runtime.errors.invoke import InvokeError from core.model_runtime.errors.invoke import InvokeError
from flask import Response, stream_with_context from flask import Response, stream_with_context, request
from flask_restful import reqparse from flask_restful import reqparse
from libs.helper import uuid_value from libs.helper import uuid_value
from services.completion_service import CompletionService from services.completion_service import CompletionService
@ -75,11 +75,13 @@ class CompletionApi(AppApiResource):
class CompletionStopApi(AppApiResource): class CompletionStopApi(AppApiResource):
def post(self, app_model, end_user, task_id): def post(self, app_model, _, task_id):
if app_model.mode != 'completion': if app_model.mode != 'completion':
raise AppUnavailableError() raise AppUnavailableError()
ApplicationQueueManager.set_stop_flag(task_id, InvokeFrom.SERVICE_API, end_user.id) end_user_id = request.get_json().get('user')
ApplicationQueueManager.set_stop_flag(task_id, InvokeFrom.SERVICE_API, end_user_id)
return {'result': 'success'}, 200 return {'result': 'success'}, 200
@ -139,11 +141,13 @@ class ChatApi(AppApiResource):
class ChatStopApi(AppApiResource): class ChatStopApi(AppApiResource):
def post(self, app_model, end_user, task_id): def post(self, app_model, _, task_id):
if app_model.mode != 'chat': if app_model.mode != 'chat':
raise NotChatAppError() raise NotChatAppError()
ApplicationQueueManager.set_stop_flag(task_id, InvokeFrom.SERVICE_API, end_user.id) end_user_id = request.get_json().get('user')
ApplicationQueueManager.set_stop_flag(task_id, InvokeFrom.SERVICE_API, end_user_id)
return {'result': 'success'}, 200 return {'result': 'success'}, 200