Difyで異なったローカルLLMエージェントを使った会話

大規模言語モデル

この記事では、DifyとOllamaを使用してローカルLLMを構築し、複数のLLMエージェントを設定してAIが社会に与える影響について議論を行ってもらいます。

前提条件

Ollamaをローカル環境で起動しておくこと:

  • 起動方法については、こちらを参照してください。

nekomata-14bがOllamaで使えること:

  • Ollamaの設定ファイルにnekomata-14bモデルを追加し、正常に稼働していることを確認してください。
nekomata-14bモデルのollamaへのインポートと使用方法
前回の記事では、Ollamaを使ってモデルファイルを作成する方法を紹介しました。今回は、その手順に従って日本語の大規模言語モデル「nekomata-14b」をインポートし、実際に使用する方法を解説します。GGUFモデルのダウンロードURLM...

Difyでnekomata-14bとllm-jp-13b-v2が使用できること:

  • Difyの設定ファイルにこれらのモデルを追加し、正常に稼働していることを確認してください。

デモ動画

ワークフローの作成

2人のエージェントのシステムプロンプトを設定:

file

file

file

file

ブロックの接続

file

完成

これで、ローカルLLMを使用して複数のエージェントがAIについて議論を行い、その結果を出力にする設定が完了しました。この設定を実行すると、各エージェントが入力に基づいて順番に応答し、多角的な議論が展開されます。

事前にOllamaをローカル環境で起動しておくことを忘れないようにしてください。

DSLファイル


app:
  description: ''
  icon: snowman_without_snow
  icon_background: '#D3F8DF'
  mode: advanced-chat
  name: Multi-Perspective AI Debate2
workflow:
  features:
    file_upload:
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
    opening_statement: ''
    retriever_resource:
      enabled: false
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        sourceType: start
        targetType: llm
      id: 1711527768326-1711527784865
      source: '1711527768326'
      sourceHandle: source
      target: '1711527784865'
      targetHandle: target
      type: custom
    - data:
        sourceType: answer
        targetType: llm
      id: 1716775953161-1716775619258
      selected: false
      source: '1716775953161'
      sourceHandle: source
      target: '1716775619258'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1711527784865-1716776291546
      source: '1711527784865'
      sourceHandle: source
      target: '1716776291546'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716776291546-1716776255897
      source: '1716776291546'
      sourceHandle: source
      target: '1716776255897'
      targetHandle: target
      type: custom
    - data:
        sourceType: answer
        targetType: llm
      id: 1716776255897-1711527861837
      source: '1716776255897'
      sourceHandle: source
      target: '1711527861837'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1711527861837-1716776460437
      source: '1711527861837'
      sourceHandle: source
      target: '1716776460437'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716776460437-1716775953161
      source: '1716776460437'
      sourceHandle: source
      target: '1716775953161'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1716775619258-1716776501998
      source: '1716775619258'
      sourceHandle: source
      target: '1716776501998'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716776501998-1711527970616
      source: '1716776501998'
      sourceHandle: source
      target: '1711527970616'
      targetHandle: target
      type: custom
    - data:
        sourceType: answer
        targetType: llm
      id: 1711527970616-1716777781638
      source: '1711527970616'
      sourceHandle: source
      target: '1716777781638'
      targetHandle: target
      type: custom
    - data:
        sourceType: llm
        targetType: template-transform
      id: 1716777781638-1716777823449
      source: '1716777781638'
      sourceHandle: source
      target: '1716777823449'
      targetHandle: target
      type: custom
    - data:
        sourceType: template-transform
        targetType: answer
      id: 1716777823449-1716777828148
      source: '1716777823449'
      sourceHandle: source
      target: '1716777828148'
      targetHandle: target
      type: custom
    nodes:
    - data:
        desc: ''
        selected: false
        title: Start
        type: start
        variables: []
      dragging: false
      height: 54
      id: '1711527768326'
      position:
        x: 80
        y: 282
      positionAbsolute:
        x: 80
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "\u697D\u89B3\u7684AI\u7814\u7A76\u8005:"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 4096
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: llm-jp-13b-v2
          provider: ollama
        prompt_template:
        - id: 6c4a2969-ff55-4a63-8711-9920b0bcf807
          role: system
          text: "\u3042\u306A\u305F\u306F\u697D\u89B3\u7684\u306AAI\u7814\u7A76\u8005\
            \u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\u306B\
            \u5BFE\u3057\u3066\u3001AI\u306E\u53EF\u80FD\u6027\u3092\u4FE1\u3058\u3001\
            \u793E\u4F1A\u3078\u306E\u30DD\u30B8\u30C6\u30A3\u30D6\u306A\u5F71\u97FF\
            \u3092\u5F37\u8ABF\u3057\u306A\u304C\u3089\u7B54\u3048\u3066\u304F\u3060\
            \u3055\u3044\u3002\n\n# \u8B70\u8AD6\u3059\u308B\u30C6\u30FC\u30DE\n{{#sys.query#}}\n\
            \u4E0A\u8A18\u306E\u30C6\u30FC\u30DE\u306B\u5F93\u3063\u3066\u7C21\u6F54\
            \u306B\u56DE\u7B54\u3057\u3066\u304F\u3060\u3055\u3044\n\n"
        selected: false
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u80051"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      dragging: false
      height: 98
      id: '1711527784865'
      position:
        x: 364
        y: 282
      positionAbsolute:
        x: 364
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005:"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 512
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: nekomata-14b
          provider: ollama
        prompt_template:
        - id: 17774cf5-0f56-4814-885b-347ea826cb02
          role: system
          text: "\u3042\u306A\u305F\u306F\u614E\u91CD\u6D3E\u306E\u7D4C\u6E08\u5B66\
            \u8005\u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\
            \u306B\u5BFE\u3057\u3066\u3001\u6280\u8853\u9769\u65B0\u304C\u52B4\u50CD\
            \u5E02\u5834\u306B\u4E0E\u3048\u308B\u5F71\u97FF\u306B\u3064\u3044\u3066\
            \u614E\u91CD\u306A\u898B\u65B9\u3092\u793A\u3057\u306A\u304C\u3089\u7B54\
            \u3048\u3066\u304F\u3060\u3055\u3044\u3002\n\n# \u8B70\u8AD6\u3059\u308B\
            \u30C6\u30FC\u30DE\n{{#sys.query#}}\n\n# \u4F1A\u8A71\u5C65\u6B74\n{{#1716776291546.output#}}\n\
            \n---\n\n\u4E0A\u8A18\u306E\u30C6\u30FC\u30DE\u3068\u4F1A\u8A71\u5C65\u6B74\
            \u306B\u5F93\u3063\u3066\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005\u3068\
            \u3057\u3066\u7C21\u6F54\u306B\u53CD\u8AD6\u3057\u3066\u304F\u3060\u3055\
            \u3044"
        selected: false
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80051"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      height: 98
      id: '1711527861837'
      position:
        x: 669.0937298845706
        y: 282
      positionAbsolute:
        x: 669.0937298845706
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716776501998.output#}}'
        desc: ''
        selected: false
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u80052_Disp"
        type: answer
        variables:
        - value_selector:
          - '1711527888920'
          - output
          variable: output
      height: 106
      id: '1711527970616'
      position:
        x: 949.0710669287596
        y: 453.4984609693367
      positionAbsolute:
        x: 949.0710669287596
        y: 453.4984609693367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "\n\n\u697D\u89B3\u7684AI\u7814\u7A76\u8005:"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 512
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: llm-jp-13b-v2
          provider: ollama
        prompt_template:
        - id: 17774cf5-0f56-4814-885b-347ea826cb02
          role: system
          text: "\u3042\u306A\u305F\u306F\u697D\u89B3\u7684\u306AAI\u7814\u7A76\u8005\
            \u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\u306B\
            \u5BFE\u3057\u3066\u3001AI\u306E\u53EF\u80FD\u6027\u3092\u4FE1\u3058\u3001\
            \u793E\u4F1A\u3078\u306E\u30DD\u30B8\u30C6\u30A3\u30D6\u306A\u5F71\u97FF\
            \u3092\u5F37\u8ABF\u3057\u306A\u304C\u3089\u7B54\u3048\u3066\u304F\u3060\
            \u3055\u3044\u3002\n\n# \u8B70\u8AD6\u3059\u308B\u30C6\u30FC\u30DE\n{{#sys.query#}}\n\
            \n# \u4F1A\u8A71\u5C65\u6B74\n{{#1716776460437.output#}}\n\n---\n\n\u4E0A\
            \u8A18\u306E\u30C6\u30FC\u30DE\u3068\u4F1A\u8A71\u5C65\u6B74\u306B\u5F93\
            \u3063\u3066\u697D\u89B3\u7684AI\u7814\u7A76\u8005\u3068\u3057\u3066\u7C21\
            \u6F54\u306B\u53CD\u8AD6\u3057\u3066\u304F\u3060\u3055\u3044\n"
        selected: false
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u80052"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      height: 98
      id: '1716775619258'
      position:
        x: 949.0710669287596
        y: 282
      positionAbsolute:
        x: 949.0710669287596
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716776460437.output#}}'
        desc: ''
        selected: false
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80051_Disp"
        type: answer
        variables:
        - value_selector:
          - '1711527888920'
          - output
          variable: output
      height: 106
      id: '1716775953161'
      position:
        x: 669.0937298845706
        y: 453.4984609693367
      positionAbsolute:
        x: 669.0937298845706
        y: 453.4984609693367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716776291546.output#}}'
        desc: ''
        selected: false
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u80051_Disp"
        type: answer
        variables: []
      height: 106
      id: '1716776255897'
      position:
        x: 364
        y: 459.59231491240956
      positionAbsolute:
        x: 364
        y: 459.59231491240956
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u697D\u89B3\u7684AI\u7814\u7A76\u80051\r\n\r\
          \n{{ LLM_output }}\r\n\r\n"
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u80051_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1711527784865'
          - text
          variable: LLM_output
      height: 54
      id: '1716776291546'
      position:
        x: 364
        y: 387.336618158831
      positionAbsolute:
        x: 364
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80051\r\
          \n\r\n{{ LLM_output }}\r\n\r\n"
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80051_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1711527861837'
          - text
          variable: LLM_output
      height: 54
      id: '1716776460437'
      position:
        x: 669.0937298845706
        y: 387.336618158831
      positionAbsolute:
        x: 669.0937298845706
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u697D\u89B3\u7684AI\u7814\u7A76\u80052\r\n\r\
          \n{{ LLM_output }}\r\n\r\n"
        title: "\u697D\u89B3\u7684AI\u7814\u7A76\u80052_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1716775619258'
          - text
          variable: LLM_output
      height: 54
      id: '1716776501998'
      position:
        x: 949.0710669287596
        y: 387.336618158831
      positionAbsolute:
        x: 949.0710669287596
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        memory:
          query_prompt_template: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005:"
          role_prefix:
            assistant: ''
            user: ''
          window:
            enabled: false
            size: 50
        model:
          completion_params:
            frequency_penalty: 0
            max_tokens: 512
            presence_penalty: 0
            temperature: 0.7
            top_p: 1
          mode: chat
          name: nekomata-14b
          provider: ollama
        prompt_template:
        - edition_type: basic
          id: 17774cf5-0f56-4814-885b-347ea826cb02
          role: system
          text: "\u3042\u306A\u305F\u306F\u614E\u91CD\u6D3E\u306E\u7D4C\u6E08\u5B66\
            \u8005\u3067\u3059\u3002\u4EE5\u4E0B\u306E\u30A4\u30F3\u30D7\u30C3\u30C8\
            \u306B\u5BFE\u3057\u3066\u3001\u6280\u8853\u9769\u65B0\u304C\u52B4\u50CD\
            \u5E02\u5834\u306B\u4E0E\u3048\u308B\u5F71\u97FF\u306B\u3064\u3044\u3066\
            \u614E\u91CD\u306A\u898B\u65B9\u3092\u793A\u3057\u306A\u304C\u3089\u7B54\
            \u3048\u3066\u304F\u3060\u3055\u3044\u3002\n\n# \u8B70\u8AD6\u3059\u308B\
            \u30C6\u30FC\u30DE\n{{#sys.query#}}\n\n# \u4F1A\u8A71\u5C65\u6B74\n{{#1716776501998.output#}}\n\
            \n---\n\n\u4E0A\u8A18\u306E\u30C6\u30FC\u30DE\u3068\u4F1A\u8A71\u5C65\u6B74\
            \u306B\u5F93\u3063\u3066\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u8005\u3068\
            \u3057\u3066\u7C21\u6F54\u306B\u53CD\u8AD6\u3057\u3066\u304F\u3060\u3055\
            \u3044"
        selected: true
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80052"
        type: llm
        variables:
        - value_selector:
          - sys
          - query
          variable: query
        vision:
          enabled: false
      height: 98
      id: '1716777781638'
      position:
        x: 1242.245842277085
        y: 282
      positionAbsolute:
        x: 1242.245842277085
        y: 282
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        selected: false
        template: "\r\n---\r\n\r\n## \u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80052\r\
          \n\r\n{{ LLM_output }}\r\n\r\n"
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80052_Ans"
        type: template-transform
        variables:
        - value_selector:
          - '1716777781638'
          - text
          variable: LLM_output
      height: 54
      id: '1716777823449'
      position:
        x: 1242.245842277085
        y: 387.336618158831
      positionAbsolute:
        x: 1242.245842277085
        y: 387.336618158831
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1716777823449.output#}}'
        desc: ''
        selected: false
        title: "\u614E\u91CD\u6D3E\u7D4C\u6E08\u5B66\u80052_Disp"
        type: answer
        variables:
        - value_selector:
          - '1711527888920'
          - output
          variable: output
      height: 106
      id: '1716777828148'
      position:
        x: 1242.245842277085
        y: 453.4984609693367
      positionAbsolute:
        x: 1242.245842277085
        y: 453.4984609693367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    viewport:
      x: -926.1069548352325
      y: -47.31394892400715
      zoom: 1.1486983549970353

コメント

タイトルとURLをコピーしました