forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: conversation variable & variable assigner node (langgenius#7222)
Signed-off-by: -LAN- <[email protected]> Co-authored-by: Joel <[email protected]> Co-authored-by: -LAN- <[email protected]>
- Loading branch information
Showing
128 changed files
with
3,355 additions
and
684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,14 @@ | |
class DifyConfig( | ||
# Packaging info | ||
PackagingInfo, | ||
|
||
# Deployment configs | ||
DeploymentConfig, | ||
|
||
# Feature configs | ||
FeatureConfig, | ||
|
||
# Middleware configs | ||
MiddlewareConfig, | ||
|
||
# Extra service configs | ||
ExtraServiceConfig, | ||
|
||
# Enterprise feature configs | ||
# **Before using, please contact [email protected] by email to inquire about licensing matters.** | ||
EnterpriseFeatureConfig, | ||
|
@@ -36,7 +31,6 @@ class DifyConfig( | |
env_file='.env', | ||
env_file_encoding='utf-8', | ||
frozen=True, | ||
|
||
# ignore extra attributes | ||
extra='ignore', | ||
) | ||
|
@@ -67,3 +61,5 @@ def HTTP_REQUEST_NODE_READABLE_MAX_TEXT_SIZE(self) -> str: | |
SSRF_PROXY_HTTPS_URL: str | None = None | ||
|
||
MODERATION_BUFFER_SIZE: int = Field(default=300, description='The buffer size for moderation.') | ||
|
||
MAX_VARIABLE_SIZE: int = Field(default=5 * 1024, description='The maximum size of a variable. default is 5KB.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
audio, | ||
completion, | ||
conversation, | ||
conversation_variables, | ||
generator, | ||
message, | ||
model_config, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from flask_restful import Resource, marshal_with, reqparse | ||
from sqlalchemy import select | ||
from sqlalchemy.orm import Session | ||
|
||
from controllers.console import api | ||
from controllers.console.app.wraps import get_app_model | ||
from controllers.console.setup import setup_required | ||
from controllers.console.wraps import account_initialization_required | ||
from extensions.ext_database import db | ||
from fields.conversation_variable_fields import paginated_conversation_variable_fields | ||
from libs.login import login_required | ||
from models import ConversationVariable | ||
from models.model import AppMode | ||
|
||
|
||
class ConversationVariablesApi(Resource): | ||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
@get_app_model(mode=AppMode.ADVANCED_CHAT) | ||
@marshal_with(paginated_conversation_variable_fields) | ||
def get(self, app_model): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('conversation_id', type=str, location='args') | ||
args = parser.parse_args() | ||
|
||
stmt = ( | ||
select(ConversationVariable) | ||
.where(ConversationVariable.app_id == app_model.id) | ||
.order_by(ConversationVariable.created_at) | ||
) | ||
if args['conversation_id']: | ||
stmt = stmt.where(ConversationVariable.conversation_id == args['conversation_id']) | ||
else: | ||
raise ValueError('conversation_id is required') | ||
|
||
# NOTE: This is a temporary solution to avoid performance issues. | ||
page = 1 | ||
page_size = 100 | ||
stmt = stmt.limit(page_size).offset((page - 1) * page_size) | ||
|
||
with Session(db.engine) as session: | ||
rows = session.scalars(stmt).all() | ||
|
||
return { | ||
'page': page, | ||
'limit': page_size, | ||
'total': len(rows), | ||
'has_more': False, | ||
'data': [ | ||
{ | ||
'created_at': row.created_at, | ||
'updated_at': row.updated_at, | ||
**row.to_variable().model_dump(), | ||
} | ||
for row in rows | ||
], | ||
} | ||
|
||
|
||
api.add_resource(ConversationVariablesApi, '/apps/<uuid:app_id>/conversation-variables') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.