Unverified Commit d680fca9 authored by John Wang's avatar John Wang Committed by GitHub

fix: provider_response_latency type error (#45)

parent 92fb4ab4
...@@ -45,7 +45,7 @@ message_detail_fields = { ...@@ -45,7 +45,7 @@ message_detail_fields = {
'message_tokens': fields.Integer, 'message_tokens': fields.Integer,
'answer': fields.String, 'answer': fields.String,
'answer_tokens': fields.Integer, 'answer_tokens': fields.Integer,
'provider_response_latency': fields.Integer, 'provider_response_latency': fields.Float,
'from_source': fields.String, 'from_source': fields.String,
'from_end_user_id': fields.String, 'from_end_user_id': fields.String,
'from_account_id': fields.String, 'from_account_id': fields.String,
......
...@@ -26,46 +26,46 @@ from services.errors.conversation import ConversationNotExistsError ...@@ -26,46 +26,46 @@ from services.errors.conversation import ConversationNotExistsError
from services.errors.message import MessageNotExistsError from services.errors.message import MessageNotExistsError
from services.message_service import MessageService from services.message_service import MessageService
account_fields = {
class ChatMessageApi(Resource): 'id': fields.String,
account_fields = { 'name': fields.String,
'id': fields.String, 'email': fields.String
'name': fields.String, }
'email': fields.String
} feedback_fields = {
'rating': fields.String,
feedback_fields = { 'content': fields.String,
'rating': fields.String, 'from_source': fields.String,
'content': fields.String, 'from_end_user_id': fields.String,
'from_source': fields.String, 'from_account': fields.Nested(account_fields, allow_null=True),
'from_end_user_id': fields.String, }
'from_account': fields.Nested(account_fields, allow_null=True),
} annotation_fields = {
'content': fields.String,
annotation_fields = { 'account': fields.Nested(account_fields, allow_null=True),
'content': fields.String, 'created_at': TimestampField
'account': fields.Nested(account_fields, allow_null=True), }
'created_at': TimestampField
} message_detail_fields = {
'id': fields.String,
message_detail_fields = { 'conversation_id': fields.String,
'id': fields.String, 'inputs': fields.Raw,
'conversation_id': fields.String, 'query': fields.String,
'inputs': fields.Raw, 'message': fields.Raw,
'query': fields.String, 'message_tokens': fields.Integer,
'message': fields.Raw, 'answer': fields.String,
'message_tokens': fields.Integer, 'answer_tokens': fields.Integer,
'answer': fields.String, 'provider_response_latency': fields.Float,
'answer_tokens': fields.Integer, 'from_source': fields.String,
'provider_response_latency': fields.Integer, 'from_end_user_id': fields.String,
'from_source': fields.String, 'from_account_id': fields.String,
'from_end_user_id': fields.String, 'feedbacks': fields.List(fields.Nested(feedback_fields)),
'from_account_id': fields.String, 'annotation': fields.Nested(annotation_fields, allow_null=True),
'feedbacks': fields.List(fields.Nested(feedback_fields)), 'created_at': TimestampField
'annotation': fields.Nested(annotation_fields, allow_null=True), }
'created_at': TimestampField
}
class ChatMessageListApi(Resource):
message_infinite_scroll_pagination_fields = { message_infinite_scroll_pagination_fields = {
'limit': fields.Integer, 'limit': fields.Integer,
'has_more': fields.Boolean, 'has_more': fields.Boolean,
...@@ -253,7 +253,8 @@ class MessageMoreLikeThisApi(Resource): ...@@ -253,7 +253,8 @@ class MessageMoreLikeThisApi(Resource):
message_id = str(message_id) message_id = str(message_id)
parser = reqparse.RequestParser() parser = reqparse.RequestParser()
parser.add_argument('response_mode', type=str, required=True, choices=['blocking', 'streaming'], location='args') parser.add_argument('response_mode', type=str, required=True, choices=['blocking', 'streaming'],
location='args')
args = parser.parse_args() args = parser.parse_args()
streaming = args['response_mode'] == 'streaming' streaming = args['response_mode'] == 'streaming'
...@@ -301,7 +302,8 @@ def compact_response(response: Union[dict | Generator]) -> Response: ...@@ -301,7 +302,8 @@ def compact_response(response: Union[dict | Generator]) -> Response:
except QuotaExceededError: except QuotaExceededError:
yield "data: " + json.dumps(api.handle_error(ProviderQuotaExceededError()).get_json()) + "\n\n" yield "data: " + json.dumps(api.handle_error(ProviderQuotaExceededError()).get_json()) + "\n\n"
except ModelCurrentlyNotSupportError: except ModelCurrentlyNotSupportError:
yield "data: " + json.dumps(api.handle_error(ProviderModelCurrentlyNotSupportError()).get_json()) + "\n\n" yield "data: " + json.dumps(
api.handle_error(ProviderModelCurrentlyNotSupportError()).get_json()) + "\n\n"
except (LLMBadRequestError, LLMAPIConnectionError, LLMAPIUnavailableError, except (LLMBadRequestError, LLMAPIConnectionError, LLMAPIUnavailableError,
LLMRateLimitError, LLMAuthorizationError) as e: LLMRateLimitError, LLMAuthorizationError) as e:
yield "data: " + json.dumps(api.handle_error(CompletionRequestError(str(e))).get_json()) + "\n\n" yield "data: " + json.dumps(api.handle_error(CompletionRequestError(str(e))).get_json()) + "\n\n"
...@@ -353,9 +355,33 @@ class MessageSuggestedQuestionApi(Resource): ...@@ -353,9 +355,33 @@ class MessageSuggestedQuestionApi(Resource):
return {'data': questions} return {'data': questions}
class MessageApi(Resource):
@setup_required
@login_required
@account_initialization_required
@marshal_with(message_detail_fields)
def get(self, app_id, message_id):
app_id = str(app_id)
message_id = str(message_id)
# get app info
app_model = _get_app(app_id, 'chat')
message = db.session.query(Message).filter(
Message.id == message_id,
Message.app_id == app_model.id
).first()
if not message:
raise NotFound("Message Not Exists.")
return message
api.add_resource(MessageMoreLikeThisApi, '/apps/<uuid:app_id>/completion-messages/<uuid:message_id>/more-like-this') api.add_resource(MessageMoreLikeThisApi, '/apps/<uuid:app_id>/completion-messages/<uuid:message_id>/more-like-this')
api.add_resource(MessageSuggestedQuestionApi, '/apps/<uuid:app_id>/chat-messages/<uuid:message_id>/suggested-questions') api.add_resource(MessageSuggestedQuestionApi, '/apps/<uuid:app_id>/chat-messages/<uuid:message_id>/suggested-questions')
api.add_resource(ChatMessageApi, '/apps/<uuid:app_id>/chat-messages', endpoint='chat_messages') api.add_resource(ChatMessageListApi, '/apps/<uuid:app_id>/chat-messages', endpoint='console_chat_messages')
api.add_resource(MessageFeedbackApi, '/apps/<uuid:app_id>/feedbacks') api.add_resource(MessageFeedbackApi, '/apps/<uuid:app_id>/feedbacks')
api.add_resource(MessageAnnotationApi, '/apps/<uuid:app_id>/annotations') api.add_resource(MessageAnnotationApi, '/apps/<uuid:app_id>/annotations')
api.add_resource(MessageAnnotationCountApi, '/apps/<uuid:app_id>/annotations/count') api.add_resource(MessageAnnotationCountApi, '/apps/<uuid:app_id>/annotations/count')
api.add_resource(MessageApi, '/apps/<uuid:app_id>/messages/<uuid:message_id>', endpoint='console_message')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment