-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm_client.py
More file actions
30 lines (27 loc) · 974 Bytes
/
llm_client.py
File metadata and controls
30 lines (27 loc) · 974 Bytes
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
import requests
class LLMClient:
def __init__(self, api_key: str, model: str, url: str):
self.url = url
self.headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
self.model = model
def review_diff(self, diff: str) -> str:
prompt = (
"Review this PR diff. Respond in markdown with sections: "
"Bugs, Improvements, Positives.\n\n"
f"{diff[:8000]}"
)
payload = {
"model": self.model,
"messages": [
{"role": "system", "content": "You are a senior code reviewer."},
{"role": "user", "content": prompt},
],
"temperature": 0.2,
}
r = requests.post(self.url, headers=self.headers, json=payload, timeout=60)
r.raise_for_status()
data = r.json()
return data["choices"][0]["message"]["content"].strip()