# /// script # requires-python = ">=3.10" # dependencies = ["chromadb-client==1.5.9", "openai>=1.60"] # /// """Ask a question about the exe-docs collection. Finds the five closest chunks in Chroma, prints where they came from, and has a model answer from them, both through the exe.dev LLM integration. uv run ask.py "How do I make my VM public?" """ import os, sys import chromadb from openai import OpenAI os.environ.setdefault("CHROMA_OPENAI_API_KEY", "exe-gateway") question = " ".join(sys.argv[1:]) or "How do I make my VM public?" host = os.environ.get("CHROMA_URL", "http://localhost:8000") # The collection remembers its embedding function (model and base URL), # so Chroma embeds the question the same way as the documents. col = chromadb.HttpClient(host=host).get_collection("exe-docs") res = col.query(query_texts=[question], n_results=5) context = [] for doc, meta, dist in zip(res["documents"][0], res["metadatas"][0], res["distances"][0]): print(f"{dist:.3f} {meta['title']} > {meta['heading']} {meta['url']}") context.append(f"From {meta['url']} ({meta['heading']}):\n{doc}") llm = OpenAI(base_url="https://llm.int.exe.xyz/v1", api_key="exe-gateway") answer = llm.responses.create( model=os.environ.get("MODEL", "gpt-5.4-mini"), instructions="Answer from the documentation excerpts only, briefly, and name the page you used.", input="\n\n".join(context) + f"\n\nQuestion: {question}", ) print("\n" + answer.output_text)