File size: 780 Bytes
07a91a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Small client example to call POST /generate."""

from __future__ import annotations

import json
import os

import requests
from dotenv import load_dotenv

load_dotenv()

BASE_URL = os.getenv("CODING_LLM_URL", "http://127.0.0.1:8000")
API_KEY = os.getenv("API_KEY", "")

payload = {
    "instruction": "Fix this function and explain",
    "input": "def add(a,b) return a+b",
}

headers = {"Content-Type": "application/json"}
if API_KEY:
    headers["x-api-key"] = API_KEY

resp = requests.post(f"{BASE_URL}/generate", headers=headers, json=payload, timeout=60)
if resp.status_code == 401:
    raise PermissionError("Unauthorized (401). Ensure API_KEY matches server configuration.")
resp.raise_for_status()
print(json.dumps(resp.json(), indent=2))