Explorer
/proc/21/root/tmp/patch_llm_worker.py
← Zurück ↓ Download
#!/usr/bin/env python3
"""Patch llm_call_worker.py for Qwen 3.7 Flash compatibility."""

import subprocess

# Read current file
r = subprocess.run(['docker', 'exec', 'graphiti-service', 'cat', '/app/llm_call_worker.py'],
                   capture_output=True, text=True)
src = r.stdout

# Replace the extra_body config
old_extra_body = """extra_body={'provider': {'order': ['Nvidia'], 'allow_fallbacks': False},
                        'reasoning': {'exclude': True}},"""

new_extra_body = """extra_body={'provider': {'order': ['Alibaba']},
                        'reasoning': {'effort': 'none'}},"""

if old_extra_body in src:
    src = src.replace(old_extra_body, new_extra_body)
    print("✅ Patched: provider Nvidia→Alibaba, reasoning exclude→effort:none")
else:
    print("❌ Old pattern not found")
    # Show current lines around it
    lines = src.split('\n')
    for i, line in enumerate(lines):
        if 'extra_body' in line or 'reasoning' in line:
            print(f"  Line {i}: {line}")

# Backup original
subprocess.run(['docker', 'cp', '/app/llm_call_worker.py', 
                'graphiti-service:/app/llm_call_worker.py.bak-p2zf'],
               capture_output=True)

# Write patched version to container via stdin
w = subprocess.run(['docker', 'exec', '-i', 'graphiti-service', 'sh', '-c',
                    'cat > /app/llm_call_worker.py'],
                   input=src.encode(), capture_output=True)

if w.returncode == 0:
    print("✅ Patched file written to container")
    print("\nNew content of llm_call_worker.py:")
    check = subprocess.run(['docker', 'exec', 'graphiti-service', 'cat', '/app/llm_call_worker.py'],
                          capture_output=True, text=True)
    for line in check.stdout.split('\n'):
        if 'extra_body' in line or 'reasoning' in line or 'provider' in line.lower():
            print(f"  {line.strip()}")
else:
    print(f"❌ Failed to write: {w.stderr.decode()}")
    raise SystemExit(1)

print("\n✅ Patch complete. Restart Graphiti next.")