()
| 1082 | |
| 1083 | |
| 1084 | def main(): |
| 1085 | parser = argparse.ArgumentParser( |
| 1086 | description="Test llama-server tool-calling capability." |
| 1087 | ) |
| 1088 | parser.add_argument("--host", default="localhost") |
| 1089 | parser.add_argument("--port", default=8080, type=int) |
| 1090 | parser.add_argument( |
| 1091 | "--no-stream", action="store_true", help="Disable streaming mode tests" |
| 1092 | ) |
| 1093 | parser.add_argument( |
| 1094 | "--stream-only", action="store_true", help="Only run streaming mode tests" |
| 1095 | ) |
| 1096 | parser.add_argument( |
| 1097 | "--test", |
| 1098 | help="Run only the test whose name contains this substring (case-insensitive)", |
| 1099 | ) |
| 1100 | args = parser.parse_args() |
| 1101 | |
| 1102 | url = f"http://{args.host}:{args.port}/v1/chat/completions" |
| 1103 | print_info(f"Testing server at {url}") |
| 1104 | |
| 1105 | modes = [] |
| 1106 | if not args.stream_only: |
| 1107 | modes.append(False) |
| 1108 | if not args.no_stream: |
| 1109 | modes.append(True) |
| 1110 | |
| 1111 | cases: list[dict] = ALL_TEST_CASES |
| 1112 | if args.test: |
| 1113 | name_filter = args.test.lower() |
| 1114 | cases = [c for c in cases if name_filter in str(c["name"]).lower()] |
| 1115 | if not cases: |
| 1116 | print_fail(f"No test cases matched '{args.test}'") |
| 1117 | sys.exit(1) |
| 1118 | |
| 1119 | total = 0 |
| 1120 | passed = 0 |
| 1121 | for stream in modes: |
| 1122 | for case in cases: |
| 1123 | total += 1 |
| 1124 | if run_test(url, case, stream=stream): |
| 1125 | passed += 1 |
| 1126 | |
| 1127 | color = GREEN if passed == total else RED |
| 1128 | _print(f"\n{BOLD}{color}{'─'*60}{RESET}") |
| 1129 | _print(f"{BOLD}{color} Results: {passed}/{total} passed{RESET}") |
| 1130 | _print(f"{BOLD}{color}{'─'*60}{RESET}\n") |
| 1131 | sys.exit(0 if passed == total else 1) |
| 1132 | |
| 1133 | |
| 1134 | if __name__ == "__main__": |
no test coverage detected