357 lines
17 KiB
Python
357 lines
17 KiB
Python
# Copyright (c) 2025 Patrick Motsch
|
|
# AI node definitions - map to methodAi actions.
|
|
|
|
from modules.shared.i18nRegistry import t
|
|
|
|
from modules.features.graphicalEditor.nodeDefinitions.contextPickerHelp import (
|
|
CONTEXT_BUILDER_PARAM_DESCRIPTION,
|
|
)
|
|
|
|
# Shared authoritative DataPicker paths (same handover idea as ``context.extractContent`` outputPorts).
|
|
ACTION_RESULT_DATA_PICK_OPTIONS = [
|
|
{
|
|
"path": ["documents", 0, "documentData"],
|
|
"pickerLabel": t("Gesamter Inhalt"),
|
|
"detail": t(
|
|
"Strukturiertes Handover als JSON inklusive aller Textteile "
|
|
"und Verweisen auf ausgelagerte Bilder."
|
|
),
|
|
"recommended": True,
|
|
"type": "Any",
|
|
},
|
|
{
|
|
"path": ["response"],
|
|
"pickerLabel": t("Nur Text"),
|
|
"detail": t("Verketteter Klartext aus allen erkannten Textteilen."),
|
|
"recommended": True,
|
|
"type": "str",
|
|
},
|
|
{
|
|
"path": ["imageDocumentsOnly"],
|
|
"pickerLabel": t("Nur Bilder"),
|
|
"detail": t("Nur die extrahierten Bilddokumente als Liste, ohne JSON-Handover."),
|
|
"recommended": False,
|
|
"type": "List[ActionDocument]",
|
|
},
|
|
{
|
|
"path": ["documents"],
|
|
"pickerLabel": t("Alle Dateitypen"),
|
|
"detail": t("Alle Ausgabedokumente nacheinander: JSON-Handover und Bilder."),
|
|
"recommended": False,
|
|
"type": "List[ActionDocument]",
|
|
},
|
|
]
|
|
|
|
AI_RESULT_DATA_PICK_OPTIONS = [
|
|
{
|
|
"path": ["documents", 0, "documentData"],
|
|
"pickerLabel": t("Gesamter Inhalt"),
|
|
"detail": t(
|
|
"Hauptausgabedatei oder strukturierter Inhalt von ``documents[0]`` "
|
|
"(z. B. erzeugtes Dokument, JSON-Handover)."
|
|
),
|
|
"recommended": True,
|
|
"type": "Any",
|
|
},
|
|
{
|
|
"path": ["response"],
|
|
"pickerLabel": t("Nur Text"),
|
|
"detail": t("Modell-Antwort als reiner Fließtext (ohne eingebettete Bildbytes)."),
|
|
"recommended": True,
|
|
"type": "str",
|
|
},
|
|
{
|
|
"path": ["imageDocumentsOnly"],
|
|
"pickerLabel": t("Nur Bilder"),
|
|
"detail": t("Nur Bild-Dokumente aus ``documents`` (ohne erstes Nicht-Bild-Artefakt, falls gesetzt)."),
|
|
"recommended": False,
|
|
"type": "List[ActionDocument]",
|
|
},
|
|
{
|
|
"path": ["documents"],
|
|
"pickerLabel": t("Alle Ausgabedateien"),
|
|
"detail": t("Alle Dokumente der KI-Antwort: erzeugte Dateien, Bilder, Anhänge."),
|
|
"recommended": False,
|
|
"type": "List[Document]",
|
|
},
|
|
]
|
|
|
|
DOCUMENT_LIST_DATA_PICK_OPTIONS = [
|
|
{
|
|
"path": ["documents"],
|
|
"pickerLabel": t("Alle Dokumente"),
|
|
"detail": t("Die vollständige Dokumentenliste."),
|
|
"recommended": True,
|
|
"type": "List[Document]",
|
|
},
|
|
{
|
|
"path": ["documents", 0],
|
|
"pickerLabel": t("Erstes Dokument"),
|
|
"detail": t("Metadaten und Pfade des ersten Listeneintrags."),
|
|
"recommended": False,
|
|
"type": "Document",
|
|
},
|
|
{
|
|
"path": ["count"],
|
|
"pickerLabel": t("Anzahl"),
|
|
"detail": t("Anzahl der Dokumente."),
|
|
"recommended": False,
|
|
"type": "int",
|
|
},
|
|
]
|
|
|
|
CONSOLIDATE_RESULT_DATA_PICK_OPTIONS = [
|
|
{
|
|
"path": ["result"],
|
|
"pickerLabel": t("Konsolidiertes Ergebnis"),
|
|
"detail": t("Text oder Struktur nach Konsolidierung."),
|
|
"recommended": True,
|
|
"type": "Any",
|
|
},
|
|
{
|
|
"path": ["mode"],
|
|
"pickerLabel": t("Modus"),
|
|
"detail": t("Verwendeter Konsolidierungsmodus."),
|
|
"recommended": False,
|
|
"type": "str",
|
|
},
|
|
{
|
|
"path": ["count"],
|
|
"pickerLabel": t("Anzahl"),
|
|
"detail": t("Anzahl zusammengeführter Elemente."),
|
|
"recommended": False,
|
|
"type": "int",
|
|
},
|
|
]
|
|
|
|
_AI_COMMON_PARAMS = [
|
|
{"name": "requireNeutralization", "type": "bool", "required": False,
|
|
"frontendType": "checkbox", "default": False,
|
|
"description": t("Eingaben fuer diesen Call neutralisieren")},
|
|
{"name": "allowedModels", "type": "array", "required": False,
|
|
"frontendType": "modelMultiSelect", "default": [],
|
|
"description": t("Erlaubte LLM-Modelle (leer = alle erlaubten)")},
|
|
]
|
|
|
|
AI_NODES = [
|
|
{
|
|
"id": "ai.prompt",
|
|
"category": "ai",
|
|
"label": t("Prompt"),
|
|
"description": t("Prompt eingeben und KI führt aus"),
|
|
"parameters": [
|
|
{"name": "aiPrompt", "type": "str", "required": True, "frontendType": "templateTextarea",
|
|
"description": t("KI-Prompt")},
|
|
{"name": "resultType", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["txt", "json", "md", "csv", "xml", "html", "pdf", "docx", "xlsx", "pptx", "png", "jpg"]},
|
|
"description": t("Ausgabeformat"), "default": "txt"},
|
|
{"name": "documentList", "type": "DocumentList", "required": False, "frontendType": "hidden",
|
|
"description": t("Dokumente aus vorherigen Schritten"), "default": "",
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
{"name": "context", "type": "Any", "required": False, "frontendType": "contextBuilder",
|
|
"description": CONTEXT_BUILDER_PARAM_DESCRIPTION, "default": "",
|
|
"graphInherit": {"port": 0, "kind": "primaryTextRef"}},
|
|
{"name": "simpleMode", "type": "bool", "required": False, "frontendType": "checkbox",
|
|
"description": t("Einfacher Modus"), "default": True},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": [
|
|
"FormPayload", "DocumentList", "AiResult", "TextResult", "Transit", "LoopItem", "ActionResult",
|
|
]}},
|
|
"outputPorts": {0: {"schema": "AiResult", "dataPickOptions": AI_RESULT_DATA_PICK_OPTIONS}},
|
|
"paramMappers": ["aiPromptLegacyAlias"],
|
|
"meta": {"icon": "mdi-robot", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "process",
|
|
},
|
|
{
|
|
"id": "ai.webResearch",
|
|
"category": "ai",
|
|
"label": t("Web-Recherche"),
|
|
"description": t("Recherche im Web"),
|
|
"parameters": [
|
|
{"name": "prompt", "type": "str", "required": True, "frontendType": "textarea",
|
|
"description": t("Recherche-Anfrage")},
|
|
{"name": "context", "type": "Any", "required": False, "frontendType": "contextBuilder",
|
|
"description": CONTEXT_BUILDER_PARAM_DESCRIPTION, "default": "",
|
|
"graphInherit": {"port": 0, "kind": "primaryTextRef"}},
|
|
{"name": "documentList", "type": "DocumentList", "required": False, "frontendType": "hidden",
|
|
"description": t("Dokumente aus vorherigen Schritten"), "default": "",
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": [
|
|
"FormPayload", "Transit", "AiResult", "DocumentList", "ActionResult", "LoopItem", "TextResult",
|
|
]}},
|
|
"outputPorts": {0: {"schema": "AiResult", "dataPickOptions": AI_RESULT_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-magnify", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "webResearch",
|
|
},
|
|
{
|
|
"id": "ai.summarizeDocument",
|
|
"category": "ai",
|
|
"label": t("Dokument zusammenfassen"),
|
|
"description": t("Dokumentinhalt zusammenfassen"),
|
|
"parameters": [
|
|
{"name": "documentList", "type": "DocumentList", "required": True, "frontendType": "dataRef",
|
|
"description": t("Dokumente aus vorherigen Schritten"),
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
{"name": "resultType", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["txt", "json", "md", "csv", "xml", "html", "pdf", "docx", "xlsx", "pptx", "png", "jpg"]},
|
|
"description": t("Ausgabeformat"), "default": "txt"},
|
|
{"name": "summaryLength", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["brief", "medium", "detailed"]},
|
|
"description": t("Kurz, mittel oder ausführlich"), "default": "medium"},
|
|
{"name": "folderId", "type": "str", "required": False, "frontendType": "userFileFolder",
|
|
"description": t("Zielordner in Meine Dateien"),
|
|
"default": ""},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": ["DocumentList", "Transit", "LoopItem"]}},
|
|
"outputPorts": {0: {"schema": "AiResult", "dataPickOptions": AI_RESULT_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-file-document-outline", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "summarizeDocument",
|
|
},
|
|
{
|
|
"id": "ai.translateDocument",
|
|
"category": "ai",
|
|
"label": t("Dokument übersetzen"),
|
|
"description": t("Dokument in Zielsprache übersetzen"),
|
|
"parameters": [
|
|
{"name": "documentList", "type": "DocumentList", "required": True, "frontendType": "dataRef",
|
|
"description": t("Dokumente aus vorherigen Schritten"),
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
{"name": "resultType", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["txt", "json", "md", "csv", "xml", "html", "pdf", "docx", "xlsx", "pptx", "png", "jpg"]},
|
|
"description": t("Ausgabeformat"), "default": "txt"},
|
|
{"name": "targetLanguage", "type": "str", "required": True, "frontendType": "text",
|
|
"description": t("Zielsprache (z.B. de, en, French)")},
|
|
{"name": "folderId", "type": "str", "required": False, "frontendType": "userFileFolder",
|
|
"description": t("Zielordner in Meine Dateien"),
|
|
"default": ""},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": ["DocumentList", "Transit", "LoopItem"]}},
|
|
"outputPorts": {0: {"schema": "AiResult", "dataPickOptions": AI_RESULT_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-translate", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "translateDocument",
|
|
},
|
|
{
|
|
"id": "ai.convertDocument",
|
|
"category": "ai",
|
|
"label": t("Dokument konvertieren"),
|
|
"description": t("Dokument in anderes Format konvertieren"),
|
|
"parameters": [
|
|
{"name": "documentList", "type": "DocumentList", "required": True, "frontendType": "dataRef",
|
|
"description": t("Dokumente aus vorherigen Schritten"),
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
{"name": "targetFormat", "type": "str", "required": True, "frontendType": "select",
|
|
"frontendOptions": {"options": ["docx", "pdf", "xlsx", "csv", "txt", "html", "json", "md"]},
|
|
"description": t("Zielformat")},
|
|
{"name": "folderId", "type": "str", "required": False, "frontendType": "userFileFolder",
|
|
"description": t("Zielordner in Meine Dateien"),
|
|
"default": ""},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": ["DocumentList", "Transit", "LoopItem"]}},
|
|
"outputPorts": {0: {"schema": "DocumentList", "dataPickOptions": DOCUMENT_LIST_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-file-convert", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "convertDocument",
|
|
},
|
|
{
|
|
"id": "ai.generateDocument",
|
|
"category": "ai",
|
|
"label": t("Dokument generieren"),
|
|
"description": t("Dokument aus Prompt generieren"),
|
|
"parameters": [
|
|
{"name": "prompt", "type": "str", "required": True, "frontendType": "textarea",
|
|
"description": t("Generierungs-Prompt")},
|
|
{"name": "outputFormat", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["docx", "pdf", "txt", "html", "md"]},
|
|
"description": t("Ausgabeformat"), "default": "docx"},
|
|
{"name": "title", "type": "str", "required": False, "frontendType": "text",
|
|
"description": t("Dokumenttitel (Metadaten / Dateiname)"), "default": ""},
|
|
{"name": "documentType", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["letter", "memo", "proposal", "contract", "report", "email"]},
|
|
"description": t("Dokumentart (Inhaltshinweis fuer die KI)"), "default": "proposal"},
|
|
{"name": "folderId", "type": "str", "required": False, "frontendType": "userFileFolder",
|
|
"description": t("Zielordner in Meine Dateien"),
|
|
"default": ""},
|
|
{"name": "context", "type": "Any", "required": False, "frontendType": "contextBuilder",
|
|
"description": CONTEXT_BUILDER_PARAM_DESCRIPTION, "default": "",
|
|
"graphInherit": {"port": 0, "kind": "primaryTextRef"}},
|
|
{"name": "documentList", "type": "DocumentList", "required": False, "frontendType": "hidden",
|
|
"description": t("Dokumente aus vorherigen Schritten"), "default": "",
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": [
|
|
"FormPayload", "Transit", "AiResult", "DocumentList", "ActionResult", "LoopItem", "TextResult",
|
|
]}},
|
|
"outputPorts": {0: {"schema": "DocumentList", "dataPickOptions": DOCUMENT_LIST_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-file-plus", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "generateDocument",
|
|
},
|
|
{
|
|
"id": "ai.generateCode",
|
|
"category": "ai",
|
|
"label": t("Code generieren"),
|
|
"description": t("Code aus Beschreibung generieren"),
|
|
"parameters": [
|
|
{"name": "prompt", "type": "str", "required": True, "frontendType": "textarea",
|
|
"description": t("Code-Generierungs-Prompt")},
|
|
{"name": "resultType", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["py", "js", "ts", "html", "java", "cpp", "txt", "json", "csv", "xml"]},
|
|
"description": t("Datei-Endung der erzeugten Code-Datei"), "default": "py"},
|
|
{"name": "folderId", "type": "str", "required": False, "frontendType": "userFileFolder",
|
|
"description": t("Zielordner in Meine Dateien"),
|
|
"default": ""},
|
|
{"name": "context", "type": "Any", "required": False, "frontendType": "contextBuilder",
|
|
"description": CONTEXT_BUILDER_PARAM_DESCRIPTION, "default": "",
|
|
"graphInherit": {"port": 0, "kind": "primaryTextRef"}},
|
|
{"name": "documentList", "type": "DocumentList", "required": False, "frontendType": "hidden",
|
|
"description": t("Dokumente aus vorherigen Schritten"), "default": "",
|
|
"graphInherit": {"port": 0, "kind": "documentListWire"}},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": [
|
|
"FormPayload", "Transit", "AiResult", "DocumentList", "ActionResult", "LoopItem", "TextResult",
|
|
]}},
|
|
"outputPorts": {0: {"schema": "AiResult", "dataPickOptions": AI_RESULT_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-code-tags", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "generateCode",
|
|
},
|
|
{
|
|
"id": "ai.consolidate",
|
|
"category": "ai",
|
|
"label": t("KI-Konsolidierung"),
|
|
"description": t("Gesammelte Ergebnisse mit KI zusammenfassen, klassifizieren oder semantisch zusammenführen"),
|
|
"parameters": [
|
|
{"name": "mode", "type": "str", "required": False, "frontendType": "select",
|
|
"frontendOptions": {"options": ["summarize", "classify", "semanticMerge"]},
|
|
"description": t("Konsolidierungsmodus"), "default": "summarize"},
|
|
{"name": "prompt", "type": "str", "required": False, "frontendType": "textarea",
|
|
"description": t("Optionaler Prompt für die Konsolidierung"), "default": ""},
|
|
] + _AI_COMMON_PARAMS,
|
|
"inputs": 1,
|
|
"outputs": 1,
|
|
"inputPorts": {0: {"accepts": ["AggregateResult", "Transit"]}},
|
|
"outputPorts": {0: {"schema": "ConsolidateResult", "dataPickOptions": CONSOLIDATE_RESULT_DATA_PICK_OPTIONS}},
|
|
"meta": {"icon": "mdi-table-merge-cells", "color": "#9C27B0", "usesAi": True},
|
|
"_method": "ai",
|
|
"_action": "consolidate",
|
|
},
|
|
]
|