Skip to content

Commit

Permalink
Merge branch 'feat/workflow-backend' into deploy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
takatost committed Mar 17, 2024
2 parents 6083a0c + 73c2b35 commit 53a89dd
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
31 changes: 31 additions & 0 deletions api/constants/model_template.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from models.model import AppMode

default_app_templates = {
Expand All @@ -10,6 +12,35 @@
}
},

# completion default mode
AppMode.COMPLETION: {
'app': {
'mode': AppMode.COMPLETION.value,
'enable_site': True,
'enable_api': True
},
'model_config': {
'model': {
"provider": "openai",
"name": "gpt-4",
"mode": "chat",
"completion_params": {}
},
'user_input_form': json.dumps([
{
"paragraph": {
"label": "Query",
"variable": "query",
"required": True,
"default": ""
}
}
]),
'pre_prompt': '{{query}}'
},

},

# chat default mode
AppMode.CHAT: {
'app': {
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from core.tools.tool_manager import ToolManager


ALLOW_CREATE_APP_MODES = ['chat', 'agent-chat', 'advanced-chat', 'workflow']
ALLOW_CREATE_APP_MODES = ['chat', 'agent-chat', 'advanced-chat', 'workflow', 'completion']


class AppListApi(Resource):
Expand Down
4 changes: 2 additions & 2 deletions api/core/workflow/nodes/code/code_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
MAX_STRING_ARRAY_LENGTH = 30
MAX_NUMBER_ARRAY_LENGTH = 1000

JAVASCRIPT_DEFAULT_CODE = """function main({args1, args2}) {
JAVASCRIPT_DEFAULT_CODE = """function main({arg1, arg2}) {
return {
result: args1 + args2
}
}"""

PYTHON_DEFAULT_CODE = """def main(args1: int, args2: int) -> dict:
PYTHON_DEFAULT_CODE = """def main(arg1: int, arg2: int) -> dict:
return {
"result": args1 + args2,
}"""
Expand Down
4 changes: 2 additions & 2 deletions api/services/app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def import_app(self, tenant_id: str, data: str, args: dict, account: Account) ->
if not workflow:
raise ValueError("Missing workflow in data argument "
"when app mode is advanced-chat or workflow")
elif app_mode in [AppMode.CHAT, AppMode.AGENT_CHAT]:
elif app_mode in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.COMPLETION]:
if not model_config_data:
raise ValueError("Missing model_config in data argument "
"when app mode is chat or agent-chat")
"when app mode is chat, agent-chat or completion")
else:
raise ValueError("Invalid app mode")

Expand Down
21 changes: 19 additions & 2 deletions api/services/workflow/workflow_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def convert_app_model_config_to_workflow(self, app_model: App,
if app_config.dataset:
knowledge_retrieval_node = self._convert_to_knowledge_retrieval_node(
new_app_mode=new_app_mode,
dataset_config=app_config.dataset
dataset_config=app_config.dataset,
model_config=app_config.model
)

if knowledge_retrieval_node:
Expand Down Expand Up @@ -359,12 +360,15 @@ def _convert_to_http_request_node(self, app_model: App,

return nodes

def _convert_to_knowledge_retrieval_node(self, new_app_mode: AppMode, dataset_config: DatasetEntity) \
def _convert_to_knowledge_retrieval_node(self, new_app_mode: AppMode,
dataset_config: DatasetEntity,
model_config: ModelConfigEntity) \
-> Optional[dict]:
"""
Convert datasets to Knowledge Retrieval Node
:param new_app_mode: new app mode
:param dataset_config: dataset
:param model_config: model config
:return:
"""
retrieve_config = dataset_config.retrieve_config
Expand All @@ -385,6 +389,19 @@ def _convert_to_knowledge_retrieval_node(self, new_app_mode: AppMode, dataset_co
"query_variable_selector": query_variable_selector,
"dataset_ids": dataset_config.dataset_ids,
"retrieval_mode": retrieve_config.retrieve_strategy.value,
"single_retrieval_config": {
"model": {
"provider": model_config.provider,
"name": model_config.model,
"mode": model_config.mode,
"completion_params": {
**model_config.parameters,
"stop": model_config.stop,
}
}
}
if retrieve_config.retrieve_strategy == DatasetRetrieveConfigEntity.RetrieveStrategy.MULTIPLE
else None,
"multiple_retrieval_config": {
"top_k": retrieve_config.top_k,
"score_threshold": retrieve_config.score_threshold,
Expand Down
22 changes: 20 additions & 2 deletions api/tests/unit_tests/services/workflow/test_workflow_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,18 @@ def test__convert_to_knowledge_retrieval_node_for_chatbot():
)
)

model_config = ModelConfigEntity(
provider='openai',
model='gpt-4',
mode='chat',
parameters={},
stop=[]
)

node = WorkflowConverter()._convert_to_knowledge_retrieval_node(
new_app_mode=new_app_mode,
dataset_config=dataset_config
dataset_config=dataset_config,
model_config=model_config
)

assert node["data"]["type"] == "knowledge-retrieval"
Expand Down Expand Up @@ -240,9 +249,18 @@ def test__convert_to_knowledge_retrieval_node_for_workflow_app():
)
)

model_config = ModelConfigEntity(
provider='openai',
model='gpt-4',
mode='chat',
parameters={},
stop=[]
)

node = WorkflowConverter()._convert_to_knowledge_retrieval_node(
new_app_mode=new_app_mode,
dataset_config=dataset_config
dataset_config=dataset_config,
model_config=model_config
)

assert node["data"]["type"] == "knowledge-retrieval"
Expand Down

0 comments on commit 53a89dd

Please sign in to comment.