Upload 4 files
Browse files- .gitattributes +2 -0
- marl/__init__.py +29 -0
- marl/__main__.py +116 -0
- marl/core.cpython-312-x86_64-linux-gnu.so +3 -0
- marl/proxy.cpython-312-x86_64-linux-gnu.so +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
marl/core.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
marl/proxy.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
marl/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MARL — Model-Agnostic Runtime Middleware for LLMs
|
| 3 |
+
═══════════════════════════════════════════════════
|
| 4 |
+
Apply the 5-stage multi-agent pipeline (S1→S2→S3→S4→S5) to ANY LLM
|
| 5 |
+
to systematically improve reasoning, self-correction, and reliability.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
from marl import Marl
|
| 9 |
+
|
| 10 |
+
# OpenAI
|
| 11 |
+
marl = Marl.from_openai(api_key="sk-...")
|
| 12 |
+
result = marl.run("Your complex question here")
|
| 13 |
+
|
| 14 |
+
# Any custom LLM
|
| 15 |
+
marl = Marl(call_fn=my_llm_function)
|
| 16 |
+
result = marl.run("Your question")
|
| 17 |
+
|
| 18 |
+
# As OpenAI-compatible proxy
|
| 19 |
+
marl.serve(port=8080) # localhost:8080/v1/chat/completions
|
| 20 |
+
|
| 21 |
+
Author: Ginigen AI
|
| 22 |
+
License: Apache 2.0
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
from .core import Marl, MarlResult, MarlConfig
|
| 26 |
+
from .proxy import MarlProxy
|
| 27 |
+
|
| 28 |
+
__version__ = "1.0.0"
|
| 29 |
+
__all__ = ["Marl", "MarlResult", "MarlConfig", "MarlProxy"]
|
marl/__main__.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MARL CLI — Command-line interface
|
| 3 |
+
|
| 4 |
+
Usage:
|
| 5 |
+
# Run as proxy
|
| 6 |
+
python -m marl proxy --port 8080 --backend openai --model gpt-5.2
|
| 7 |
+
|
| 8 |
+
# Run single query
|
| 9 |
+
python -m marl run "Your question here" --backend ollama --model llama3.1
|
| 10 |
+
|
| 11 |
+
# Test connection
|
| 12 |
+
python -m marl test --backend openai
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import argparse
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
parser = argparse.ArgumentParser(
|
| 22 |
+
prog="marl",
|
| 23 |
+
description="🌀 MARL — Model-Agnostic Runtime Middleware for LLMs"
|
| 24 |
+
)
|
| 25 |
+
sub = parser.add_subparsers(dest="command")
|
| 26 |
+
|
| 27 |
+
# ── proxy ──
|
| 28 |
+
p_proxy = sub.add_parser("proxy", help="Start OpenAI-compatible proxy server")
|
| 29 |
+
p_proxy.add_argument("--port", type=int, default=8080)
|
| 30 |
+
p_proxy.add_argument("--host", default="0.0.0.0")
|
| 31 |
+
p_proxy.add_argument("--backend", default="openai",
|
| 32 |
+
choices=["openai", "anthropic", "ollama", "friendli", "custom"])
|
| 33 |
+
p_proxy.add_argument("--model", default=None)
|
| 34 |
+
p_proxy.add_argument("--api-key", default=None)
|
| 35 |
+
p_proxy.add_argument("--base-url", default=None, help="For custom backend")
|
| 36 |
+
|
| 37 |
+
# ── run ──
|
| 38 |
+
p_run = sub.add_parser("run", help="Run single MARL query")
|
| 39 |
+
p_run.add_argument("prompt", help="The question/task")
|
| 40 |
+
p_run.add_argument("--backend", default="openai",
|
| 41 |
+
choices=["openai", "anthropic", "ollama", "friendli", "custom"])
|
| 42 |
+
p_run.add_argument("--model", default=None)
|
| 43 |
+
p_run.add_argument("--api-key", default=None)
|
| 44 |
+
p_run.add_argument("--base-url", default=None)
|
| 45 |
+
p_run.add_argument("--trace", action="store_true", help="Show full agent trace")
|
| 46 |
+
|
| 47 |
+
# ── test ──
|
| 48 |
+
p_test = sub.add_parser("test", help="Test backend connection")
|
| 49 |
+
p_test.add_argument("--backend", default="openai",
|
| 50 |
+
choices=["openai", "anthropic", "ollama", "friendli", "custom"])
|
| 51 |
+
p_test.add_argument("--model", default=None)
|
| 52 |
+
p_test.add_argument("--api-key", default=None)
|
| 53 |
+
p_test.add_argument("--base-url", default=None)
|
| 54 |
+
|
| 55 |
+
args = parser.parse_args()
|
| 56 |
+
|
| 57 |
+
if not args.command:
|
| 58 |
+
parser.print_help()
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
from .core import Marl, MarlConfig
|
| 62 |
+
|
| 63 |
+
marl = _build_marl(args)
|
| 64 |
+
|
| 65 |
+
if args.command == "proxy":
|
| 66 |
+
marl.serve(host=args.host, port=args.port)
|
| 67 |
+
|
| 68 |
+
elif args.command == "run":
|
| 69 |
+
config = MarlConfig(include_trace=args.trace)
|
| 70 |
+
marl.config = config
|
| 71 |
+
print("🌀 MARL running S1→S2→S3→S4→S5 pipeline...\n")
|
| 72 |
+
result = marl.run(args.prompt)
|
| 73 |
+
if args.trace:
|
| 74 |
+
print(result.full_output)
|
| 75 |
+
else:
|
| 76 |
+
print(result.answer)
|
| 77 |
+
print(f"\n⏱️ {result.elapsed:.1f}s | Fixes: {len(result.fixes)}")
|
| 78 |
+
|
| 79 |
+
elif args.command == "test":
|
| 80 |
+
print("🔍 Testing backend connection...")
|
| 81 |
+
try:
|
| 82 |
+
resp = marl.call_fn("Say OK", "", 10, 0)
|
| 83 |
+
if resp and not resp.startswith("[ERROR"):
|
| 84 |
+
print(f"✅ Connected! Response: {resp[:50]}")
|
| 85 |
+
else:
|
| 86 |
+
print(f"❌ Error: {resp}")
|
| 87 |
+
except Exception as e:
|
| 88 |
+
print(f"❌ Failed: {e}")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _build_marl(args) -> "Marl":
|
| 92 |
+
from .core import Marl
|
| 93 |
+
backend = args.backend
|
| 94 |
+
api_key = args.api_key or os.getenv("OPENAI_API_KEY") or os.getenv("ANTHROPIC_API_KEY") or ""
|
| 95 |
+
model = args.model
|
| 96 |
+
|
| 97 |
+
if backend == "openai":
|
| 98 |
+
return Marl.from_openai(api_key=api_key, model=model or "gpt-5.2")
|
| 99 |
+
elif backend == "anthropic":
|
| 100 |
+
key = args.api_key or os.getenv("ANTHROPIC_API_KEY", "")
|
| 101 |
+
return Marl.from_anthropic(api_key=key, model=model or "claude-sonnet-4-20250514")
|
| 102 |
+
elif backend == "ollama":
|
| 103 |
+
return Marl.from_ollama(model=model or "llama3.1")
|
| 104 |
+
elif backend == "friendli":
|
| 105 |
+
key = args.api_key or os.getenv("FRIENDLI_TOKEN", "")
|
| 106 |
+
return Marl.from_friendli(token=key, model=model or "deppfs281rgffnk")
|
| 107 |
+
elif backend == "custom":
|
| 108 |
+
base_url = args.base_url or "http://localhost:8000/v1"
|
| 109 |
+
return Marl.from_openai_compatible(base_url=base_url, api_key=api_key,
|
| 110 |
+
model=model or "default")
|
| 111 |
+
else:
|
| 112 |
+
raise ValueError(f"Unknown backend: {backend}")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
marl/core.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4961041acda79d7c394b215734a9d93510cd84aa397431062b075ddd6ad60291
|
| 3 |
+
size 1478112
|
marl/proxy.cpython-312-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b597e6159ccc821ac7a8b8bd6c8a1b4209175742d5aae38fc1fc7361282b4199
|
| 3 |
+
size 514720
|