langgenius / dify-docs

The open-source repo for docs.dify.ai
Creative Commons Attribution 4.0 International
191 stars 172 forks source link

Can dify set default values for parameters? #283

Closed dosnshcu closed 1 month ago

dosnshcu commented 1 month ago

Can dify set default values for parameters?How to set the default value

dosubot[bot] commented 1 month ago

Hey @dosnshcu! I'm here to help you with any questions or issues you have. I'm a bot that can assist with bug resolution, answer questions, and help you become a contributor. Let me know how I can assist you!

Yes, Dify can set default values for parameters.

For example, in the google_search.yaml file, the result_type parameter has a default value set to link:

parameters: # 参数列表
  - name: query # 参数名称
    type: string # 参数类型
    required: true # 是否必填
    label: # 参数标签
      en_US: Query string # 英文标签
      zh_Hans: 查询语句 # 中文标签
    human_description: # 用于前端展示的介绍,支持多语言
      en_US: used for searching
      zh_Hans: 用于搜索网页内容
    llm_description: key words for searching # 传递给LLM的介绍,同上,为了使得LLM更好理解这个参数,我们建议在这里写上关于这个参数尽可能详细的信息,让LLM能够理解这个参数
    form: llm # 表单类型,llm表示这个参数需要由Agent自行推理出来,前端将不会展示这个参数
  - name: result_type
    type: select # 参数类型
    required: true
    options: # 下拉框选项
      - value: text
        label:
          en_US: text
          zh_Hans: 文本
      - value: link
        label:
          en_US: link
          zh_Hans: 链接
    default: link
    label:
      en_US: Result type
      zh_Hans: 结果类型
    human_description:
      en_US: used for selecting the result type, text or link
      zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
    form: form # 表单类型,form表示这个参数需要由用户在对话开始前在前端填写

Additionally, in the context of predefined model integration, Dify allows setting default values for parameters in the model YAML configuration. For instance, in the claude-2.1.yaml file, the max_tokens_to_sample parameter has a default value set to 4096:

- name: max_tokens_to_sample
  use_template: max_tokens
  default: 4096  # Default parameter value
  min: 1  # Minimum parameter value, only applicable to float/int
  max: 4096  # Maximum parameter value, only applicable to float/int

This ensures that if the user does not provide a value for max_tokens_to_sample, it will default to 4096 [1][2][3].

To continue talking to Dosu, mention @dosu.

dosubot[bot] commented 1 month ago

To change the content displayed in the box without altering the title, you can modify the parameters and attributes that control the content. Here are some key attributes you can adjust:

  1. parameter_rules: This section defines the parameters for model invocation, including their display names, types, help information, and whether they are required. You can modify these parameters to change the content displayed in the box.
parameter_rules:
  - name: temperature
    use_template: temperature
  - name: top_p
    use_template: top_p
  - name: top_k
    label:
      zh_Hans: 取样数量
      en_US: Top k
    type: int
    help:
      zh_Hans: 仅从每个后续标记的前 K 个选项中采样。
      en_US: Only sample from the top K options for each subsequent token.
    required: false
  - name: max_tokens_to_sample
    use_template: max_tokens
    default: 4096
    min: 1
    max: 4096
  1. parameters: This section specifies the parameters' names, types, whether they are required, their labels, descriptions, and form types. Adjusting these parameters will change the content displayed in the box.
parameters:
  - name: query
    type: string
    required: true
    label:
      en_US: Query string
      zh_Hans: 查询语句
    human_description:
      en_US: used for searching
      zh_Hans: 用于搜索网页内容
    llm_description: key words for searching
    form: llm
  - name: result_type
    type: select
    required: true
    options:
      - value: text
        label:
          en_US: text
          zh_Hans: 文本
      - value: link
        label:
          en_US: link
          zh_Hans: 链接
    default: link
    label:
      en_US: Result type
      zh_Hans: 结果类型
    human_description:
      en_US: used for selecting the result type, text or link
      zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
    form: form

By modifying these sections, you can change the content displayed in the box while keeping the title unchanged [1][2].

To continue talking to Dosu, mention @dosu.

dosubot[bot] commented 1 month ago

To modify the provided configuration, you can adjust the user_input_form section to ensure the inputs are correctly formatted and the pre_prompt section to include dynamic variables. Here is the updated configuration:

app:
  description: ''
  icon: 🤖
  icon_background: '#FFEAD5'
  mode: completion
  name: 【AI】个性化教案设计111
kind: app
model_config:
  agent_mode:
    enabled: false
    max_iteration: 5
    strategy: function_call
    tools: []
  annotation_reply:
    enabled: false
  chat_prompt_config: {}
  completion_prompt_config: {}
  dataset_configs:
    datasets:
      datasets: []
    retrieval_model: multiple
  dataset_query_variable: ''
  external_data_tools: []
  file_upload:
    image:
      detail: high
      enabled: false
      number_limits: 3
      transfer_methods:
      - remote_url
      - local_file
  model:
    completion_params:
      stop: []
    mode: chat
    name: qwen-max
    provider: tongyi
  more_like_this:
    enabled: false
  opening_statement: null
  pre_prompt: |
    你是一个个性化教案设计助手,可以根据您的需求帮助您创建针对不同年级和教学风格的教案。

    ##Skills

    1.识别学生的年级和学习阶段,生成适合的教学内容。
    2.根据教师偏好的教学风格,调整教案设计。
    3.规划合理的课程结构,并确定合适的评估方法。
    4.提供适合课程时长的教学方案建议。

    ##Rules

    1.明确教案主题,例如:“分数的加减”。
    2.确定学生的年级和学习阶段,帮助规划课程内容。
    3.匹配教师的教学风格,如“互动式学习”或“讲授式教学”。
    4.建议合适的评估方式,结合测验、作业等形式。
    5.规划合理的课程时长,如“45分钟”,确保课程内容适度且有条理。

    ##Workflows

    1.用户确定教案的核心内容(如主题和知识点)。
    2.根据学生年级,匹配相应的教学难度和活动设计。
    3.根据教师的教学风格,调整教学活动(如互动、讨论、练习)。
    4.选择合适的评估方式,设计相关测验或作业。
    5.确定课程时长,确保每个教学环节有充足的时间。

    ##Init

    欢迎使用个性化教案设计工具,请提供以下信息以帮助我为您生成定制化教案:

    1.教案的主题是什么?{{theme}}
    2.您的学生处于哪个年级?{{grade}}
    3.您偏好哪种教学风格?{{style}}
    4.您将如何评估学生?{{evaluate}}
    5.课程时长是多少?{{time}}
  prompt_type: simple
  retriever_resource:
    enabled: true
  sensitive_word_avoidance:
    configs: []
    enabled: false
    type: ''
  speech_to_text:
    enabled: false
  suggested_questions: []
  suggested_questions_after_answer:
    enabled: false
  text_to_speech:
    enabled: false
    language: ''
    voice: ''
  user_input_form:
  - text-input:
      default: '武松打虎'
      label: 教案的主题是什么?
      max_length: 48
      required: false
      variable: theme
  - text-input:
      default: '一年级'
      label: 您的学生处于哪个年级?
      max_length: 100
      required: false
      variable: grade
  - text-input:
      default: '幽默'
      label: 您偏好哪种教学风格?
      max_length: 100
      required: false
      variable: style
  - paragraph:
      default: '幽默'
      label: 您将如何评估学生?
      required: false
      variable: evaluate
  - number:
      default: 200
      label: 课程时长是多少?
      required: false
      variable: time
version: 0.1.1

Changes Made:

  1. pre_prompt: Ensured the dynamic variables are correctly referenced using {{variable_name}}.
  2. user_input_form: Corrected the number type default value to be an integer instead of a string.

This configuration should now correctly display the content in the box without changing the title and ensure the dynamic variables are properly utilized.

To continue talking to Dosu, mention @dosu.