Using the Gaffa LLMs.txt File with Your AI Assistant
Step 1: Get the LLMs.txt File
Step 2: Load It Into Your AI Assistant
Step 3: Ask the Assistant to Write Your Script
Step 4: Example Script
import os, time, requests, pathlib, urllib.parse
API_KEY = os.environ.get("GAFFA_API_KEY", "YOUR_API_KEY")
BASE = "https://api.gaffa.dev"
def submit_request(url, actions, async_mode=True):
payload = {
"url": url,
"async": async_mode,
"settings": {"actions": actions}
}
r = requests.post(
f"{BASE}/v1/browser/requests",
headers={"X-API-Key": API_KEY, "Content-Type": "application/json"},
json=payload
)
r.raise_for_status()
return r.json()["data"]
def wait_for_completion(request_id, poll_every=2, max_wait=180):
start = time.time()
while True:
r = requests.get(
f"{BASE}/v1/browser/requests/{request_id}",
headers={"X-API-Key": API_KEY}
)
data = r.json()["data"]
if data["state"] in ("completed", "failed"):
return data
if time.time() - start > max_wait:
raise TimeoutError("Request timed out")
time.sleep(poll_every)
def download_outputs(brq, dest="outputs"):
dest = pathlib.Path(dest)
dest.mkdir(parents=True, exist_ok=True)
files = []
for act in brq.get("actions") or []:
out = act.get("output")
if isinstance(out, str) and out.startswith("http"):
name = pathlib.Path(urllib.parse.urlparse(out).path).name
p = dest / name
with requests.get(out, stream=True) as r:
with open(p, "wb") as f:
for chunk in r.iter_content(8192):
if chunk: f.write(chunk)
files.append(str(p))
return files
if __name__ == "__main__":
target_url = "https://demo.gaffa.dev/simulate/article?paragraphs=5"
actions = [
{"type": "wait", "selector": "article"},
{"type": "generate_markdown"}
]
job = submit_request(target_url, actions)
brq = wait_for_completion(job["id"])
print("Final state:", brq["state"])
if brq["state"] == "completed":
saved = download_outputs(brq)
print("Downloaded:", saved)Step 5: Extend and Customise
Last updated