-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckExisting
More file actions
130 lines (108 loc) · 4.5 KB
/
checkExisting
File metadata and controls
130 lines (108 loc) · 4.5 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import requests
import json
import os
import urllib3
# 1. Configuration
USER_KEY = os.getenv("USER_KEY")
MODEL_API = "https://granite-3-3-8b-instruct--apicast-production.apps.int.stc.ai.prod.us-east-1.aws.paas.redhat.com:443/v1/chat/completions"
MODEL_ID = "ibm-granite/granite-3.3-8b-instruct"
# This silences the 'InsecureRequestWarning' if we have to fallback to verify=False
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def call_granite(messages, tools=None):
headers = {
"Authorization": f"Bearer {USER_KEY}",
"Content-Type": "application/json"
}
payload = {
"model": MODEL_ID,
"messages": messages,
"temperature": 0.2,
"max_tokens": 500
}
if tools:
payload["tools"] = tools
# 1. Try to find the certificate in your current folder
cert_file = "Current-IT-Root-CAs.pem"
try:
if os.path.exists(cert_file):
response = requests.post(MODEL_API, headers=headers, json=payload, verify=cert_file)
else:
# 2. HACKATHON FALLBACK: If the file is missing, just skip verification to keep moving
print(f"--- Warning: {cert_file} not found. Proceeding without verification ---")
response = requests.post(MODEL_API, headers=headers, json=payload, verify=False)
response.raise_for_status() # This will catch 401/500 errors
return response.json()
except requests.exceptions.RequestException as e:
print(f"API Error: {e}")
return None
# --- TOOL DEFINITION ---
tools = [
{
"type": "function",
"function": {
"name": "search_jira",
"description": "Search issues.redhat.com for existing bug reports.",
"parameters": {
"type": "object",
"properties": {
"jql": {
"type": "string",
"description": "The JQL query (e.g. 'text ~ \"lan tx queue\"')"
}
},
"required": ["jql"]
}
}
}
]
# --- MOCK JIRA FUNCTION ---
# (Replace this later with a real requests call to Jira)
def search_jira(jql):
print(f"\n[SYSTEM] Agent is searching Jira with: {jql}")
# Mock data for your hackathon demo
if "lan tx" in jql.lower():
return [{"key": "RHEL-9921", "summary": "Failed to set LAN Tx queue on certain NICs", "status": "Closed"}]
return []
# --- UPDATE YOUR call_granite CALL ---
# Change your loop to include 'tools=tools' in the call_granite function
# 2. Define the Agent's "Persona"
system_prompt = {
"role": "system",
"content": (
"You are the 'CheckExisting' Agent. When a user provides a bug, extract the technical error code or unique symptoms. Use the search_jira tool. If the search returns results, compare the summaries. If a match is found, provide the link and say 'DUPLICATE DETECTED'. If no similar bugs exist, say 'UNIQUE ISSUE - PROCEEDING TO JIRA CREATION'"
)
}
# 3. Main Loop
def run_agent():
print("=== CheckExisting Agent Active ===")
history = [system_prompt]
while True:
user_input = input("Enter Bug Description (or 'quit'): ")
if user_input.lower() == 'quit': break
history.append({"role": "user", "content": user_input})
# 1. Call Granite with Tools
result = call_granite(history, tools=tools)
message = result['choices'][0]['message']
# 2. Check if AI wants to use the tool
if "tool_calls" in message:
for tool_call in message["tool_calls"]:
# Extract the JQL the AI wrote
args = json.loads(tool_call["function"]["arguments"])
jql = args.get("jql")
# Execute Tool
results = search_jira(jql)
# Feed the Observation back to the AI
history.append(message) # Add the assistant's request to history
history.append({
"role": "tool",
"tool_call_id": tool_call["id"],
"name": "search_jira",
"content": json.dumps(results)
})
# 3. Final call to get the AI's summary of the data
final_result = call_granite(history)
print(f"\nAI Final Analysis: {final_result['choices'][0]['message']['content']}\n")
else:
print(f"\nAI Analysis: {message['content']}\n")
if __name__ == "__main__":
run_agent()