Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
d680fca9
Unverified
Commit
d680fca9
authored
May 16, 2023
by
John Wang
Committed by
GitHub
May 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: provider_response_latency type error (#45)
parent
92fb4ab4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
44 deletions
+70
-44
conversation.py
api/controllers/console/app/conversation.py
+1
-1
message.py
api/controllers/console/app/message.py
+69
-43
No files found.
api/controllers/console/app/conversation.py
View file @
d680fca9
...
...
@@ -45,7 +45,7 @@ message_detail_fields = {
'message_tokens'
:
fields
.
Integer
,
'answer'
:
fields
.
String
,
'answer_tokens'
:
fields
.
Integer
,
'provider_response_latency'
:
fields
.
Integer
,
'provider_response_latency'
:
fields
.
Float
,
'from_source'
:
fields
.
String
,
'from_end_user_id'
:
fields
.
String
,
'from_account_id'
:
fields
.
String
,
...
...
api/controllers/console/app/message.py
View file @
d680fca9
...
...
@@ -26,46 +26,46 @@ from services.errors.conversation import ConversationNotExistsError
from
services.errors.message
import
MessageNotExistsError
from
services.message_service
import
MessageService
class
ChatMessageApi
(
Resource
):
account_fields
=
{
'id'
:
fields
.
String
,
'name'
:
fields
.
String
,
'email'
:
fields
.
String
}
feedback_fields
=
{
'rating
'
:
fields
.
String
,
'content
'
:
fields
.
String
,
'from_source'
:
fields
.
String
,
'from_end_user_id'
:
fields
.
String
,
'from_account'
:
fields
.
Nested
(
account_fields
,
allow_null
=
True
),
}
annotation_fields
=
{
'content'
:
fields
.
String
,
'account'
:
fields
.
Nested
(
account_fields
,
allow_null
=
True
),
'created_at'
:
TimestampField
}
message_detail_fields
=
{
'id'
:
fields
.
String
,
'conversation_id
'
:
fields
.
String
,
'inputs
'
:
fields
.
Raw
,
'query'
:
fields
.
String
,
'message'
:
fields
.
Raw
,
'message
_tokens'
:
fields
.
Integer
,
'answer'
:
fields
.
String
,
'answer_tokens'
:
fields
.
Integer
,
'provider_response_latency'
:
fields
.
Integer
,
'from_source
'
:
fields
.
String
,
'from_end_user_id'
:
fields
.
String
,
'from_account_id'
:
fields
.
String
,
'feedbacks'
:
fields
.
List
(
fields
.
Nested
(
feedback_fields
)),
'annotation'
:
fields
.
Nested
(
annotation_fields
,
allow_null
=
True
),
'created_at'
:
TimestampField
}
account_fields
=
{
'id'
:
fields
.
String
,
'name'
:
fields
.
String
,
'email'
:
fields
.
String
}
feedback_fields
=
{
'rating'
:
fields
.
String
,
'content'
:
fields
.
String
,
'from_source
'
:
fields
.
String
,
'from_end_user_id
'
:
fields
.
String
,
'from_account'
:
fields
.
Nested
(
account_fields
,
allow_null
=
True
)
,
}
annotation_fields
=
{
'content'
:
fields
.
String
,
'account'
:
fields
.
Nested
(
account_fields
,
allow_null
=
True
),
'created_at'
:
TimestampField
}
message_detail_fields
=
{
'id'
:
fields
.
String
,
'conversation_id'
:
fields
.
String
,
'inputs'
:
fields
.
Raw
,
'query
'
:
fields
.
String
,
'message
'
:
fields
.
Raw
,
'message_tokens'
:
fields
.
Integer
,
'answer'
:
fields
.
String
,
'answer
_tokens'
:
fields
.
Integer
,
'provider_response_latency'
:
fields
.
Float
,
'from_source'
:
fields
.
String
,
'from_end_user_id'
:
fields
.
String
,
'from_account_id
'
:
fields
.
String
,
'feedbacks'
:
fields
.
List
(
fields
.
Nested
(
feedback_fields
))
,
'annotation'
:
fields
.
Nested
(
annotation_fields
,
allow_null
=
True
)
,
'created_at'
:
TimestampField
}
class
ChatMessageListApi
(
Resource
):
message_infinite_scroll_pagination_fields
=
{
'limit'
:
fields
.
Integer
,
'has_more'
:
fields
.
Boolean
,
...
...
@@ -253,7 +253,8 @@ class MessageMoreLikeThisApi(Resource):
message_id
=
str
(
message_id
)
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
()
streaming
=
args
[
'response_mode'
]
==
'streaming'
...
...
@@ -301,7 +302,8 @@ def compact_response(response: Union[dict | Generator]) -> Response:
except
QuotaExceededError
:
yield
"data: "
+
json
.
dumps
(
api
.
handle_error
(
ProviderQuotaExceededError
())
.
get_json
())
+
"
\n\n
"
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
,
LLMRateLimitError
,
LLMAuthorizationError
)
as
e
:
yield
"data: "
+
json
.
dumps
(
api
.
handle_error
(
CompletionRequestError
(
str
(
e
)))
.
get_json
())
+
"
\n\n
"
...
...
@@ -353,9 +355,33 @@ class MessageSuggestedQuestionApi(Resource):
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
(
MessageSuggestedQuestionApi
,
'/apps/<uuid:app_id>/chat-messages/<uuid:message_id>/suggested-questions'
)
api
.
add_resource
(
ChatMessage
Api
,
'/apps/<uuid:app_id>/chat-messages'
,
endpoint
=
'
chat_messages'
)
api
.
add_resource
(
ChatMessage
ListApi
,
'/apps/<uuid:app_id>/chat-messages'
,
endpoint
=
'console_
chat_messages'
)
api
.
add_resource
(
MessageFeedbackApi
,
'/apps/<uuid:app_id>/feedbacks'
)
api
.
add_resource
(
MessageAnnotationApi
,
'/apps/<uuid:app_id>/annotations'
)
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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment