Skip to content

Commit 7a0063d

Browse files
Merge pull request #29 from cybozu/feature/improve-cli-mode
fix cli output
2 parents de1db28 + 02a4785 commit 7a0063d

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

src/improve.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from llm_client import call_llm_api_for_improve
33
from utils import validate_chat_completion_format
44
from schema import PromptInput
5-
from prompt import show_prompt
65

76

87
def improve_prompt(
@@ -15,9 +14,6 @@ def improve_prompt(
1514
apply_techniques: Optional[List[str]] = None,
1615
aws_region: Optional[str] = None,
1716
) -> PromptInput:
18-
print("Improving prompt...")
19-
print(f"Target prompt: {show_prompt(target_prompt)}")
20-
2117
if apply_techniques is None:
2218
apply_techniques = []
2319

src/main.py

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,20 @@ def average_satisfaction(evaluation: Dict[str, Any]) -> float:
208208
def main() -> None:
209209
args = parse_args()
210210
if args.command == "webui":
211+
print("\033[36m" + "Launching web UI..." + "\033[0m")
211212
launch_webui()
212213
if args.command == "improve":
213214
# Load and parse prompt
214215
current_prompt = parse_prompt_input(
215216
args.target_prompt_path, args.input_mode, args.input_format
216217
)
217218
print(
218-
f"Loaded prompt from {args.target_prompt_path}:\n{show_prompt(current_prompt)}"
219+
"\033[36m"
220+
+ "\n🔍 Loaded Prompt from: "
221+
+ args.target_prompt_path
222+
+ "\033[0m"
219223
)
224+
print(show_prompt(current_prompt))
220225

221226
if args.attack_api_mode is None:
222227
args.attack_api_mode = args.eval_api_mode
@@ -237,15 +242,19 @@ def main() -> None:
237242
args.user_input_description,
238243
)
239244
initial_avg_score = average_satisfaction(initial_evaluation)
240-
print("Initial Evaluation Result:")
241-
print(initial_evaluation)
242-
print(f"Initial Average Satisfaction Score: {initial_avg_score:.2f}")
245+
print("\033[35m" + "\n🧪 Initial Evaluation Result:" + "\033[0m")
246+
print(json.dumps(initial_evaluation, indent=2, ensure_ascii=False))
247+
print(
248+
"\033[33m"
249+
+ f"\n📊 Initial Average Satisfaction Score: {initial_avg_score:.2f}"
250+
+ "\033[0m"
251+
)
243252

244253
evaluation_result = initial_evaluation
245254
final_avg_score = initial_avg_score
246255

247256
for i in range(args.max_iterations):
248-
print(f"\n--- Iteration {i + 1} ---")
257+
print("\033[36m" + f"\n{'=' * 20} Iteration {i + 1} {'=' * 20}" + "\033[0m")
249258
if i > 0:
250259
evaluation_result = evaluate_prompt(
251260
args.eval_api_mode,
@@ -254,15 +263,21 @@ def main() -> None:
254263
args.user_input_description,
255264
aws_region=args.aws_region,
256265
)
257-
print("Evaluation Result:")
258-
print(evaluation_result)
266+
print("\033[35m" + "🔍 Evaluation Result:" + "\033[0m")
267+
print(json.dumps(evaluation_result, indent=2, ensure_ascii=False))
259268

260269
final_avg_score = average_satisfaction(evaluation_result)
261-
print(f"Average Satisfaction Score: {final_avg_score:.2f}")
270+
print(
271+
"\033[33m"
272+
+ f"📊 Average Satisfaction Score: {final_avg_score:.2f}"
273+
+ "\033[0m"
274+
)
262275

263276
if final_avg_score >= args.threshold:
264277
print(
265-
"Prompt meets the required security threshold. Stopping refinement."
278+
"\033[32m"
279+
+ "✅ Prompt meets the required security threshold. Stopping refinement."
280+
+ "\033[0m"
266281
)
267282
break
268283

@@ -276,36 +291,44 @@ def main() -> None:
276291
apply_techniques=apply_techniques,
277292
aws_region=args.aws_region,
278293
)
279-
print("Improved Prompt:")
294+
print("\033[32m" + "\nImproved Prompt:" + "\033[0m")
280295
print(show_prompt(current_prompt))
281296

282297
if args.max_iterations == 1 or final_avg_score < args.threshold:
283-
print("\n--- Final Evaluation ---")
284298
evaluation_result = evaluate_prompt(
285299
args.eval_api_mode,
286300
args.eval_model,
287301
current_prompt,
288302
args.user_input_description,
289303
)
290-
print("Final Evaluation Result:")
291-
print(evaluation_result)
292304
final_avg_score = average_satisfaction(evaluation_result)
293-
print(f"Average Satisfaction Score: {final_avg_score:.2f}")
305+
print("\033[35m" + "\n🎯 Final Evaluation Result:" + "\033[0m")
306+
print(json.dumps(evaluation_result, indent=2, ensure_ascii=False))
307+
print(
308+
"\033[33m" + f"\n📈 Final Avg Score: {final_avg_score:.2f}" + "\033[0m"
309+
)
294310

295311
# Write the improved prompt to output file
296-
print("\n--- Writing Improved Prompt to Output File ---")
312+
print(
313+
"\033[36m" + "\n--- Writing Improved Prompt to Output File ---" + "\033[0m"
314+
)
297315
write_prompt_output(
298316
args.output_path,
299317
current_prompt,
300318
args.input_mode,
301319
args.input_format,
302320
)
321+
print("\033[32m" + f"✅ Prompt written to: {args.output_path}" + "\033[0m")
303322

304323
# Run injection test if requested
305324
attack_results = []
306325
if args.test_after:
307326
tools = load_tools(args.tools_path) if args.tools_path else None
308-
print("\n--- Running injection test on final prompt ---")
327+
print(
328+
"\033[36m"
329+
+ "\n--- Running injection test on final prompt ---"
330+
+ "\033[0m"
331+
)
309332
attack_results = run_injection_test(
310333
current_prompt,
311334
args.attack_api_mode,
@@ -319,7 +342,11 @@ def main() -> None:
319342

320343
if args.report_dir:
321344
report_dir_path = os.path.abspath(args.report_dir)
322-
print(f"\n--- Generating report at {report_dir_path} ---")
345+
print(
346+
"\033[36m"
347+
+ f"\n--- Generating report at {report_dir_path} ---"
348+
+ "\033[0m"
349+
)
323350
generate_report(
324351
initial_prompt,
325352
initial_evaluation,
@@ -336,7 +363,7 @@ def main() -> None:
336363
args.attack_api_mode,
337364
args.judge_api_mode,
338365
)
339-
print("Report generation complete.")
366+
print("\033[32m" + "✅ Report generation complete." + "\033[0m")
340367

341368

342369
if __name__ == "__main__":

src/prompt.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ def write_prompt_output(
161161
else:
162162
raise ValueError(f"Unsupported input_mode={input_mode} for writing output")
163163

164-
print(f"✅ Prompt written in {output_format} format to: {output_path}")
165-
166164

167165
def show_prompt(prompt: PromptInput) -> str:
168166
"""

0 commit comments

Comments
 (0)