Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: conversation variable & variable assigner node #7222

Merged
merged 73 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
375a07a
feat: var struct
iamjoel Jul 16, 2024
e915ddf
feat: add var assigner title and icons
iamjoel Jul 16, 2024
e4b738b
feat: support var picker and get var type
iamjoel Jul 16, 2024
dfc993e
feat: write mode card
iamjoel Jul 16, 2024
035a001
feat: support show number plus
iamjoel Jul 16, 2024
287073f
feat: assigner node
iamjoel Jul 17, 2024
bbf64b9
feat: support string value
iamjoel Jul 17, 2024
c96fafa
feat: support number value
iamjoel Jul 17, 2024
21660db
feat: support object type
iamjoel Jul 17, 2024
3eb9eea
feat: support array file
iamjoel Jul 17, 2024
7141770
feat: array type struct
iamjoel Jul 17, 2024
122a2c5
assigner node support env
JzoNgKVO Jul 22, 2024
f95a6ec
Merge branch 'main' into feat/variable-assigner
iamjoel Jul 24, 2024
189dcc5
fix: constant field no schema error
iamjoel Jul 24, 2024
a4c179e
feat: type value ui to ui design
iamjoel Jul 24, 2024
c027b59
feat: code editor support element
iamjoel Jul 24, 2024
0c02fdf
feat: json example
iamjoel Jul 24, 2024
2fe51dd
fix: not select node show
iamjoel Jul 24, 2024
842ab01
fix: placeholder out of editor
iamjoel Jul 24, 2024
003b4b1
fix: height flash
iamjoel Jul 24, 2024
a8bbed2
feat: support icon to left
iamjoel Jul 24, 2024
1ceed84
fix: object value icon to left
iamjoel Jul 24, 2024
d9182f1
feat: edit obj support key
iamjoel Jul 24, 2024
2709336
feat: new var select trigger
iamjoel Jul 24, 2024
6491a9f
fix: constant type popup with
iamjoel Jul 24, 2024
2732dad
fix: var type value picker
iamjoel Jul 24, 2024
a192e4d
fix: not show number constant value
iamjoel Jul 25, 2024
b1d949d
fix: set value not align
iamjoel Jul 25, 2024
0dfb61a
feat: string number valid
iamjoel Jul 25, 2024
69a2dc7
feat: other value type valid
iamjoel Jul 25, 2024
c9eac4b
fix: var selector ui
iamjoel Jul 25, 2024
398ea52
conversation variable panel
JzoNgKVO Jul 24, 2024
80148b0
update style of variable item
JzoNgKVO Jul 25, 2024
65d5415
conversation variable modal
JzoNgKVO Jul 25, 2024
3e71136
default value
JzoNgKVO Jul 25, 2024
80e8129
array string & array number
JzoNgKVO Jul 26, 2024
0cc6256
conversation variable CURD
JzoNgKVO Jul 26, 2024
3c38e0b
Merge branch 'main' into tp
JzoNgKVO Jul 26, 2024
74ce50d
Merge branch 'main' into tp
JzoNgKVO Jul 26, 2024
f5ef56e
new style of preview
JzoNgKVO Jul 29, 2024
a43a589
use conversation variable
JzoNgKVO Jul 29, 2024
4964ca0
fix converdation variable use
JzoNgKVO Jul 29, 2024
52d637a
step run
JzoNgKVO Jul 29, 2024
60dca1f
chore: var assigner to new
iamjoel Jul 30, 2024
f2acce1
fix: not support append var change to append
iamjoel Jul 30, 2024
350912e
chore: change copywrite
iamjoel Jul 30, 2024
f1d7b2a
chore: not chose self
iamjoel Jul 30, 2024
5edfbac
chore: handle write mode ui
iamjoel Jul 30, 2024
df10424
draft sync
JzoNgKVO Jul 30, 2024
6f69202
conversation variable modal in preview
JzoNgKVO Jul 30, 2024
bd44769
Merge branch 'main' into feat/variable-assigner
iamjoel Jul 30, 2024
482879e
feat: use new option card component
iamjoel Jul 30, 2024
6cde84c
chore: support selector value badge
iamjoel Jul 30, 2024
2fa4b5a
fix: can choose same variable and can overwrite
iamjoel Jul 31, 2024
23e2402
support json edit in type object
JzoNgKVO Jul 31, 2024
c11e0c7
conversation variable modal data fetch
JzoNgKVO Aug 2, 2024
8165018
draft sync
JzoNgKVO Aug 2, 2024
365c679
default value for conversation value
JzoNgKVO Aug 5, 2024
cae482a
variable assigner only support coversation variable
JzoNgKVO Aug 6, 2024
8c52beb
add tip for conversation var
JzoNgKVO Aug 6, 2024
29cdfcd
add doc link
JzoNgKVO Aug 6, 2024
183f7fa
fix: condition value not support conversatioin var
iamjoel Aug 7, 2024
e4c2979
chore: assigner node describe
iamjoel Aug 12, 2024
142d802
chore: show disabled
iamjoel Aug 12, 2024
dded4c2
mrege main
iamjoel Aug 12, 2024
324ce23
fix: option border
iamjoel Aug 12, 2024
68052a8
add tip for write mode
JzoNgKVO Aug 12, 2024
72428f5
fix: link href
iamjoel Aug 12, 2024
eb49c20
fix: en links
iamjoel Aug 12, 2024
33070ce
fix: chinese var assignment link
iamjoel Aug 12, 2024
abbd8b3
feat(api/workflow): Backend support for conversation variables.
laipz8200 Jul 24, 2024
384c4e6
Merge branch 'feat/conversation-level-variables' into feat/variable-a…
laipz8200 Aug 13, 2024
bee440a
chore(db): Make a migration for conversation variables.
laipz8200 Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions api/configs/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 business@dify.ai by email to inquire about licensing matters.**
EnterpriseFeatureConfig,
Expand All @@ -36,7 +31,6 @@ class DifyConfig(
env_file='.env',
env_file_encoding='utf-8',
frozen=True,

# ignore extra attributes
extra='ignore',
)
Expand Down Expand Up @@ -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.')
1 change: 1 addition & 0 deletions api/controllers/console/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
audio,
completion,
conversation,
conversation_variables,
generator,
message,
model_config,
Expand Down
61 changes: 61 additions & 0 deletions api/controllers/console/app/conversation_variables.py
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')
7 changes: 6 additions & 1 deletion api/controllers/console/app/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def post(self, app_model: App):
parser.add_argument('hash', type=str, required=False, location='json')
# TODO: set this to required=True after frontend is updated
parser.add_argument('environment_variables', type=list, required=False, location='json')
parser.add_argument('conversation_variables', type=list, required=False, location='json')
args = parser.parse_args()
elif 'text/plain' in content_type:
try:
Expand All @@ -88,7 +89,8 @@ def post(self, app_model: App):
'graph': data.get('graph'),
'features': data.get('features'),
'hash': data.get('hash'),
'environment_variables': data.get('environment_variables')
'environment_variables': data.get('environment_variables'),
'conversation_variables': data.get('conversation_variables'),
}
except json.JSONDecodeError:
return {'message': 'Invalid JSON data'}, 400
Expand All @@ -100,13 +102,16 @@ def post(self, app_model: App):
try:
environment_variables_list = args.get('environment_variables') or []
environment_variables = [factory.build_variable_from_mapping(obj) for obj in environment_variables_list]
conversation_variables_list = args.get('conversation_variables') or []
conversation_variables = [factory.build_variable_from_mapping(obj) for obj in conversation_variables_list]
workflow = workflow_service.sync_draft_workflow(
app_model=app_model,
graph=args['graph'],
features=args['features'],
unique_hash=args.get('hash'),
account=current_user,
environment_variables=environment_variables,
conversation_variables=conversation_variables,
)
except WorkflowHashNotEqualError:
raise DraftWorkflowNotSync()
Expand Down
8 changes: 2 additions & 6 deletions api/core/app/app_config/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

from pydantic import BaseModel

from core.file.file_obj import FileExtraConfig
from core.model_runtime.entities.message_entities import PromptMessageRole
from models.model import AppMode
from models import AppMode


class ModelConfigEntity(BaseModel):
Expand Down Expand Up @@ -200,11 +201,6 @@ class TracingConfigEntity(BaseModel):
tracing_provider: str


class FileExtraConfig(BaseModel):
"""
File Upload Entity.
"""
image_config: Optional[dict[str, Any]] = None


class AppAdditionalFeatures(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion api/core/app/app_config/features/file_upload/manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Mapping
from typing import Any, Optional

from core.app.app_config.entities import FileExtraConfig
from core.file.file_obj import FileExtraConfig


class FileUploadConfigManager:
Expand Down
6 changes: 2 additions & 4 deletions api/core/app/apps/advanced_chat/app_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def generate(
contexts.tenant_id.set(application_generate_entity.app_config.tenant_id)

return self._generate(
app_model=app_model,
workflow=workflow,
user=user,
invoke_from=invoke_from,
Expand Down Expand Up @@ -180,7 +179,6 @@ def single_iteration_generate(self, app_model: App,
contexts.tenant_id.set(application_generate_entity.app_config.tenant_id)

return self._generate(
app_model=app_model,
workflow=workflow,
user=user,
invoke_from=InvokeFrom.DEBUGGER,
Expand All @@ -189,12 +187,12 @@ def single_iteration_generate(self, app_model: App,
stream=stream
)

def _generate(self, app_model: App,
def _generate(self, *,
workflow: Workflow,
user: Union[Account, EndUser],
invoke_from: InvokeFrom,
application_generate_entity: AdvancedChatAppGenerateEntity,
conversation: Conversation = None,
conversation: Conversation | None = None,
stream: bool = True) \
-> Union[dict, Generator[dict, None, None]]:
is_first_conversation = False
Expand Down
Loading