-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
55 lines (45 loc) · 1.28 KB
/
agent.py
File metadata and controls
55 lines (45 loc) · 1.28 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import requests
OPENROUTER = os.environ["OPENROUTER_API_KEY"]
GH = os.environ["GH_TOKEN"]
REPO = os.environ["GITHUB_REPOSITORY"]
CI_LOG = os.environ.get("CI_LOG", "No CI logs")
# 1️⃣ Ask AI to analyze the failure
prompt = f"""
You are a senior DevOps engineer.
Explain this CI failure and suggest a fix.
{CI_LOG}
"""
ai = requests.post(
"https://openrouter.ai/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {OPENROUTER}",
"Content-Type": "application/json",
"HTTP-Referer": "https://github.com",
"X-Title": "CI Debug Agent"
},
json={
"model": "mistralai/mistral-7b-instruct",
"messages": [{"role": "user", "content": prompt}]
}
).json()
report = ai["choices"][0]["message"]["content"]
print("\n🤖 AI REPORT:\n", report)
# 2️⃣ Create GitHub Issue
requests.post(
f"https://api.github.com/repos/{REPO}/issues",
headers={
"Authorization": f"Bearer {GH}",
"Accept": "application/vnd.github+json"
},
json={
"title": "🚨 CI Failure Detected",
"body": report
}
)
# 3️⃣ Send failure to your Flask dashboard
DASHBOARD_URL = "https://YOUR_NGROK_URL/api/failure" # ⬅️ change this
requests.post(
DASHBOARD_URL,
json={"message": report}
)