app:
  description: 原材料表記から必要なアレルゲン表示（表示義務のある主要アレルゲン名）と注意書きを生成するチェックツール
  icon: 🧾
  icon_background: '#FFEAD5'
  mode: workflow
  name: 食品製造 アレルゲン表示チェッカー
  use_icon_as_answer_icon: false
kind: app
version: 0.6.0
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      image:
        enabled: false
    opening_statement: ''
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
  graph:
    edges:
    - data:
        sourceType: start
        targetType: code
      id: start-to-code1
      source: start
      target: code1
    - data:
        sourceType: code
        targetType: llm
      id: code1-to-llm1
      source: code1
      target: llm1
    - data:
        sourceType: llm
        targetType: code
      id: llm1-to-code2
      source: llm1
      target: code2
    - data:
        sourceType: code
        targetType: end
      id: code2-to-end
      source: code2
      target: end
    nodes:
    - data:
        title: 開始
        type: start
        variables:
        - label: query
          max_length: 2048
          options: []
          required: true
          type: paragraph
          variable: query
      height: 90
      id: start
      position:
        x: 80
        y: 282
      type: custom
      width: 244
    - data:
        title: 前処理 - 原材料正規化
        type: code
        code_language: python3
        code: "def _safe_str(v):\n    \"\"\"Convert any value to string safely.\"\"\
          \"\n    if v is None:\n        return \"\"\n    if isinstance(v, list):\n\
          \        return \"\\n\".join(str(i) for i in v)\n    return str(v)\n\ndef\
          \ _safe_list(v):\n    \"\"\"Ensure value is a list.\"\"\"\n    if v is None:\n\
          \        return []\n    if isinstance(v, str):\n        return [v]\n   \
          \ if isinstance(v, list):\n        return v\n    return [v]\n\ndef main(**kwargs)\
          \ -> dict:\n    inputs = kwargs\n    raw = \"\"\n    if \"query\" in inputs\
          \ and inputs[\"query\"] is not None:\n        raw = str(inputs[\"query\"\
          ])\n    # 全角記号・不要文字を正規化\n    raw = raw.replace(\"、\", \",\").replace(\"\
          ，\", \",\").replace(\"；\", \";\").replace(\"　\", \" \")\n    raw = raw.replace(\"\
          \\r\", \"\\n\")\n    # 改行・カンマ・セミコロンで分割してトリム\n    parts = []\n    for line\
          \ in raw.split(\"\\n\"):\n        for chunk in line.split(\",\"):\n    \
          \        for sub in chunk.split(\";\"):\n                token = sub.strip()\n\
          \                if token != \"\":\n                    parts.append(token)\n\
          \    # 順序を保持して重複を除去\n    seen = []\n    normalized_list = []\n    for p\
          \ in parts:\n        if p not in seen:\n            seen.append(p)\n   \
          \         normalized_list.append(p)\n    normalized = \", \".join(normalized_list)\n\
          \    return dict(normalized=normalized)\n"
        variables:
        - value_selector:
          - start
          - query
          variable: query
        outputs:
          normalized:
            type: string
            children: null
      height: 90
      id: code1
      position:
        x: 380
        y: 282
      type: custom
      width: 244
    - data:
        title: AI判定 - アレルゲン抽出 & 表示生成
        type: llm
        model:
          provider: openai
          name: gpt-5-mini
          mode: chat
          completion_params:
            temperature: 0.3
        prompt_template:
        - role: system
          text: 'あなたは食品表示法や一般的なアレルゲン表示ガイドラインに精通した専門家アシスタントです。入力された原材料表記から、表示義務のある主要アレルゲン名（該当するもののみ）を判定し、消費者向けの注意書きを作成してください。出力は必ずJSONのみで返してください。フォーマットは次の通りに厳密に従ってください:
            {"required_labels": ["..."], "precautions": ["..."], "notes": "任意の追記事項（なければ空文字）"}。説明文や追加の解説は付けないでください。'
        - role: user
          text: '原材料: {{#code1.normalized#}}


            上記原材料に基づいて、必要なアレルゲン表示と注意書きを日本語で生成してください。'
        vision:
          enabled: false
        memory: null
        context:
          enabled: false
      height: 90
      id: llm1
      position:
        x: 680
        y: 282
      type: custom
      width: 244
    - data:
        title: 出力整形 - 表示文作成
        type: code
        code_language: python3
        code: "def _safe_str(v):\n    \"\"\"Convert any value to string safely.\"\"\
          \"\n    if v is None:\n        return \"\"\n    if isinstance(v, list):\n\
          \        return \"\\n\".join(str(i) for i in v)\n    return str(v)\n\ndef\
          \ _safe_list(v):\n    \"\"\"Ensure value is a list.\"\"\"\n    if v is None:\n\
          \        return []\n    if isinstance(v, str):\n        return [v]\n   \
          \ if isinstance(v, list):\n        return v\n    return [v]\n\ndef main(**kwargs)\
          \ -> dict:\n    inputs = kwargs\n    text = \"\"\n    if \"text\" in inputs\
          \ and inputs[\"text\"] is not None:\n        text = str(inputs[\"text\"\
          ])\n    # LLMのJSON出力をそのまま人が読みやすい形式に整形する（基本はそのまま返す）\n    result = \"判定結果:\\\
          n\" + text\n    return dict(result=result)\n"
        variables:
        - value_selector:
          - llm1
          - text
          variable: text
        outputs:
          result:
            type: string
            children: null
      height: 90
      id: code2
      position:
        x: 980
        y: 282
      type: custom
      width: 244
    - data:
        title: 終了
        type: end
        outputs:
        - value_selector:
          - code2
          - result
          variable: result
      id: end
      position:
        x: 1280
        y: 282
      type: custom
      height: 90
      width: 244
  hash: null
