mirror of
https://github.com/langgenius/dify.git
synced 2026-05-23 10:29:07 +08:00
Merge branch 'main' into 4-27-app-deploy
This commit is contained in:
@ -235,10 +235,11 @@ class TokenBufferMemory:
|
||||
if isinstance(m.content, list):
|
||||
inner_msg = ""
|
||||
for content in m.content:
|
||||
if isinstance(content, TextPromptMessageContent):
|
||||
inner_msg += f"{content.data}\n"
|
||||
elif isinstance(content, ImagePromptMessageContent):
|
||||
inner_msg += "[image]\n"
|
||||
match content:
|
||||
case TextPromptMessageContent():
|
||||
inner_msg += f"{content.data}\n"
|
||||
case ImagePromptMessageContent():
|
||||
inner_msg += "[image]\n"
|
||||
|
||||
string_messages.append(f"{role}: {inner_msg.strip()}")
|
||||
else:
|
||||
|
||||
@ -79,12 +79,13 @@ class ToolLabelManager:
|
||||
:return: list of tool labels (str)
|
||||
"""
|
||||
|
||||
if isinstance(controller, ApiToolProviderController | WorkflowToolProviderController):
|
||||
provider_id = controller.provider_id
|
||||
elif isinstance(controller, BuiltinToolProviderController):
|
||||
return controller.tool_labels
|
||||
else:
|
||||
raise ValueError("Unsupported tool type")
|
||||
match controller:
|
||||
case ApiToolProviderController() | WorkflowToolProviderController():
|
||||
provider_id = controller.provider_id
|
||||
case BuiltinToolProviderController():
|
||||
return controller.tool_labels
|
||||
case _:
|
||||
raise ValueError("Unsupported tool type")
|
||||
stmt = select(ToolLabelBinding.label_name).where(
|
||||
ToolLabelBinding.tool_id == provider_id,
|
||||
ToolLabelBinding.tool_type == controller.provider_type,
|
||||
|
||||
@ -618,26 +618,27 @@ class RagPipelineService:
|
||||
for key, value in datasource_parameters.items():
|
||||
param_value = value.get("value")
|
||||
|
||||
if not param_value:
|
||||
variables_map[key] = param_value
|
||||
elif isinstance(param_value, str):
|
||||
# handle string type parameter value, check if it contains variable reference pattern
|
||||
pattern = r"\{\{#([a-zA-Z0-9_]{1,50}(?:\.[a-zA-Z0-9_][a-zA-Z0-9_]{0,29}){1,10})#\}\}"
|
||||
match = re.match(pattern, param_value)
|
||||
if match:
|
||||
# extract variable path and try to get value from user inputs
|
||||
full_path = match.group(1)
|
||||
last_part = full_path.split(".")[-1]
|
||||
variables_map[key] = user_inputs.get(last_part, param_value)
|
||||
else:
|
||||
match param_value:
|
||||
case None | "" | [] | {}:
|
||||
variables_map[key] = param_value
|
||||
case str():
|
||||
# handle string type parameter value, check if it contains variable reference pattern
|
||||
pattern = r"\{\{#([a-zA-Z0-9_]{1,50}(?:\.[a-zA-Z0-9_][a-zA-Z0-9_]{0,29}){1,10})#\}\}"
|
||||
match_result = re.match(pattern, param_value)
|
||||
if match_result:
|
||||
# extract variable path and try to get value from user inputs
|
||||
full_path = match_result.group(1)
|
||||
last_part = full_path.split(".")[-1]
|
||||
variables_map[key] = user_inputs.get(last_part, param_value)
|
||||
else:
|
||||
variables_map[key] = param_value
|
||||
case list() if param_value:
|
||||
# handle list type parameter value, check if the last element is in user inputs
|
||||
last_part = param_value[-1]
|
||||
variables_map[key] = user_inputs.get(last_part, param_value)
|
||||
case _:
|
||||
# other type directly use original value
|
||||
variables_map[key] = param_value
|
||||
elif isinstance(param_value, list) and param_value:
|
||||
# handle list type parameter value, check if the last element is in user inputs
|
||||
last_part = param_value[-1]
|
||||
variables_map[key] = user_inputs.get(last_part, param_value)
|
||||
else:
|
||||
# other type directly use original value
|
||||
variables_map[key] = param_value
|
||||
|
||||
from core.datasource.datasource_manager import DatasourceManager
|
||||
|
||||
|
||||
@ -78,32 +78,33 @@ class ToolTransformService:
|
||||
:param tenant_id: the tenant id
|
||||
:param provider: the provider dict
|
||||
"""
|
||||
if isinstance(provider, dict) and "icon" in provider:
|
||||
provider["icon"] = ToolTransformService.get_tool_provider_icon_url(
|
||||
provider_type=provider["type"], provider_name=provider["name"], icon=provider["icon"]
|
||||
)
|
||||
elif isinstance(provider, ToolProviderApiEntity):
|
||||
if provider.plugin_id:
|
||||
if isinstance(provider.icon, str):
|
||||
provider.icon = PluginService.get_plugin_icon_url(tenant_id=tenant_id, filename=provider.icon)
|
||||
if isinstance(provider.icon_dark, str) and provider.icon_dark:
|
||||
provider.icon_dark = PluginService.get_plugin_icon_url(
|
||||
tenant_id=tenant_id, filename=provider.icon_dark
|
||||
)
|
||||
else:
|
||||
provider.icon = ToolTransformService.get_tool_provider_icon_url(
|
||||
provider_type=provider.type.value, provider_name=provider.name, icon=provider.icon
|
||||
match provider:
|
||||
case dict() if "icon" in provider:
|
||||
provider["icon"] = ToolTransformService.get_tool_provider_icon_url(
|
||||
provider_type=provider["type"], provider_name=provider["name"], icon=provider["icon"]
|
||||
)
|
||||
if provider.icon_dark:
|
||||
provider.icon_dark = ToolTransformService.get_tool_provider_icon_url(
|
||||
provider_type=provider.type.value, provider_name=provider.name, icon=provider.icon_dark
|
||||
)
|
||||
elif isinstance(provider, PluginDatasourceProviderEntity):
|
||||
if provider.plugin_id:
|
||||
if isinstance(provider.declaration.identity.icon, str):
|
||||
provider.declaration.identity.icon = PluginService.get_plugin_icon_url(
|
||||
tenant_id=tenant_id, filename=provider.declaration.identity.icon
|
||||
case ToolProviderApiEntity():
|
||||
if provider.plugin_id:
|
||||
if isinstance(provider.icon, str):
|
||||
provider.icon = PluginService.get_plugin_icon_url(tenant_id=tenant_id, filename=provider.icon)
|
||||
if isinstance(provider.icon_dark, str) and provider.icon_dark:
|
||||
provider.icon_dark = PluginService.get_plugin_icon_url(
|
||||
tenant_id=tenant_id, filename=provider.icon_dark
|
||||
)
|
||||
else:
|
||||
provider.icon = ToolTransformService.get_tool_provider_icon_url(
|
||||
provider_type=provider.type.value, provider_name=provider.name, icon=provider.icon
|
||||
)
|
||||
if provider.icon_dark:
|
||||
provider.icon_dark = ToolTransformService.get_tool_provider_icon_url(
|
||||
provider_type=provider.type.value, provider_name=provider.name, icon=provider.icon_dark
|
||||
)
|
||||
case PluginDatasourceProviderEntity():
|
||||
if provider.plugin_id:
|
||||
if isinstance(provider.declaration.identity.icon, str):
|
||||
provider.declaration.identity.icon = PluginService.get_plugin_icon_url(
|
||||
tenant_id=tenant_id, filename=provider.declaration.identity.icon
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def builtin_provider_to_user_provider(
|
||||
|
||||
Reference in New Issue
Block a user