From dfa69a879daa92fe22d0178519cd243ad76eae9c Mon Sep 17 00:00:00 2001 From: Etytabs <125467781+Etytabs@users.noreply.github.com> Date: Mon, 11 May 2026 09:58:06 +0000 Subject: [PATCH] feat: add Reversal integration example for Hermes input normalization --- plugin-reversal-example/README.md | 25 +++++++++ plugin-reversal-example/requirements.txt | 1 + .../reversal_integration.py | 52 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 plugin-reversal-example/README.md create mode 100644 plugin-reversal-example/requirements.txt create mode 100644 plugin-reversal-example/reversal_integration.py diff --git a/plugin-reversal-example/README.md b/plugin-reversal-example/README.md new file mode 100644 index 0000000..06af8e0 --- /dev/null +++ b/plugin-reversal-example/README.md @@ -0,0 +1,25 @@ +# Reversal + Hermes integration example + +This example shows how to normalize messy sources before they reach Hermes. + +## Why + +Hermes is stronger when input data is clean. +Reversal converts raw inputs (URL, PDF, Word, Excel, CSV, image, text) into a stable JSON schema. + +## Install + +pip install reversal-engine + +Optional (only for image/dashboard parsing): +export ANTHROPIC_API_KEY=your_key_here + +## Run + +python plugin-reversal-example/reversal_integration.py "https://example.com" + +## How to use in your Hermes flow + +1. Call normalize_for_hermes(source) +2. Build prompt/tool input with build_hermes_input(...) +3. Send that normalized payload to Hermes instead of raw source content diff --git a/plugin-reversal-example/requirements.txt b/plugin-reversal-example/requirements.txt new file mode 100644 index 0000000..eba5c46 --- /dev/null +++ b/plugin-reversal-example/requirements.txt @@ -0,0 +1 @@ +reversal-engine>=1.0.0 diff --git a/plugin-reversal-example/reversal_integration.py b/plugin-reversal-example/reversal_integration.py new file mode 100644 index 0000000..b72b91a --- /dev/null +++ b/plugin-reversal-example/reversal_integration.py @@ -0,0 +1,52 @@ +from __future__ import annotations +import json +import sys +from typing import Any, Dict + +from reversal_engine import reverse + + +def normalize_for_hermes(source: str, anthropic_api_key: str | None = None) -> Dict[str, Any]: + """ + Convertit une source brute (URL, PDF, Excel, image, texte) en JSON propre + avant de la passer a Hermes. + """ + result = reverse(source, api_key=anthropic_api_key) + + if result.get("status") != "ok": + return { + "status": "error", + "source": source, + "error": result.get("data", {}).get("error", "Normalization failed"), + } + + data = result.get("data", {}) + return { + "status": "ok", + "content_type": result.get("content_type"), + "source": result.get("source"), + "processed_in_ms": result.get("processed_in_ms"), + "title": data.get("title", ""), + "summary_hint": data.get("summary_hint", ""), + "payload": data, + } + + +def build_hermes_input(normalized: Dict[str, Any]) -> str: + """ + Format pret a injecter dans le prompt / tool-call Hermes. + """ + if normalized.get("status") != "ok": + return f"Normalization error: {normalized.get('error', 'unknown error')}" + + return ( + "You are Hermes.\n" + "Use ONLY the normalized JSON below as source of truth.\n\n" + + json.dumps(normalized, ensure_ascii=False, indent=2) + ) + + +if __name__ == "__main__": + source_arg = sys.argv[1] if len(sys.argv) > 1 else "https://example.com" + normalized = normalize_for_hermes(source_arg) + print(build_hermes_input(normalized))