File size: 1,619 Bytes
584bb1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re

with open("gateway.py", "r") as f:
    code = f.read()

# Let's inspect the headers sent
new_execute_completion = """async def execute_completion(payload: dict[str, Any], is_authenticated: bool = False, priority_override: int | None = None) -> dict[str, Any]:
    await wait_for_llama()
    async with inference_lock.context(is_authenticated, priority_override):
        async with httpx.AsyncClient(timeout=REQUEST_TIMEOUT) as client:
            headers = llama_auth_headers()
            print(f"Sending to {LLAMA_URL}/v1/chat/completions with headers: {headers}", flush=True)
            response = await client.post(
                f"{LLAMA_URL}/v1/chat/completions",
                json=ensure_language_guard(payload),
                headers=headers,
            )
            response.raise_for_status()
            return response.json()"""

old_execute_completion = """async def execute_completion(payload: dict[str, Any], is_authenticated: bool = False, priority_override: int | None = None) -> dict[str, Any]:
    await wait_for_llama()
    async with inference_lock.context(is_authenticated, priority_override):
        async with httpx.AsyncClient(timeout=REQUEST_TIMEOUT) as client:
            response = await client.post(
                f"{LLAMA_URL}/v1/chat/completions",
                json=ensure_language_guard(payload),
                headers=llama_auth_headers(),
            )
            response.raise_for_status()
            return response.json()"""

code = code.replace(old_execute_completion, new_execute_completion)

with open("gateway.py", "w") as f:
    f.write(code)