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/environment variables in workflow #6515

Merged
merged 134 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
fae197c
feat(api/workflow): Support environment variables in workflow.
laipz8200 Jun 25, 2024
211ae43
feat(api/workflow): Add environment_variables to workflow creation an…
laipz8200 Jun 25, 2024
4f7959b
feat(api/workflow): Encrypt environment variables in workflow model.
laipz8200 Jun 25, 2024
694d292
feat(api/fields): Update value field type to Raw in workflow_fields.py
laipz8200 Jun 25, 2024
13304db
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 3, 2024
a118b23
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 3, 2024
e7dc09f
fix(api/core/app/app_config/features/text_to_speech/manager.py): retu…
laipz8200 Jul 4, 2024
bc58537
refactor: Rename BaseWorkflow and BaseWorkflowCallback
laipz8200 Jul 4, 2024
97c5a80
refactor(api/core/app/app_config/base_app_config_manager.py): Remove …
laipz8200 Jul 4, 2024
c95bfe2
refactor: Improve some type hints
laipz8200 Jul 4, 2024
e04e965
fix: Fix or remove wrong type hints
laipz8200 Jul 4, 2024
dfd244f
fix: Avoid modify user inputs in start node
laipz8200 Jul 4, 2024
fc0e7f8
chore(gitignore): avoid upload .vscode in api dir.
laipz8200 Jul 5, 2024
202c2ff
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 5, 2024
1d577fd
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 5, 2024
529c7ac
add icon
JzoNgKVO Jul 2, 2024
a5f9320
env panel
JzoNgKVO Jul 3, 2024
f92977e
env modal
JzoNgKVO Jul 7, 2024
1ae8b4d
backup & restore
JzoNgKVO Jul 7, 2024
1afb6a1
export confirm mdoal
JzoNgKVO Jul 7, 2024
8be412d
update draft
JzoNgKVO Jul 8, 2024
db7ae28
end node support env output
JzoNgKVO Jul 9, 2024
d730365
if-else node support env
JzoNgKVO Jul 9, 2024
8e5fde0
llm node
JzoNgKVO Jul 9, 2024
bb43ad0
other nodes
JzoNgKVO Jul 9, 2024
6b0868c
single run form
JzoNgKVO Jul 9, 2024
7162203
remove mock data
JzoNgKVO Jul 9, 2024
84029b7
test(test_rerank): Remove duplicate test cases. (#6024)
laipz8200 Jul 6, 2024
81d2f83
Add 2 firecrawl tools : Scrape and Search (#6016)
ahasasjeb Jul 6, 2024
190db78
fix: the input field of tool panel not worked as expected (#6003)
hjlarry Jul 6, 2024
fb4fafb
feat(*): Swtich to dify_config. (#6025)
laipz8200 Jul 6, 2024
09723c9
chore: skip pip upgrade preparation in api dockerfile (#5999)
bowenliang123 Jul 6, 2024
fd7d33c
fix: token count includes base64 string of input images (#5868)
tmokmss Jul 6, 2024
a2ee187
Optimize db config (#6011)
NiuBlibing Jul 6, 2024
972a5f0
feat: support moonshot and glm base models for volcengine provider (#…
sinomoe Jul 6, 2024
ea1ea4b
chore: optimize memory fetch performance (#6039)
takatost Jul 7, 2024
3c4ac57
Fix/incorrect parameter extractor memory (#6038)
Yeuoly Jul 7, 2024
fadd11e
fix(configs): Update pydantic settings in config files (#6023)
laipz8200 Jul 7, 2024
d13b7a7
Modify slack webhook url validation to allow workflow (#6041) (#6042)
mabuchs Jul 7, 2024
f7d7cd7
Fix/6034 get random order of categories in explore and workflow is mi…
crazywoola Jul 7, 2024
f422a8b
Fix authorization header validation to handle bearer types correctly …
75py Jul 7, 2024
51aab9f
Address the issue of the absence of poetry in the development contain…
ox01024 Jul 8, 2024
823ce29
fix(api/core/helper/encrypter.py): Avoid exposing length of the secret
laipz8200 Jul 9, 2024
2883467
feat(variable): Add variable entities.
laipz8200 Jul 9, 2024
3cdc5c5
feat(workflow, variables): Add a app.variables module and a environme…
laipz8200 Jul 10, 2024
708cf4e
dsl export check
JzoNgKVO Jul 10, 2024
c90f4f3
add check for delete env
JzoNgKVO Jul 11, 2024
b7dda7d
Merge branch 'main' into tp
JzoNgKVO Jul 12, 2024
8f2346a
fix style of if-else
JzoNgKVO Jul 12, 2024
93af5e6
Merge branch 'main' into tp
JzoNgKVO Jul 12, 2024
9d598cc
correct color of style
JzoNgKVO Jul 12, 2024
2480197
feat: Pass current_user in contextvar
laipz8200 Jul 12, 2024
56654eb
feat(variables): Support build anonymous variable
laipz8200 Jul 15, 2024
807e431
feat(variables): export ArrayVariable
laipz8200 Jul 15, 2024
7dcb7d6
feat(variables): Add VariableType
laipz8200 Jul 15, 2024
eadc8ba
refactor(variable_pool): Change to `add(selector, value)`
laipz8200 Jul 15, 2024
f1ea2e7
refactor(services/tasks): Swtich to dify_config witch Pydantic (#6203)
ox01024 Jul 12, 2024
5eb7247
Fix/firecrawl parameters issue (#6213)
MatriQ Jul 12, 2024
b0d5a7d
refactor(api): switch to dify_config with Pydantic in controllers and…
Tian-Hun Jul 12, 2024
9d47b83
fix: model-provider-card-style (#6246)
zxhlyh Jul 12, 2024
7639b23
Update ernie_bot.py (#6236)
Littlesheepxy Jul 12, 2024
6d8e4bc
fix: remove the maximum length limit of "paragraph" variable (#6234)
hjlarry Jul 12, 2024
a23c99d
fix: markdown proc will remove image (#5855)
tangyoha Jul 12, 2024
f8ada21
Fix mermaid render (#6088)
jqhr Jul 12, 2024
e8824ab
Feat/add zhipu CogView 3 tool (#6210)
ox01024 Jul 13, 2024
48dfd53
fix: custom tool input number fail (#6200)
guogeer Jul 14, 2024
d1dd838
new style of tailwind
JzoNgKVO Jul 15, 2024
26a386e
chore(variables): Fix typo.
laipz8200 Jul 15, 2024
0006202
feat(variables): Add `to_markdown()`
laipz8200 Jul 15, 2024
5b14f28
feat(nodes): Switch to `VariablePool.get`
laipz8200 Jul 15, 2024
646e730
Update model provider configuration for Triton Inference Server and X…
BenjaminX Jul 15, 2024
f37e854
fix(if_else_node): back to `get_any`
laipz8200 Jul 15, 2024
3ddfa67
chore(models): Remove default value.
laipz8200 Jul 15, 2024
5edc370
fix(nodes): Fall back some nodes to `get_any`
laipz8200 Jul 15, 2024
cc46971
fix style of variable modal
JzoNgKVO Jul 15, 2024
0028494
feat(variables): Rename `TextVariable` to `StringVariable`
laipz8200 Jul 16, 2024
95e094a
fix draft sync
JzoNgKVO Jul 17, 2024
197df82
fix(api/models): Set default environment variables.
laipz8200 Jul 17, 2024
d991724
test(variables): Fix StringVariable test.
laipz8200 Jul 17, 2024
1d23f9f
fix(api/models/workflow): Fix encrypt.
laipz8200 Jul 17, 2024
ecf44d0
fix(environment_variables): Fix node single step run
laipz8200 Jul 17, 2024
4b44e13
fix(api/controllers/console/app/app.py): Update include_secret argume…
laipz8200 Jul 17, 2024
eb5b1c6
fix(api/core/workflow/nodes/tool/tool_node.py): Fix tool variable get.
laipz8200 Jul 17, 2024
b208934
refactor(api/core/tools): Refactor tools.
laipz8200 Jul 17, 2024
1f5d50b
hide env in variable assigner
JzoNgKVO Jul 18, 2024
56248a6
supoort var in http auth
JzoNgKVO Jul 18, 2024
625db5d
remove sys var in variable assigner
JzoNgKVO Jul 18, 2024
9b31e68
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 18, 2024
8f368c2
fix(contexts): Use tenant_id instead of current_user in contexts
laipz8200 Jul 18, 2024
a5c93e6
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 18, 2024
7a834f8
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 18, 2024
c81ee84
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 18, 2024
a1060a6
feat(api/core/workflow/utils/variable_template_parser.py): Add a new …
laipz8200 Jul 18, 2024
de310b7
feat(api/core/workflow/nodes/tool/tool_node.py): Switch to `parse_mix…
laipz8200 Jul 18, 2024
532f4f8
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 18, 2024
f33cb42
feat(api/core/app/segments): Add Segment model.
laipz8200 Jul 18, 2024
4dacb01
fix(api/core/workflow/nodes/answer/answer_node.py): Fix markdown form…
laipz8200 Jul 19, 2024
b639e4d
refactor(api/core/workflow/entities/variable_pool.py): Remove unused …
laipz8200 Jul 19, 2024
1ce4d82
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 19, 2024
19f4afe
chore(api/core/app/segments/segment_group.py): Rename file.
laipz8200 Jul 19, 2024
d4ed261
refactor(api/core/tools/tool/tool.py): Change type hints.
laipz8200 Jul 19, 2024
d2ec591
refactor(api/core/app/segments/parser.py): Rename `convert_mixed_temp…
laipz8200 Jul 19, 2024
85cfdc1
feat(api/core/workflow/nodes/tool/tool_node.py): mask parameters in t…
laipz8200 Jul 19, 2024
6539d1d
doc(api/core/workflow/utils/variable_template_parser.py): Add a line …
laipz8200 Jul 19, 2024
672c99a
feat(api/core/workflow/nodes/http_request/http_request_node.py): Supp…
laipz8200 Jul 19, 2024
d42d371
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 19, 2024
045c868
fix side effects of env rename
JzoNgKVO Jul 19, 2024
230f559
fix side effects of remove var
JzoNgKVO Jul 19, 2024
95b781d
chore(api/controllers/console/app/workflow.py): Add a todo comment.
laipz8200 Jul 19, 2024
e988dfe
Merge branch 'feat/environment-variables-in-workflow' of github.com:l…
laipz8200 Jul 19, 2024
e323376
prompt update revert
JzoNgKVO Jul 19, 2024
b686626
fix(api/core/workflow/nodes/llm/llm_node.py): Fix LLM node type.
laipz8200 Jul 19, 2024
7f00e54
Merge branch 'feat/environment-variables-in-workflow' of github.com:l…
laipz8200 Jul 19, 2024
330bfd2
fix(api/core/app/segments/factory.py): Allow to build a variable with…
laipz8200 Jul 19, 2024
65544af
feat(api/environment_variables): Add id to variables.
laipz8200 Jul 19, 2024
cd6f0cf
env button position
JzoNgKVO Jul 19, 2024
45a4266
variable filter fix
JzoNgKVO Jul 19, 2024
e27eaa4
variable filter fix
JzoNgKVO Jul 19, 2024
7229a6e
fix if-else env select
JzoNgKVO Jul 19, 2024
0316067
fix filter of code node
JzoNgKVO Jul 19, 2024
fc13c7a
add id for env
JzoNgKVO Jul 19, 2024
4e1d52a
fix validation of env name
JzoNgKVO Jul 19, 2024
7a96190
fix export check and styles
JzoNgKVO Jul 19, 2024
c5a4908
feat(api/core/helper/encrypter.py): Show blank if token is blank.
laipz8200 Jul 19, 2024
2f21ba0
refactor(api/core/workflow/entities/variable_pool.py): Make `environm…
laipz8200 Jul 19, 2024
f116d92
refactor(api/core/workflow/entities/variable_pool.py): remove `self.e…
laipz8200 Jul 19, 2024
a5f8f28
fix(api/core/workflow/nodes/start/start_node.py): Fix StartNode type.
laipz8200 Jul 19, 2024
f3489fc
fix secret CURD
JzoNgKVO Jul 19, 2024
04172d2
new style of header
JzoNgKVO Jul 19, 2024
28762da
add tooltip for secret env
JzoNgKVO Jul 20, 2024
226f4f4
use portal for variable modal
JzoNgKVO Jul 20, 2024
5dbb90b
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
laipz8200 Jul 22, 2024
768b992
chore(db): Make migrations
laipz8200 Jul 22, 2024
05c892c
chore(db): Remove `expire_on_commit=False`
laipz8200 Jul 22, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@ sdks/python-client/dify_client.egg-info
.vscode/*
!.vscode/launch.json
pyrightconfig.json
api/.vscode

.idea/
9 changes: 6 additions & 3 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

from configs import dify_config

if os.environ.get("DEBUG", "false").lower() != 'true':
from gevent import monkey

Expand All @@ -23,7 +21,9 @@
from flask_cors import CORS
from werkzeug.exceptions import Unauthorized

import contexts
from commands import register_commands
from configs import dify_config

# DO NOT REMOVE BELOW
from events import event_handlers
Expand Down Expand Up @@ -181,7 +181,10 @@ def load_user_from_request(request_from_flask_login):
decoded = PassportService().verify(auth_token)
user_id = decoded.get('user_id')

return AccountService.load_logged_in_account(account_id=user_id, token=auth_token)
account = AccountService.load_logged_in_account(account_id=user_id, token=auth_token)
if account:
contexts.tenant_id.set(account.current_tenant_id)
return account


@login_manager.unauthorized_handler
Expand Down
1 change: 0 additions & 1 deletion api/configs/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ class DataSetConfig(BaseSettings):
default=False,
)


class WorkspaceConfig(BaseSettings):
"""
Workspace configs
Expand Down
2 changes: 2 additions & 0 deletions api/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO: Update all string in code to use this constant
HIDDEN_VALUE = '[__HIDDEN__]'
3 changes: 3 additions & 0 deletions api/contexts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from contextvars import ContextVar

tenant_id: ContextVar[str] = ContextVar('tenant_id')
9 changes: 7 additions & 2 deletions api/controllers/console/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def post(self, app_model):
parser.add_argument('icon_background', type=str, location='json')
args = parser.parse_args()

data = AppDslService.export_dsl(app_model=app_model)
data = AppDslService.export_dsl(app_model=app_model, include_secret=True)
app = AppDslService.import_and_create_new_app(
tenant_id=current_user.current_tenant_id,
data=data,
Expand All @@ -234,8 +234,13 @@ def get(self, app_model):
if not current_user.is_editor:
raise Forbidden()

# Add include_secret params
parser = reqparse.RequestParser()
parser.add_argument('include_secret', type=inputs.boolean, default=False, location='args')
args = parser.parse_args()

return {
"data": AppDslService.export_dsl(app_model=app_model)
"data": AppDslService.export_dsl(app_model=app_model, include_secret=args['include_secret'])
}


Expand Down
19 changes: 13 additions & 6 deletions api/controllers/console/app/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from controllers.console.wraps import account_initialization_required
from core.app.apps.base_app_queue_manager import AppQueueManager
from core.app.entities.app_invoke_entities import InvokeFrom
from core.app.segments import factory
from core.errors.error import AppInvokeQuotaExceededError
from fields.workflow_fields import workflow_fields
from fields.workflow_run_fields import workflow_run_node_execution_fields
Expand Down Expand Up @@ -41,7 +42,7 @@ def get(self, app_model: App):
# The role of the current user in the ta table must be admin, owner, or editor
if not current_user.is_editor:
raise Forbidden()

# fetch draft workflow by app_model
workflow_service = WorkflowService()
workflow = workflow_service.get_draft_workflow(app_model=app_model)
Expand All @@ -64,13 +65,15 @@ def post(self, app_model: App):
if not current_user.is_editor:
raise Forbidden()

content_type = request.headers.get('Content-Type')
content_type = request.headers.get('Content-Type', '')

if 'application/json' in content_type:
parser = reqparse.RequestParser()
parser.add_argument('graph', type=dict, required=True, nullable=False, location='json')
parser.add_argument('features', type=dict, required=True, nullable=False, location='json')
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')
args = parser.parse_args()
elif 'text/plain' in content_type:
try:
Expand All @@ -84,7 +87,8 @@ def post(self, app_model: App):
args = {
'graph': data.get('graph'),
'features': data.get('features'),
'hash': data.get('hash')
'hash': data.get('hash'),
'environment_variables': data.get('environment_variables')
}
except json.JSONDecodeError:
return {'message': 'Invalid JSON data'}, 400
Expand All @@ -94,12 +98,15 @@ def post(self, app_model: App):
workflow_service = WorkflowService()

try:
environment_variables_list = args.get('environment_variables') or []
environment_variables = [factory.build_variable_from_mapping(obj) for obj in environment_variables_list]
workflow = workflow_service.sync_draft_workflow(
app_model=app_model,
graph=args.get('graph'),
features=args.get('features'),
graph=args['graph'],
features=args['features'],
unique_hash=args.get('hash'),
account=current_user
account=current_user,
environment_variables=environment_variables,
)
except WorkflowHashNotEqualError:
raise DraftWorkflowNotSync()
Expand Down
29 changes: 6 additions & 23 deletions api/core/app/app_config/base_app_config_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Union
from collections.abc import Mapping
from typing import Any

from core.app.app_config.entities import AppAdditionalFeatures, EasyUIBasedAppModelConfigFrom
from core.app.app_config.entities import AppAdditionalFeatures
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
from core.app.app_config.features.more_like_this.manager import MoreLikeThisConfigManager
from core.app.app_config.features.opening_statement.manager import OpeningStatementConfigManager
Expand All @@ -10,37 +11,19 @@
SuggestedQuestionsAfterAnswerConfigManager,
)
from core.app.app_config.features.text_to_speech.manager import TextToSpeechConfigManager
from models.model import AppMode, AppModelConfig
from models.model import AppMode


class BaseAppConfigManager:

@classmethod
def convert_to_config_dict(cls, config_from: EasyUIBasedAppModelConfigFrom,
app_model_config: Union[AppModelConfig, dict],
config_dict: Optional[dict] = None) -> dict:
"""
Convert app model config to config dict
:param config_from: app model config from
:param app_model_config: app model config
:param config_dict: app model config dict
:return:
"""
if config_from != EasyUIBasedAppModelConfigFrom.ARGS:
app_model_config_dict = app_model_config.to_dict()
config_dict = app_model_config_dict.copy()

return config_dict

@classmethod
def convert_features(cls, config_dict: dict, app_mode: AppMode) -> AppAdditionalFeatures:
def convert_features(cls, config_dict: Mapping[str, Any], app_mode: AppMode) -> AppAdditionalFeatures:
"""
Convert app config to app model config

:param config_dict: app config
:param app_mode: app mode
"""
config_dict = config_dict.copy()
config_dict = dict(config_dict.items())

additional_features = AppAdditionalFeatures()
additional_features.show_retrieve_source = RetrievalResourceConfigManager.convert(
Expand Down
5 changes: 3 additions & 2 deletions api/core/app/app_config/features/file_upload/manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Optional
from collections.abc import Mapping
from typing import Any, Optional

from core.app.app_config.entities import FileExtraConfig


class FileUploadConfigManager:
@classmethod
def convert(cls, config: dict, is_vision: bool = True) -> Optional[FileExtraConfig]:
def convert(cls, config: Mapping[str, Any], is_vision: bool = True) -> Optional[FileExtraConfig]:
"""
Convert model config to model config

Expand Down
4 changes: 2 additions & 2 deletions api/core/app/app_config/features/text_to_speech/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

class TextToSpeechConfigManager:
@classmethod
def convert(cls, config: dict) -> bool:
def convert(cls, config: dict):
"""
Convert model config to model config

:param config: model config args
"""
text_to_speech = False
text_to_speech = None
text_to_speech_dict = config.get('text_to_speech')
if text_to_speech_dict:
if text_to_speech_dict.get('enabled'):
Expand Down
12 changes: 11 additions & 1 deletion api/core/app/apps/advanced_chat/app_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextvars
import logging
import os
import threading
Expand All @@ -8,6 +9,7 @@
from flask import Flask, current_app
from pydantic import ValidationError

import contexts
from core.app.app_config.features.file_upload.manager import FileUploadConfigManager
from core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfigManager
from core.app.apps.advanced_chat.app_runner import AdvancedChatAppRunner
Expand Down Expand Up @@ -107,6 +109,7 @@ def generate(
extras=extras,
trace_manager=trace_manager
)
contexts.tenant_id.set(application_generate_entity.app_config.tenant_id)

return self._generate(
app_model=app_model,
Expand Down Expand Up @@ -173,6 +176,7 @@ def single_iteration_generate(self, app_model: App,
inputs=args['inputs']
)
)
contexts.tenant_id.set(application_generate_entity.app_config.tenant_id)

return self._generate(
app_model=app_model,
Expand Down Expand Up @@ -225,6 +229,8 @@ def _generate(self, app_model: App,
'queue_manager': queue_manager,
'conversation_id': conversation.id,
'message_id': message.id,
'user': user,
'context': contextvars.copy_context()
})

worker_thread.start()
Expand All @@ -249,7 +255,9 @@ def _generate_worker(self, flask_app: Flask,
application_generate_entity: AdvancedChatAppGenerateEntity,
queue_manager: AppQueueManager,
conversation_id: str,
message_id: str) -> None:
message_id: str,
user: Account,
context: contextvars.Context) -> None:
"""
Generate worker in a new thread.
:param flask_app: Flask app
Expand All @@ -259,6 +267,8 @@ def _generate_worker(self, flask_app: Flask,
:param message_id: message ID
:return:
"""
for var, val in context.items():
var.set(val)
with flask_app.app_context():
try:
runner = AdvancedChatAppRunner()
Expand Down
8 changes: 5 additions & 3 deletions api/core/app/apps/advanced_chat/app_runner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import os
import time
from typing import Optional, cast
from collections.abc import Mapping
from typing import Any, Optional, cast

from core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfig
from core.app.apps.advanced_chat.workflow_event_trigger_callback import WorkflowEventTriggerCallback
Expand All @@ -14,6 +15,7 @@
)
from core.app.entities.queue_entities import QueueAnnotationReplyEvent, QueueStopEvent, QueueTextChunkEvent
from core.moderation.base import ModerationException
from core.workflow.callbacks.base_workflow_callback import WorkflowCallback
from core.workflow.entities.node_entities import SystemVariable
from core.workflow.nodes.base_node import UserFrom
from core.workflow.workflow_engine_manager import WorkflowEngineManager
Expand Down Expand Up @@ -87,7 +89,7 @@ def run(self, application_generate_entity: AdvancedChatAppGenerateEntity,

db.session.close()

workflow_callbacks = [WorkflowEventTriggerCallback(
workflow_callbacks: list[WorkflowCallback] = [WorkflowEventTriggerCallback(
queue_manager=queue_manager,
workflow=workflow
)]
Expand Down Expand Up @@ -161,7 +163,7 @@ def handle_input_moderation(
self, queue_manager: AppQueueManager,
app_record: App,
app_generate_entity: AdvancedChatAppGenerateEntity,
inputs: dict,
inputs: Mapping[str, Any],
query: str,
message_id: str
) -> bool:
Expand Down
15 changes: 8 additions & 7 deletions api/core/app/apps/advanced_chat/generate_response_converter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
from collections.abc import Generator
from typing import cast
from typing import Any, cast

from core.app.apps.base_app_generate_response_converter import AppGenerateResponseConverter
from core.app.entities.task_entities import (
AppBlockingResponse,
AppStreamResponse,
ChatbotAppBlockingResponse,
ChatbotAppStreamResponse,
ErrorStreamResponse,
Expand All @@ -18,12 +20,13 @@ class AdvancedChatAppGenerateResponseConverter(AppGenerateResponseConverter):
_blocking_response_type = ChatbotAppBlockingResponse

@classmethod
def convert_blocking_full_response(cls, blocking_response: ChatbotAppBlockingResponse) -> dict:
def convert_blocking_full_response(cls, blocking_response: AppBlockingResponse) -> dict[str, Any]:
"""
Convert blocking full response.
:param blocking_response: blocking response
:return:
"""
blocking_response = cast(ChatbotAppBlockingResponse, blocking_response)
response = {
'event': 'message',
'task_id': blocking_response.task_id,
Expand All @@ -39,7 +42,7 @@ def convert_blocking_full_response(cls, blocking_response: ChatbotAppBlockingRes
return response

@classmethod
def convert_blocking_simple_response(cls, blocking_response: ChatbotAppBlockingResponse) -> dict:
def convert_blocking_simple_response(cls, blocking_response: AppBlockingResponse) -> dict[str, Any]:
"""
Convert blocking simple response.
:param blocking_response: blocking response
Expand All @@ -53,8 +56,7 @@ def convert_blocking_simple_response(cls, blocking_response: ChatbotAppBlockingR
return response

@classmethod
def convert_stream_full_response(cls, stream_response: Generator[ChatbotAppStreamResponse, None, None]) \
-> Generator[str, None, None]:
def convert_stream_full_response(cls, stream_response: Generator[AppStreamResponse, None, None]) -> Generator[str, Any, None]:
"""
Convert stream full response.
:param stream_response: stream response
Expand Down Expand Up @@ -83,8 +85,7 @@ def convert_stream_full_response(cls, stream_response: Generator[ChatbotAppStrea
yield json.dumps(response_chunk)

@classmethod
def convert_stream_simple_response(cls, stream_response: Generator[ChatbotAppStreamResponse, None, None]) \
-> Generator[str, None, None]:
def convert_stream_simple_response(cls, stream_response: Generator[AppStreamResponse, None, None]) -> Generator[str, Any, None]:
"""
Convert stream simple response.
:param stream_response: stream response
Expand Down
Loading