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
97e9ebd2
Unverified
Commit
97e9ebd2
authored
Jun 28, 2023
by
crazywoola
Committed by
GitHub
Jun 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature/add is deleted to conversations (#470)
parent
ec261aea
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
1 deletion
+99
-1
conversation.py
api/controllers/console/app/conversation.py
+41
-0
conversation.py
api/controllers/service_api/app/conversation.py
+21
-0
d3d503a3471c_add_is_deleted_to_conversations.py
.../versions/d3d503a3471c_add_is_deleted_to_conversations.py
+32
-0
model.py
api/models/model.py
+2
-0
conversation_service.py
api/services/conversation_service.py
+3
-1
No files found.
api/controllers/console/app/conversation.py
View file @
97e9ebd2
...
...
@@ -210,6 +210,26 @@ class CompletionConversationDetailApi(Resource):
return
_get_conversation
(
app_id
,
conversation_id
,
'completion'
)
@
setup_required
@
login_required
@
account_initialization_required
def
delete
(
self
,
app_id
,
conversation_id
):
app_id
=
str
(
app_id
)
conversation_id
=
str
(
conversation_id
)
app
=
_get_app
(
app_id
,
'chat'
)
conversation
=
db
.
session
.
query
(
Conversation
)
\
.
filter
(
Conversation
.
id
==
conversation_id
,
Conversation
.
app_id
==
app
.
id
)
.
first
()
if
not
conversation
:
raise
NotFound
(
"Conversation Not Exists."
)
conversation
.
is_deleted
=
True
db
.
session
.
commit
()
return
{
'result'
:
'success'
},
204
class
ChatConversationApi
(
Resource
):
simple_configs_fields
=
{
...
...
@@ -357,6 +377,27 @@ class ChatConversationDetailApi(Resource):
return
_get_conversation
(
app_id
,
conversation_id
,
'chat'
)
@
setup_required
@
login_required
@
account_initialization_required
def
delete
(
self
,
app_id
,
conversation_id
):
app_id
=
str
(
app_id
)
conversation_id
=
str
(
conversation_id
)
# get app info
app
=
_get_app
(
app_id
,
'chat'
)
conversation
=
db
.
session
.
query
(
Conversation
)
\
.
filter
(
Conversation
.
id
==
conversation_id
,
Conversation
.
app_id
==
app
.
id
)
.
first
()
if
not
conversation
:
raise
NotFound
(
"Conversation Not Exists."
)
conversation
.
is_deleted
=
True
db
.
session
.
commit
()
return
{
'result'
:
'success'
},
204
...
...
api/controllers/service_api/app/conversation.py
View file @
97e9ebd2
...
...
@@ -48,6 +48,26 @@ class ConversationApi(AppApiResource):
except
services
.
errors
.
conversation
.
LastConversationNotExistsError
:
raise
NotFound
(
"Last Conversation Not Exists."
)
class
ConversationDetailApi
(
AppApiResource
):
@
marshal_with
(
conversation_fields
)
def
delete
(
self
,
app_model
,
end_user
,
c_id
):
if
app_model
.
mode
!=
'chat'
:
raise
NotChatAppError
()
conversation_id
=
str
(
c_id
)
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'user'
,
type
=
str
,
location
=
'args'
)
args
=
parser
.
parse_args
()
if
end_user
is
None
and
args
[
'user'
]
is
not
None
:
end_user
=
create_or_update_end_user_for_user_id
(
app_model
,
args
[
'user'
])
try
:
ConversationService
.
delete
(
app_model
,
conversation_id
,
end_user
)
return
{
"result"
:
"success"
},
204
except
services
.
errors
.
conversation
.
ConversationNotExistsError
:
raise
NotFound
(
"Conversation Not Exists."
)
class
ConversationRenameApi
(
AppApiResource
):
...
...
@@ -74,3 +94,4 @@ class ConversationRenameApi(AppApiResource):
api
.
add_resource
(
ConversationRenameApi
,
'/conversations/<uuid:c_id>/name'
,
endpoint
=
'conversation_name'
)
api
.
add_resource
(
ConversationApi
,
'/conversations'
)
api
.
add_resource
(
ConversationApi
,
'/conversations/<uuid:c_id>'
,
endpoint
=
'conversation'
)
api/migrations/versions/d3d503a3471c_add_is_deleted_to_conversations.py
0 → 100644
View file @
97e9ebd2
"""add is_deleted to conversations
Revision ID: d3d503a3471c
Revises: e32f6ccb87c6
Create Date: 2023-06-27 19:13:30.897981
"""
from
alembic
import
op
import
sqlalchemy
as
sa
# revision identifiers, used by Alembic.
revision
=
'd3d503a3471c'
down_revision
=
'e32f6ccb87c6'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
# ### commands auto generated by Alembic - please adjust! ###
with
op
.
batch_alter_table
(
'conversations'
,
schema
=
None
)
as
batch_op
:
batch_op
.
add_column
(
sa
.
Column
(
'is_deleted'
,
sa
.
Boolean
(),
server_default
=
sa
.
text
(
'false'
),
nullable
=
False
))
# ### end Alembic commands ###
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
with
op
.
batch_alter_table
(
'conversations'
,
schema
=
None
)
as
batch_op
:
batch_op
.
drop_column
(
'is_deleted'
)
# ### end Alembic commands ###
api/models/model.py
View file @
97e9ebd2
...
...
@@ -206,6 +206,8 @@ class Conversation(db.Model):
messages
=
db
.
relationship
(
"Message"
,
backref
=
"conversation"
,
lazy
=
'select'
,
passive_deletes
=
"all"
)
message_annotations
=
db
.
relationship
(
"MessageAnnotation"
,
backref
=
"conversation"
,
lazy
=
'select'
,
passive_deletes
=
"all"
)
is_deleted
=
db
.
Column
(
db
.
Boolean
,
nullable
=
False
,
server_default
=
db
.
text
(
'false'
))
@
property
def
model_config
(
self
):
model_config
=
{}
...
...
api/services/conversation_service.py
View file @
97e9ebd2
...
...
@@ -16,6 +16,7 @@ class ConversationService:
return
InfiniteScrollPagination
(
data
=
[],
limit
=
limit
,
has_more
=
False
)
base_query
=
db
.
session
.
query
(
Conversation
)
.
filter
(
Conversation
.
is_deleted
==
False
,
Conversation
.
app_id
==
app_model
.
id
,
Conversation
.
from_source
==
(
'api'
if
isinstance
(
user
,
EndUser
)
else
'console'
),
Conversation
.
from_end_user_id
==
(
user
.
id
if
isinstance
(
user
,
EndUser
)
else
None
),
...
...
@@ -79,6 +80,7 @@ class ConversationService:
Conversation
.
from_source
==
(
'api'
if
isinstance
(
user
,
EndUser
)
else
'console'
),
Conversation
.
from_end_user_id
==
(
user
.
id
if
isinstance
(
user
,
EndUser
)
else
None
),
Conversation
.
from_account_id
==
(
user
.
id
if
isinstance
(
user
,
Account
)
else
None
),
Conversation
.
is_deleted
==
False
)
.
first
()
if
not
conversation
:
...
...
@@ -90,5 +92,5 @@ class ConversationService:
def
delete
(
cls
,
app_model
:
App
,
conversation_id
:
str
,
user
:
Optional
[
Union
[
Account
|
EndUser
]]):
conversation
=
cls
.
get_conversation
(
app_model
,
conversation_id
,
user
)
db
.
session
.
delete
(
conversation
)
conversation
.
is_deleted
=
True
db
.
session
.
commit
()
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