Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,13 @@ exadata_specs = {
|
|
22 |
"X11M": {"Quarter Rack": {"max_iops": 600000, "max_throughput": 40}, "Half Rack": {"max_iops": 1200000, "max_throughput": 80}, "Full Rack": {"max_iops": 2400000, "max_throughput": 160}},
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# --- Utils ---
|
26 |
def clean_awr_content(content):
|
27 |
if "<html" in content.lower():
|
@@ -32,7 +39,7 @@ def clean_awr_content(content):
|
|
32 |
# === AGENTS ===
|
33 |
|
34 |
class CriticalAnalyzerAgent:
|
35 |
-
def analyze(self, content, performance_test_mode, exadata_model, rack_size):
|
36 |
cleaned_content = clean_awr_content(content)
|
37 |
if len(cleaned_content) > 128000:
|
38 |
cleaned_content = cleaned_content[:128000] + "\n\n[TRUNCATED]..."
|
@@ -69,7 +76,7 @@ Compare observed vs theoretical. Recommend actions to close the performance gap.
|
|
69 |
"""
|
70 |
|
71 |
response = client.chat.completions.create(
|
72 |
-
model=
|
73 |
messages=[
|
74 |
{"role": "system", "content": "You are an expert Oracle DBA."},
|
75 |
{"role": "user", "content": prompt}
|
@@ -79,7 +86,7 @@ Compare observed vs theoretical. Recommend actions to close the performance gap.
|
|
79 |
return response.choices[0].message.content.strip()
|
80 |
|
81 |
class HealthAgent:
|
82 |
-
def check_health(self, content):
|
83 |
cleaned_content = clean_awr_content(content)
|
84 |
if len(cleaned_content) > 128000:
|
85 |
cleaned_content = cleaned_content[:128000] + "\n\n[TRUNCATED]..."
|
@@ -105,7 +112,7 @@ AWR CONTENT:
|
|
105 |
"""
|
106 |
|
107 |
response = client.chat.completions.create(
|
108 |
-
model=
|
109 |
messages=[
|
110 |
{"role": "system", "content": "You are the strict Oracle AWR Health Analysis Agent."},
|
111 |
{"role": "user", "content": prompt}
|
@@ -115,26 +122,26 @@ AWR CONTENT:
|
|
115 |
return response.choices[0].message.content.strip()
|
116 |
|
117 |
class RaterAgent:
|
118 |
-
def rate(self, content):
|
119 |
prompt = f"Rate the following analysis from 1-5 stars and explain:\n\n{content}"
|
120 |
response = client.chat.completions.create(
|
121 |
-
model=
|
122 |
messages=[{"role": "user", "content": prompt}]
|
123 |
)
|
124 |
return response.choices[0].message.content.strip()
|
125 |
|
126 |
# === Main Process ===
|
127 |
-
def process_awr(awr_text, threshold, performance_test_mode, exadata_model, rack_size):
|
128 |
analyzer = CriticalAnalyzerAgent()
|
129 |
health = HealthAgent()
|
130 |
rater = RaterAgent()
|
131 |
|
132 |
if not awr_text.strip():
|
133 |
-
return "No AWR text provided", "", ""
|
134 |
|
135 |
-
analysis = analyzer.analyze(awr_text, performance_test_mode, exadata_model, rack_size)
|
136 |
-
health_status = health.check_health(awr_text)
|
137 |
-
rating_text = rater.rate(analysis)
|
138 |
|
139 |
stars = 0
|
140 |
match = re.search(r"(\d+)", rating_text)
|
@@ -144,8 +151,8 @@ def process_awr(awr_text, threshold, performance_test_mode, exadata_model, rack_
|
|
144 |
retry_status = "✅ Accepted"
|
145 |
|
146 |
if stars < threshold:
|
147 |
-
analysis_retry = analyzer.analyze(awr_text, performance_test_mode, exadata_model, rack_size)
|
148 |
-
rating_text_retry = rater.rate(analysis_retry)
|
149 |
retry_status = "✅ Retry Occurred"
|
150 |
analysis = analysis_retry
|
151 |
rating_text = rating_text_retry
|
@@ -161,6 +168,7 @@ with gr.Blocks() as demo:
|
|
161 |
performance_test_mode = gr.Checkbox(label="Performance Test Mode")
|
162 |
exadata_model = gr.Dropdown(choices=list(exadata_specs.keys()), label="Exadata Model", visible=False)
|
163 |
rack_size = gr.Dropdown(choices=["Quarter Rack", "Half Rack", "Full Rack"], label="Rack Size", visible=False)
|
|
|
164 |
|
165 |
def toggle_visibility(mode):
|
166 |
return gr.update(visible=mode), gr.update(visible=mode)
|
@@ -169,10 +177,12 @@ with gr.Blocks() as demo:
|
|
169 |
|
170 |
analyze_btn = gr.Button("Analyze AWR Report")
|
171 |
output = gr.Textbox(label="AWR Analysis", lines=20)
|
172 |
-
health = gr.Textbox(label="Health Agent Findings", lines=
|
173 |
rating = gr.Textbox(label="Rater", lines=3)
|
174 |
retry_status = gr.Textbox(label="Retry Status")
|
175 |
|
176 |
-
analyze_btn.click(process_awr,
|
|
|
|
|
177 |
|
178 |
-
demo.launch(debug=True)
|
|
|
22 |
"X11M": {"Quarter Rack": {"max_iops": 600000, "max_throughput": 40}, "Half Rack": {"max_iops": 1200000, "max_throughput": 80}, "Full Rack": {"max_iops": 2400000, "max_throughput": 160}},
|
23 |
}
|
24 |
|
25 |
+
# --- Supported LLM Models ---
|
26 |
+
supported_llms = {
|
27 |
+
"gpt-3.5-turbo": "Fastest / lowest cost (basic analysis), Standard AWR Healthcheck",
|
28 |
+
"gpt-4-turbo": "Balanced (recommended default), Production Performance Analysis",
|
29 |
+
"gpt-4o": "Deep + technical (best), Deep Dive, Exadata, RAC Stability, Risk Audit",
|
30 |
+
}
|
31 |
+
|
32 |
# --- Utils ---
|
33 |
def clean_awr_content(content):
|
34 |
if "<html" in content.lower():
|
|
|
39 |
# === AGENTS ===
|
40 |
|
41 |
class CriticalAnalyzerAgent:
|
42 |
+
def analyze(self, content, performance_test_mode, exadata_model, rack_size, llm_model):
|
43 |
cleaned_content = clean_awr_content(content)
|
44 |
if len(cleaned_content) > 128000:
|
45 |
cleaned_content = cleaned_content[:128000] + "\n\n[TRUNCATED]..."
|
|
|
76 |
"""
|
77 |
|
78 |
response = client.chat.completions.create(
|
79 |
+
model=llm_model,
|
80 |
messages=[
|
81 |
{"role": "system", "content": "You are an expert Oracle DBA."},
|
82 |
{"role": "user", "content": prompt}
|
|
|
86 |
return response.choices[0].message.content.strip()
|
87 |
|
88 |
class HealthAgent:
|
89 |
+
def check_health(self, content, llm_model):
|
90 |
cleaned_content = clean_awr_content(content)
|
91 |
if len(cleaned_content) > 128000:
|
92 |
cleaned_content = cleaned_content[:128000] + "\n\n[TRUNCATED]..."
|
|
|
112 |
"""
|
113 |
|
114 |
response = client.chat.completions.create(
|
115 |
+
model=llm_model,
|
116 |
messages=[
|
117 |
{"role": "system", "content": "You are the strict Oracle AWR Health Analysis Agent."},
|
118 |
{"role": "user", "content": prompt}
|
|
|
122 |
return response.choices[0].message.content.strip()
|
123 |
|
124 |
class RaterAgent:
|
125 |
+
def rate(self, content, llm_model):
|
126 |
prompt = f"Rate the following analysis from 1-5 stars and explain:\n\n{content}"
|
127 |
response = client.chat.completions.create(
|
128 |
+
model=llm_model,
|
129 |
messages=[{"role": "user", "content": prompt}]
|
130 |
)
|
131 |
return response.choices[0].message.content.strip()
|
132 |
|
133 |
# === Main Process ===
|
134 |
+
def process_awr(awr_text, threshold, performance_test_mode, exadata_model, rack_size, llm_model):
|
135 |
analyzer = CriticalAnalyzerAgent()
|
136 |
health = HealthAgent()
|
137 |
rater = RaterAgent()
|
138 |
|
139 |
if not awr_text.strip():
|
140 |
+
return "No AWR text provided", "", "", ""
|
141 |
|
142 |
+
analysis = analyzer.analyze(awr_text, performance_test_mode, exadata_model, rack_size, llm_model)
|
143 |
+
health_status = health.check_health(awr_text, llm_model)
|
144 |
+
rating_text = rater.rate(analysis, llm_model)
|
145 |
|
146 |
stars = 0
|
147 |
match = re.search(r"(\d+)", rating_text)
|
|
|
151 |
retry_status = "✅ Accepted"
|
152 |
|
153 |
if stars < threshold:
|
154 |
+
analysis_retry = analyzer.analyze(awr_text, performance_test_mode, exadata_model, rack_size, llm_model)
|
155 |
+
rating_text_retry = rater.rate(analysis_retry, llm_model)
|
156 |
retry_status = "✅ Retry Occurred"
|
157 |
analysis = analysis_retry
|
158 |
rating_text = rating_text_retry
|
|
|
168 |
performance_test_mode = gr.Checkbox(label="Performance Test Mode")
|
169 |
exadata_model = gr.Dropdown(choices=list(exadata_specs.keys()), label="Exadata Model", visible=False)
|
170 |
rack_size = gr.Dropdown(choices=["Quarter Rack", "Half Rack", "Full Rack"], label="Rack Size", visible=False)
|
171 |
+
llm_selector = gr.Dropdown(choices=list(supported_llms.keys()), value="gpt-4-turbo", label="LLM Model")
|
172 |
|
173 |
def toggle_visibility(mode):
|
174 |
return gr.update(visible=mode), gr.update(visible=mode)
|
|
|
177 |
|
178 |
analyze_btn = gr.Button("Analyze AWR Report")
|
179 |
output = gr.Textbox(label="AWR Analysis", lines=20)
|
180 |
+
health = gr.Textbox(label="Health Agent Findings", lines=10)
|
181 |
rating = gr.Textbox(label="Rater", lines=3)
|
182 |
retry_status = gr.Textbox(label="Retry Status")
|
183 |
|
184 |
+
analyze_btn.click(process_awr,
|
185 |
+
inputs=[awr_text, threshold, performance_test_mode, exadata_model, rack_size, llm_selector],
|
186 |
+
outputs=[output, health, rating, retry_status])
|
187 |
|
188 |
+
demo.launch(debug=True)
|