Files
vllm-omni/examples/offline_inference/qwen2_5_omni/extract_prompts.py
T

44 lines
1.1 KiB
Python
Raw Normal View History

2025-11-11 10:49:53 +08:00
#!/usr/bin/env python3
import argparse
def extract_prompt(line: str) -> str | None:
2025-11-30 16:45:30 -08:00
# Extract the content between the first '|' and the second '|'
2025-11-17 14:44:10 +08:00
i = line.find("|")
2025-11-11 10:49:53 +08:00
if i == -1:
return None
2025-11-17 14:44:10 +08:00
j = line.find("|", i + 1)
2025-11-11 10:49:53 +08:00
if j == -1:
return None
2025-11-17 14:44:10 +08:00
return line[i + 1 : j].strip()
2025-11-11 10:49:53 +08:00
def main() -> None:
parser = argparse.ArgumentParser()
2025-11-11 11:56:08 +08:00
parser.add_argument("--input", "-i", required=True, help="Input .lst file path")
parser.add_argument("--output", "-o", required=True, help="Output file path")
2025-11-17 14:44:10 +08:00
parser.add_argument(
"--topk",
"-k",
type=int,
default=100,
help="Extract the top K prompts (default: 100)",
)
2025-11-11 10:49:53 +08:00
args = parser.parse_args()
prompts = []
2025-11-18 20:54:26 +08:00
with open(args.input, encoding="utf-8", errors="ignore") as f:
2025-11-11 10:49:53 +08:00
for line in f:
if len(prompts) >= args.topk:
break
p = extract_prompt(line.rstrip("\n"))
if p:
prompts.append(p)
with open(args.output, "w", encoding="utf-8") as f:
for p in prompts:
f.write(p + "\n")
if __name__ == "__main__":
main()