Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/environment-vari…
Browse files Browse the repository at this point in the history
…ables-in-workflow
  • Loading branch information
laipz8200 committed Jul 22, 2024
2 parents 226f4f4 + dfb6f4f commit 5dbb90b
Show file tree
Hide file tree
Showing 57 changed files with 678 additions and 105 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Dify requires the following dependencies to build, make sure they're installed o

Dify is composed of a backend and a frontend. Navigate to the backend directory by `cd api/`, then follow the [Backend README](api/README.md) to install it. In a separate terminal, navigate to the frontend directory by `cd web/`, then follow the [Frontend README](web/README.md) to install.

Check the [installation FAQ](https://docs.dify.ai/getting-started/faq/install-faq) for a list of common issues and steps to troubleshoot.
Check the [installation FAQ](https://docs.dify.ai/learn-more/faq/self-host-faq) for a list of common issues and steps to troubleshoot.

### 5. Visit dify in your browser

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Dify 依赖以下工具和库:

Dify 由后端和前端组成。通过 `cd api/` 导航到后端目录,然后按照 [后端 README](api/README.md) 进行安装。在另一个终端中,通过 `cd web/` 导航到前端目录,然后按照 [前端 README](web/README.md) 进行安装。

查看 [安装常见问题解答](https://docs.dify.ai/getting-started/faq/install-faq) 以获取常见问题列表和故障排除步骤。
查看 [安装常见问题解答](https://docs.dify.ai/v/zh-hans/learn-more/faq/install-faq) 以获取常见问题列表和故障排除步骤。

### 5. 在浏览器中访问 Dify

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Dify はバックエンドとフロントエンドから構成されています
まず`cd api/`でバックエンドのディレクトリに移動し、[Backend README](api/README.md)に従ってインストールします。
次に別のターミナルで、`cd web/`でフロントエンドのディレクトリに移動し、[Frontend README](web/README.md)に従ってインストールしてください。

よくある問題とトラブルシューティングの手順については、[installation FAQ](https://docs.dify.ai/getting-started/faq/install-faq) を確認してください。
よくある問題とトラブルシューティングの手順については、[installation FAQ](https://docs.dify.ai/v/japanese/learn-more/faq/install-faq) を確認してください。

### 5. ブラウザで dify にアクセスする

Expand Down
7 changes: 4 additions & 3 deletions api/controllers/console/datasets/datasets.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import flask_restful
from flask import current_app, request
from flask import request
from flask_login import current_user
from flask_restful import Resource, marshal, marshal_with, reqparse
from werkzeug.exceptions import Forbidden, NotFound

import services
from configs import dify_config
from controllers.console import api
from controllers.console.apikey import api_key_fields, api_key_list
from controllers.console.app.error import ProviderNotInitializeError
Expand Down Expand Up @@ -530,7 +531,7 @@ class DatasetApiBaseUrlApi(Resource):
@account_initialization_required
def get(self):
return {
'api_base_url': (current_app.config['SERVICE_API_URL'] if current_app.config['SERVICE_API_URL']
'api_base_url': (dify_config.SERVICE_API_URL if dify_config.SERVICE_API_URL
else request.host_url.rstrip('/')) + '/v1'
}

Expand All @@ -540,7 +541,7 @@ class DatasetRetrievalSettingApi(Resource):
@login_required
@account_initialization_required
def get(self):
vector_type = current_app.config['VECTOR_STORE']
vector_type = dify_config.VECTOR_STORE
match vector_type:
case VectorType.MILVUS | VectorType.RELYT | VectorType.PGVECTOR | VectorType.TIDB_VECTOR | VectorType.CHROMA | VectorType.TENCENT | VectorType.ORACLE:
return {
Expand Down
11 changes: 6 additions & 5 deletions api/controllers/console/datasets/file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from flask import current_app, request
from flask import request
from flask_login import current_user
from flask_restful import Resource, marshal_with

import services
from configs import dify_config
from controllers.console import api
from controllers.console.datasets.error import (
FileTooLargeError,
Expand All @@ -26,9 +27,9 @@ class FileApi(Resource):
@account_initialization_required
@marshal_with(upload_config_fields)
def get(self):
file_size_limit = current_app.config.get("UPLOAD_FILE_SIZE_LIMIT")
batch_count_limit = current_app.config.get("UPLOAD_FILE_BATCH_LIMIT")
image_file_size_limit = current_app.config.get("UPLOAD_IMAGE_FILE_SIZE_LIMIT")
file_size_limit = dify_config.UPLOAD_FILE_SIZE_LIMIT
batch_count_limit = dify_config.UPLOAD_FILE_BATCH_LIMIT
image_file_size_limit = dify_config.UPLOAD_IMAGE_FILE_SIZE_LIMIT
return {
'file_size_limit': file_size_limit,
'batch_count_limit': batch_count_limit,
Expand Down Expand Up @@ -76,7 +77,7 @@ class FileSupportTypeApi(Resource):
@login_required
@account_initialization_required
def get(self):
etl_type = current_app.config['ETL_TYPE']
etl_type = dify_config.ETL_TYPE
allowed_extensions = UNSTRUCTURED_ALLOWED_EXTENSIONS if etl_type == 'Unstructured' else ALLOWED_EXTENSIONS
return {'allowed_extensions': allowed_extensions}

Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/explore/parameter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from flask import current_app
from flask_restful import fields, marshal_with

from configs import dify_config
from controllers.console import api
from controllers.console.app.error import AppUnavailableError
from controllers.console.explore.wraps import InstalledAppResource
Expand Down Expand Up @@ -78,7 +78,7 @@ def get(self, installed_app: InstalledApp):
"transfer_methods": ["remote_url", "local_file"]
}}),
'system_parameters': {
'image_file_size_limit': current_app.config.get('UPLOAD_IMAGE_FILE_SIZE_LIMIT')
'image_file_size_limit': dify_config.UPLOAD_IMAGE_FILE_SIZE_LIMIT
}
}

Expand Down
5 changes: 3 additions & 2 deletions api/controllers/console/init_validate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os

from flask import current_app, session
from flask import session
from flask_restful import Resource, reqparse

from configs import dify_config
from libs.helper import str_len
from models.model import DifySetup
from services.account_service import TenantService
Expand Down Expand Up @@ -40,7 +41,7 @@ def post(self):
return {'result': 'success'}, 201

def get_init_validate_status():
if current_app.config['EDITION'] == 'SELF_HOSTED':
if dify_config.EDITION == 'SELF_HOSTED':
if os.environ.get('INIT_PASSWORD'):
return session.get('is_init_validated') or DifySetup.query.first()

Expand Down
7 changes: 4 additions & 3 deletions api/controllers/console/setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from functools import wraps

from flask import current_app, request
from flask import request
from flask_restful import Resource, reqparse

from configs import dify_config
from libs.helper import email, get_remote_ip, str_len
from libs.password import valid_password
from models.model import DifySetup
Expand All @@ -17,7 +18,7 @@
class SetupApi(Resource):

def get(self):
if current_app.config['EDITION'] == 'SELF_HOSTED':
if dify_config.EDITION == 'SELF_HOSTED':
setup_status = get_setup_status()
if setup_status:
return {
Expand Down Expand Up @@ -77,7 +78,7 @@ def decorated(*args, **kwargs):


def get_setup_status():
if current_app.config['EDITION'] == 'SELF_HOSTED':
if dify_config.EDITION == 'SELF_HOSTED':
return DifySetup.query.first()
else:
return True
Expand Down
11 changes: 6 additions & 5 deletions api/controllers/console/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import logging

import requests
from flask import current_app
from flask_restful import Resource, reqparse

from configs import dify_config

from . import api


Expand All @@ -15,16 +16,16 @@ def get(self):
parser = reqparse.RequestParser()
parser.add_argument('current_version', type=str, required=True, location='args')
args = parser.parse_args()
check_update_url = current_app.config['CHECK_UPDATE_URL']
check_update_url = dify_config.CHECK_UPDATE_URL

result = {
'version': current_app.config['CURRENT_VERSION'],
'version': dify_config.CURRENT_VERSION,
'release_date': '',
'release_notes': '',
'can_auto_update': False,
'features': {
'can_replace_logo': current_app.config['CAN_REPLACE_LOGO'],
'model_load_balancing_enabled': current_app.config['MODEL_LB_ENABLED']
'can_replace_logo': dify_config.CAN_REPLACE_LOGO,
'model_load_balancing_enabled': dify_config.MODEL_LB_ENABLED
}
}

Expand Down
7 changes: 4 additions & 3 deletions api/controllers/console/workspace/account.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import datetime

import pytz
from flask import current_app, request
from flask import request
from flask_login import current_user
from flask_restful import Resource, fields, marshal_with, reqparse

from configs import dify_config
from constants.languages import supported_language
from controllers.console import api
from controllers.console.setup import setup_required
Expand Down Expand Up @@ -36,7 +37,7 @@ def post(self):

parser = reqparse.RequestParser()

if current_app.config['EDITION'] == 'CLOUD':
if dify_config.EDITION == 'CLOUD':
parser.add_argument('invitation_code', type=str, location='json')

parser.add_argument(
Expand All @@ -45,7 +46,7 @@ def post(self):
required=True, location='json')
args = parser.parse_args()

if current_app.config['EDITION'] == 'CLOUD':
if dify_config.EDITION == 'CLOUD':
if not args['invitation_code']:
raise ValueError('invitation_code is required')

Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/workspace/members.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import current_app
from flask_login import current_user
from flask_restful import Resource, abort, marshal_with, reqparse

import services
from configs import dify_config
from controllers.console import api
from controllers.console.setup import setup_required
from controllers.console.wraps import account_initialization_required, cloud_edition_billing_resource_check
Expand Down Expand Up @@ -48,7 +48,7 @@ def post(self):

inviter = current_user
invitation_results = []
console_web_url = current_app.config.get("CONSOLE_WEB_URL")
console_web_url = dify_config.CONSOLE_WEB_URL
for invitee_email in invitee_emails:
try:
token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, interface_language, role=invitee_role, inviter=inviter)
Expand Down
5 changes: 3 additions & 2 deletions api/controllers/console/workspace/tool_providers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import io

from flask import current_app, send_file
from flask import send_file
from flask_login import current_user
from flask_restful import Resource, reqparse
from werkzeug.exceptions import Forbidden

from configs import dify_config
from controllers.console import api
from controllers.console.setup import setup_required
from controllers.console.wraps import account_initialization_required
Expand Down Expand Up @@ -104,7 +105,7 @@ class ToolBuiltinProviderIconApi(Resource):
@setup_required
def get(self, provider):
icon_bytes, mimetype = BuiltinToolManageService.get_builtin_tool_provider_icon(provider)
icon_cache_max_age = current_app.config.get('TOOL_ICON_CACHE_MAX_AGE')
icon_cache_max_age = dify_config.TOOL_ICON_CACHE_MAX_AGE
return send_file(io.BytesIO(icon_bytes), mimetype=mimetype, max_age=icon_cache_max_age)

class ToolApiProviderAddApi(Resource):
Expand Down
7 changes: 4 additions & 3 deletions api/controllers/console/wraps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
from functools import wraps

from flask import abort, current_app, request
from flask import abort, request
from flask_login import current_user

from configs import dify_config
from controllers.console.workspace.error import AccountNotInitializedError
from services.feature_service import FeatureService
from services.operation_service import OperationService
Expand All @@ -26,7 +27,7 @@ def decorated(*args, **kwargs):
def only_edition_cloud(view):
@wraps(view)
def decorated(*args, **kwargs):
if current_app.config['EDITION'] != 'CLOUD':
if dify_config.EDITION != 'CLOUD':
abort(404)

return view(*args, **kwargs)
Expand All @@ -37,7 +38,7 @@ def decorated(*args, **kwargs):
def only_edition_self_hosted(view):
@wraps(view)
def decorated(*args, **kwargs):
if current_app.config['EDITION'] != 'SELF_HOSTED':
if dify_config.EDITION != 'SELF_HOSTED':
abort(404)

return view(*args, **kwargs)
Expand Down
12 changes: 10 additions & 2 deletions api/core/agent/fc_agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,14 @@ def extract_tool_calls(self, llm_result_chunk: LLMResultChunk) -> Union[None, li
"""
tool_calls = []
for prompt_message in llm_result_chunk.delta.message.tool_calls:
args = {}
if prompt_message.function.arguments != '':
args = json.loads(prompt_message.function.arguments)

tool_calls.append((
prompt_message.id,
prompt_message.function.name,
json.loads(prompt_message.function.arguments),
args,
))

return tool_calls
Expand All @@ -359,10 +363,14 @@ def extract_blocking_tool_calls(self, llm_result: LLMResult) -> Union[None, list
"""
tool_calls = []
for prompt_message in llm_result.message.tool_calls:
args = {}
if prompt_message.function.arguments != '':
args = json.loads(prompt_message.function.arguments)

tool_calls.append((
prompt_message.id,
prompt_message.function.name,
json.loads(prompt_message.function.arguments),
args,
))

return tool_calls
Expand Down
1 change: 1 addition & 0 deletions api/core/llm_generator/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
SUGGESTED_QUESTIONS_AFTER_ANSWER_INSTRUCTION_PROMPT = (
"Please help me predict the three most likely questions that human would ask, "
"and keeping each question under 20 characters.\n"
"MAKE SURE your output is the SAME language as the Assistant's latest response(if the main response is written in Chinese, then the language of your output must be using Chinese.)!\n"
"The output must be an array in JSON format following the specified schema:\n"
"[\"question1\",\"question2\",\"question3\"]\n"
)
Expand Down
2 changes: 1 addition & 1 deletion api/core/memory/token_buffer_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_history_prompt_messages(self, max_token_limit: int = 2000,

if curr_message_tokens > max_token_limit:
pruned_memory = []
while curr_message_tokens > max_token_limit and prompt_messages:
while curr_message_tokens > max_token_limit and len(prompt_messages)>1:
pruned_memory.append(prompt_messages.pop(0))
curr_message_tokens = self.model_instance.get_llm_num_tokens(
prompt_messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameter_rules:
use_template: max_tokens
default: 512
min: 1
max: 4096
max: 16384
- name: response_format
label:
zh_Hans: 回复格式
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameter_rules:
use_template: max_tokens
default: 512
min: 1
max: 4096
max: 16384
- name: response_format
label:
zh_Hans: 回复格式
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- openai/gpt-4o
- openai/gpt-4o-mini
- openai/gpt-4
- openai/gpt-4-32k
- openai/gpt-3.5-turbo
Expand Down
Loading

0 comments on commit 5dbb90b

Please sign in to comment.