import shcortex_lib
import time
import os

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LIB = os.path.join(ROOT, "target", "release", "shcortex_lib.dll")

def generate_large_conversation(num_turns=100):
    lines = []
    for i in range(num_turns):
        speaker = "Alice" if i % 2 == 0 else "Bob"
        line = f"{speaker}: This is a long conversation turn {i+1} with many words to ensure we exceed the 500-token threshold and trigger the structured prompt format. We are testing the compression and latency of SHCortex with large contexts."
        lines.append(line)
    return "\n".join(lines)

def main():
    text = generate_large_conversation(100)
    tokens = text.split()
    print(f"Generated {len(tokens)} tokens.")

    sc = shcortex_lib.SHCortex()
    start = time.perf_counter()
    sc.compress(text, 0.7, 5)
    prompt = sc.build_prompt("What is the main topic?")
    resp, latency = sc.bench_latency(text, "What is the main topic?", "nemotron-3-super:cloud")
    print(f"Latency: {latency:.2f} ms")
    print("--- Prompt ---")
    print(prompt)
    print("--- Response ---")
    print(resp)

if __name__ == "__main__":
    main()