draftboard 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- draftboard/__init__.py +41 -0
- draftboard/__main__.py +225 -0
- draftboard/agent.py +104 -0
- draftboard/api.py +901 -0
- draftboard/measure.py +225 -0
- draftboard/models.py +407 -0
- draftboard/pptx_export.py +479 -0
- draftboard/render.py +80 -0
- draftboard/static/404.html +1 -0
- draftboard/static/__next.__PAGE__.txt +27 -0
- draftboard/static/__next._full.txt +22 -0
- draftboard/static/__next._tree.txt +3 -0
- draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_buildManifest.js +11 -0
- draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_clientMiddlewareManifest.js +1 -0
- draftboard/static/_next/static/0t_Cdsf-nvbYcwqDy78ch/_ssgManifest.js +1 -0
- draftboard/static/_next/static/chunks/0cz1d0mv5g_q7.js +1 -0
- draftboard/static/_next/static/chunks/0oheds1fsp9jx.js +1 -0
- draftboard/static/_next/static/chunks/1vsonpqt4u2rw.js +1 -0
- draftboard/static/_next/static/chunks/24xul4hawiu8l.js +1 -0
- draftboard/static/_next/static/chunks/2r7iycbt4s29o.js +22 -0
- draftboard/static/_next/static/chunks/2utugak-w5oge.css +1 -0
- draftboard/static/_next/static/chunks/39_j1bdzreq0m.js +1 -0
- draftboard/static/_next/static/chunks/3qfy96eoyh-ek.js +1 -0
- draftboard/static/_next/static/chunks/3u8gxd9uztfzl.js +4 -0
- draftboard/static/_next/static/chunks/3v_59l1qr_8dp.js +31 -0
- draftboard/static/_next/static/chunks/turbopack-2u1d16houkiyo.js +1 -0
- draftboard/static/_not-found/__next._full.txt +20 -0
- draftboard/static/_not-found/__next._not-found/__PAGE__.txt +26 -0
- draftboard/static/_not-found/__next._tree.txt +4 -0
- draftboard/static/_not-found.html +1 -0
- draftboard/static/_not-found.txt +20 -0
- draftboard/static/index.html +1 -0
- draftboard/static/index.txt +22 -0
- draftboard/static/p/__placeholder__/__next._full.txt +27 -0
- draftboard/static/p/__placeholder__/__next._tree.txt +5 -0
- draftboard/static/p/__placeholder__/__next.p/$d$id/__PAGE__.txt +34 -0
- draftboard/static/p/__placeholder__/preview/__next._full.txt +27 -0
- draftboard/static/p/__placeholder__/preview/__next._tree.txt +6 -0
- draftboard/static/p/__placeholder__/preview/__next.p/$d$id/preview/__PAGE__.txt +35 -0
- draftboard/static/p/__placeholder__/preview.html +1 -0
- draftboard/static/p/__placeholder__/preview.txt +27 -0
- draftboard/static/p/__placeholder__.html +1 -0
- draftboard/static/p/__placeholder__.txt +27 -0
- draftboard/storage.py +183 -0
- draftboard/tasks.py +464 -0
- draftboard/themes.py +213 -0
- draftboard/tools.py +723 -0
- draftboard-0.0.1.dist-info/METADATA +16 -0
- draftboard-0.0.1.dist-info/RECORD +51 -0
- draftboard-0.0.1.dist-info/WHEEL +4 -0
- draftboard-0.0.1.dist-info/entry_points.txt +2 -0
draftboard/__init__.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Draftboard package."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import pathlib
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
# Ensure backend/.venv/Lib/site-packages is present in sys.path
|
|
8
|
+
backend_venv_sp = (
|
|
9
|
+
pathlib.Path(__file__).resolve().parent.parent.parent
|
|
10
|
+
/ ".venv"
|
|
11
|
+
/ "Lib"
|
|
12
|
+
/ "site-packages"
|
|
13
|
+
)
|
|
14
|
+
if backend_venv_sp.exists():
|
|
15
|
+
sp_str = str(backend_venv_sp)
|
|
16
|
+
if sp_str not in sys.path:
|
|
17
|
+
sys.path.insert(0, sp_str)
|
|
18
|
+
|
|
19
|
+
# On Windows, pywin32 modules (win32, win32/lib, pywin32_system32) require their
|
|
20
|
+
# directories to be explicitly in sys.path and DLL search path if pywin32_bootstrap
|
|
21
|
+
# was skipped by trampolines or custom runners.
|
|
22
|
+
if sys.platform == "win32":
|
|
23
|
+
candidates: list[pathlib.Path] = []
|
|
24
|
+
for p in sys.path:
|
|
25
|
+
if "site-packages" in p:
|
|
26
|
+
candidates.append(pathlib.Path(p))
|
|
27
|
+
if backend_venv_sp.exists() and backend_venv_sp not in candidates:
|
|
28
|
+
candidates.append(backend_venv_sp)
|
|
29
|
+
|
|
30
|
+
for sp in candidates:
|
|
31
|
+
for sub in ("win32", "win32/lib", "pythonwin", "pywin32_system32"):
|
|
32
|
+
target = sp / sub
|
|
33
|
+
if target.exists():
|
|
34
|
+
t_str = str(target)
|
|
35
|
+
if t_str not in sys.path:
|
|
36
|
+
sys.path.append(t_str)
|
|
37
|
+
if hasattr(os, "add_dll_directory"):
|
|
38
|
+
try:
|
|
39
|
+
os.add_dll_directory(t_str)
|
|
40
|
+
except Exception:
|
|
41
|
+
pass
|
draftboard/__main__.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI entry point for the Draftboard workbench.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
draftboard run "Your prompt here" [--output result.json]
|
|
6
|
+
draftboard init <project_id>
|
|
7
|
+
draftboard export <ir_json> [-o out.pptx]
|
|
8
|
+
draftboard outline <project_id> <version>
|
|
9
|
+
draftboard confirm <project_id> <version>
|
|
10
|
+
draftboard export-deck <project_id> <artifact_id> [--revision N]
|
|
11
|
+
draftboard serve [--host HOST] [--port PORT]
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import asyncio
|
|
16
|
+
import json
|
|
17
|
+
import pathlib
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
from dotenv import load_dotenv
|
|
21
|
+
|
|
22
|
+
load_dotenv()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main() -> None:
|
|
26
|
+
parser = argparse.ArgumentParser(description="Draftboard AI workbench CLI")
|
|
27
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
28
|
+
|
|
29
|
+
# run: run agent with a prompt
|
|
30
|
+
run_p = sub.add_parser("run", help="Run agent with a prompt")
|
|
31
|
+
run_p.add_argument("prompt", help="Prompt to send to the agent")
|
|
32
|
+
run_p.add_argument("--output", "-o", help="Save result to this JSON file")
|
|
33
|
+
|
|
34
|
+
# init: create a project directory with sample assets
|
|
35
|
+
init_p = sub.add_parser("init", help="Init a new project")
|
|
36
|
+
init_p.add_argument("project_id", help="Project ID")
|
|
37
|
+
|
|
38
|
+
# export: write an IR JSON file to an editable PPTX
|
|
39
|
+
export_p = sub.add_parser("export", help="Export an IR JSON file to PPTX")
|
|
40
|
+
export_p.add_argument("ir_json", help="Path to the artifact IR JSON file")
|
|
41
|
+
export_p.add_argument(
|
|
42
|
+
"--output", "-o", help="Output .pptx path (default: alongside the IR file)"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# outline: show a saved outline for review
|
|
46
|
+
outline_p = sub.add_parser("outline", help="Show a saved outline for review")
|
|
47
|
+
outline_p.add_argument("project_id", help="Project ID")
|
|
48
|
+
outline_p.add_argument("version", help="Outline version, e.g. v-abc12345")
|
|
49
|
+
|
|
50
|
+
# confirm: user explicitly approves an outline
|
|
51
|
+
confirm_p = sub.add_parser("confirm", help="Confirm an outline (user approval)")
|
|
52
|
+
confirm_p.add_argument("project_id", help="Project ID")
|
|
53
|
+
confirm_p.add_argument("version", help="Outline version to confirm")
|
|
54
|
+
|
|
55
|
+
# export-deck: export a stored artifact revision to PPTX
|
|
56
|
+
deck_p = sub.add_parser("export-deck", help="Export a stored artifact to PPTX")
|
|
57
|
+
deck_p.add_argument("project_id", help="Project ID")
|
|
58
|
+
deck_p.add_argument("artifact_id", help="Artifact ID")
|
|
59
|
+
deck_p.add_argument(
|
|
60
|
+
"--revision", type=int, default=None, help="Revision (default: latest)"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# serve: run the web API + single-port frontend workbench
|
|
64
|
+
serve_p = sub.add_parser("serve", help="Run the Draftboard web workbench & API")
|
|
65
|
+
serve_p.add_argument("--host", default="127.0.0.1", help="Bind host")
|
|
66
|
+
serve_p.add_argument("--port", type=int, default=8000, help="Bind port")
|
|
67
|
+
serve_p.add_argument("--reload", action="store_true", help="Enable auto-reload on code changes")
|
|
68
|
+
serve_p.add_argument("--build", action="store_true", help="Rebuild frontend static bundle before starting")
|
|
69
|
+
|
|
70
|
+
args = parser.parse_args()
|
|
71
|
+
|
|
72
|
+
if args.command == "run":
|
|
73
|
+
from draftboard.agent import run_agent
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
result = asyncio.run(run_agent(args.prompt))
|
|
77
|
+
print(result)
|
|
78
|
+
if args.output:
|
|
79
|
+
pathlib.Path(args.output).write_text(
|
|
80
|
+
json.dumps({"result": result}, ensure_ascii=False, indent=2),
|
|
81
|
+
encoding="utf-8",
|
|
82
|
+
)
|
|
83
|
+
sys.exit(0)
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
|
|
88
|
+
elif args.command == "init":
|
|
89
|
+
project_root = (
|
|
90
|
+
pathlib.Path.home()
|
|
91
|
+
/ ".draftboard"
|
|
92
|
+
/ "projects"
|
|
93
|
+
/ args.project_id
|
|
94
|
+
/ "assets"
|
|
95
|
+
)
|
|
96
|
+
project_root.mkdir(parents=True, exist_ok=True)
|
|
97
|
+
sample = project_root / "intro.md"
|
|
98
|
+
sample.write_text(
|
|
99
|
+
"# My Project\n\nThis is a sample material file.\n\n"
|
|
100
|
+
"## Background\n\nAdd your content here.\n",
|
|
101
|
+
encoding="utf-8",
|
|
102
|
+
)
|
|
103
|
+
print(f"Project '{args.project_id}' initialized at {project_root.parent}")
|
|
104
|
+
sys.exit(0)
|
|
105
|
+
|
|
106
|
+
elif args.command == "export":
|
|
107
|
+
from draftboard.models import Artifact
|
|
108
|
+
from draftboard.pptx_export import export_pptx
|
|
109
|
+
|
|
110
|
+
ir_path = pathlib.Path(args.ir_json)
|
|
111
|
+
output = (
|
|
112
|
+
pathlib.Path(args.output)
|
|
113
|
+
if args.output
|
|
114
|
+
else ir_path.with_suffix(".pptx")
|
|
115
|
+
)
|
|
116
|
+
try:
|
|
117
|
+
artifact = Artifact.model_validate_json(
|
|
118
|
+
ir_path.read_text(encoding="utf-8")
|
|
119
|
+
)
|
|
120
|
+
export_pptx(artifact, output)
|
|
121
|
+
except Exception as e:
|
|
122
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
123
|
+
sys.exit(1)
|
|
124
|
+
print(
|
|
125
|
+
f"Exported {len(artifact.slides)} slides to {output}"
|
|
126
|
+
)
|
|
127
|
+
sys.exit(0)
|
|
128
|
+
|
|
129
|
+
elif args.command == "outline":
|
|
130
|
+
from draftboard.storage import ProjectStorage
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
storage = ProjectStorage(args.project_id)
|
|
134
|
+
outline = storage.load_outline(args.version)
|
|
135
|
+
except KeyError as e:
|
|
136
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
137
|
+
sys.exit(1)
|
|
138
|
+
status = "CONFIRMED" if outline.is_confirmed else "DRAFT (not confirmed)"
|
|
139
|
+
print(f"Outline {outline.outline_version} [{status}]")
|
|
140
|
+
for i, item in enumerate(outline.items, start=1):
|
|
141
|
+
layout = item.layout.value if item.layout else "auto"
|
|
142
|
+
print(f"\n{i}. [{item.outline_item_id}] {item.title} (layout: {layout})")
|
|
143
|
+
print(f" {item.summary}")
|
|
144
|
+
print(f" sources: {', '.join(item.source_ids)} | evidence: {item.evidence_status.value}")
|
|
145
|
+
if not outline.is_confirmed:
|
|
146
|
+
path = storage.root / "outlines" / f"{outline.outline_version}.json"
|
|
147
|
+
print(f"\nTo edit: modify {path}")
|
|
148
|
+
print(f"To approve: draftboard confirm {args.project_id} {outline.outline_version}")
|
|
149
|
+
sys.exit(0)
|
|
150
|
+
|
|
151
|
+
elif args.command == "confirm":
|
|
152
|
+
from draftboard.storage import ProjectStorage
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
storage = ProjectStorage(args.project_id)
|
|
156
|
+
outline = storage.confirm_outline(args.version)
|
|
157
|
+
except KeyError as e:
|
|
158
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
159
|
+
sys.exit(1)
|
|
160
|
+
print(f"Outline {outline.outline_version} confirmed ({len(outline.items)} items).")
|
|
161
|
+
sys.exit(0)
|
|
162
|
+
|
|
163
|
+
elif args.command == "export-deck":
|
|
164
|
+
from draftboard.storage import ProjectStorage
|
|
165
|
+
from draftboard.tools import export_deck_impl
|
|
166
|
+
|
|
167
|
+
storage = ProjectStorage(args.project_id)
|
|
168
|
+
revision = args.revision
|
|
169
|
+
if revision is None:
|
|
170
|
+
revision = storage.next_revision(args.artifact_id) - 1
|
|
171
|
+
if revision < 1:
|
|
172
|
+
print(f"Error: artifact '{args.artifact_id}' has no revisions.", file=sys.stderr)
|
|
173
|
+
sys.exit(1)
|
|
174
|
+
try:
|
|
175
|
+
result = export_deck_impl(args.project_id, args.artifact_id, revision)
|
|
176
|
+
except KeyError as e:
|
|
177
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
178
|
+
sys.exit(1)
|
|
179
|
+
if result.success:
|
|
180
|
+
print(f"Exported {result.slide_count} slides to {result.pptx_path}")
|
|
181
|
+
sys.exit(0)
|
|
182
|
+
print("Export failed:", file=sys.stderr)
|
|
183
|
+
for issue in result.issues:
|
|
184
|
+
print(f" [{issue.code}] {issue.message}", file=sys.stderr)
|
|
185
|
+
sys.exit(1)
|
|
186
|
+
|
|
187
|
+
elif args.command == "serve":
|
|
188
|
+
import shutil
|
|
189
|
+
import subprocess
|
|
190
|
+
import uvicorn
|
|
191
|
+
|
|
192
|
+
pkg_dir = pathlib.Path(__file__).resolve().parent
|
|
193
|
+
has_embedded_ui = (pkg_dir / "static" / "_next").is_dir()
|
|
194
|
+
frontend_dir = (
|
|
195
|
+
pkg_dir.parents[2] / "frontend"
|
|
196
|
+
if len(pkg_dir.parents) > 2
|
|
197
|
+
else None
|
|
198
|
+
)
|
|
199
|
+
out_index = (
|
|
200
|
+
frontend_dir / "out" / "index.html" if frontend_dir else None
|
|
201
|
+
)
|
|
202
|
+
if (
|
|
203
|
+
frontend_dir
|
|
204
|
+
and (frontend_dir / "package.json").exists()
|
|
205
|
+
and (args.build or (not has_embedded_ui and not (out_index and out_index.exists())))
|
|
206
|
+
):
|
|
207
|
+
npm_cmd = shutil.which("npm")
|
|
208
|
+
if npm_cmd:
|
|
209
|
+
print("Building frontend static bundle...")
|
|
210
|
+
subprocess.run([npm_cmd, "run", "build"], cwd=str(frontend_dir), check=False)
|
|
211
|
+
|
|
212
|
+
src_dir = str(pkg_dir)
|
|
213
|
+
print(f"Draftboard workbench: http://{args.host}:{args.port}/")
|
|
214
|
+
uvicorn.run(
|
|
215
|
+
"draftboard.api:app",
|
|
216
|
+
host=args.host,
|
|
217
|
+
port=args.port,
|
|
218
|
+
reload=args.reload,
|
|
219
|
+
reload_dirs=[src_dir] if args.reload else None,
|
|
220
|
+
)
|
|
221
|
+
sys.exit(0)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
if __name__ == "__main__":
|
|
225
|
+
main()
|
draftboard/agent.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agent definition and runner for the Draftboard workbench.
|
|
3
|
+
Uses the OpenAI Agents SDK (openai-agents package).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from agents import Agent, OpenAIChatCompletionsModel, Runner
|
|
10
|
+
from openai import AsyncOpenAI
|
|
11
|
+
|
|
12
|
+
from draftboard.tools import (
|
|
13
|
+
export_deck,
|
|
14
|
+
generate_slides,
|
|
15
|
+
patch_slide,
|
|
16
|
+
propose_outline,
|
|
17
|
+
read_materials,
|
|
18
|
+
validate_artifact,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
SYSTEM_PROMPT = """You are a presentation creation assistant for the Draftboard workbench.
|
|
22
|
+
Your job is to help users turn their materials (Markdown notes, images) into structured, editable presentations.
|
|
23
|
+
|
|
24
|
+
Rules:
|
|
25
|
+
- Always cite source_ids when making claims about materials
|
|
26
|
+
- Never fabricate line numbers or image content
|
|
27
|
+
- Mark evidence as 'unsupported' or 'partial' when you are not sure
|
|
28
|
+
- Follow the pipeline: read_materials -> propose_outline -> user confirms -> generate_slides -> validate_artifact -> export_deck
|
|
29
|
+
- When proposing outline items, pick the most fitting layout: 'cover' (first slide), 'content', 'bullets' (newline-separated points), 'two_column' (requires column_right), 'text_image' (requires image_asset_id matching an actual uploaded image), or 'closing' (last slide); include concise presenter speaker_notes when helpful
|
|
30
|
+
- The outline must be confirmed by the user (via the draftboard confirm CLI command) before you generate slides; you cannot confirm it yourself
|
|
31
|
+
- generate_slides copies the confirmed outline verbatim; never rewrite or re-summarize confirmed content
|
|
32
|
+
- After generating, call validate_artifact, then export_deck
|
|
33
|
+
- Only report success when export_deck returns success=true with a file path; if it returns issues, relay them to the user with the slide and element IDs — never claim completion otherwise
|
|
34
|
+
- Only use the provided tools; do not access external URLs or run shell commands
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def resolve_model(model: Any = None) -> Any:
|
|
39
|
+
"""Resolve model string or OpenAIChatCompletionsModel instance.
|
|
40
|
+
|
|
41
|
+
Supports Google AI Studio (Gemini) via its OpenAI-compatible endpoint:
|
|
42
|
+
https://generativelanguage.googleapis.com/v1beta/openai/
|
|
43
|
+
"""
|
|
44
|
+
if model is not None and not isinstance(model, str):
|
|
45
|
+
return model
|
|
46
|
+
|
|
47
|
+
gemini_key = os.environ.get("GEMINI_API_KEY")
|
|
48
|
+
openai_key = os.environ.get("OPENAI_API_KEY")
|
|
49
|
+
base_url = os.environ.get("OPENAI_BASE_URL")
|
|
50
|
+
|
|
51
|
+
# If GEMINI_API_KEY is provided or base_url points to googleapis:
|
|
52
|
+
if gemini_key or (base_url and "generativelanguage.googleapis.com" in base_url):
|
|
53
|
+
api_key = gemini_key or openai_key
|
|
54
|
+
base_url = base_url or "https://generativelanguage.googleapis.com/v1beta/openai/"
|
|
55
|
+
model_name = (
|
|
56
|
+
model
|
|
57
|
+
or os.environ.get("DRAFTBOARD_MODEL")
|
|
58
|
+
or os.environ.get("GEMINI_MODEL")
|
|
59
|
+
or "gemini-2.5-flash"
|
|
60
|
+
)
|
|
61
|
+
client = AsyncOpenAI(api_key=api_key, base_url=base_url, max_retries=5)
|
|
62
|
+
return OpenAIChatCompletionsModel(model=model_name, openai_client=client)
|
|
63
|
+
|
|
64
|
+
# Standard custom base_url
|
|
65
|
+
if base_url:
|
|
66
|
+
client = AsyncOpenAI(api_key=openai_key, base_url=base_url, max_retries=5)
|
|
67
|
+
model_name = model or os.environ.get("DRAFTBOARD_MODEL", "gpt-4o-mini")
|
|
68
|
+
return OpenAIChatCompletionsModel(model=model_name, openai_client=client)
|
|
69
|
+
|
|
70
|
+
return model or os.environ.get("DRAFTBOARD_MODEL", "gpt-4o-mini")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def create_agent(model: Any = None) -> Agent:
|
|
74
|
+
"""Create and return a configured DraftboardAgent."""
|
|
75
|
+
resolved_model = resolve_model(model)
|
|
76
|
+
return Agent(
|
|
77
|
+
name="DraftboardAgent",
|
|
78
|
+
instructions=SYSTEM_PROMPT,
|
|
79
|
+
tools=[read_materials, propose_outline, generate_slides, patch_slide, validate_artifact, export_deck],
|
|
80
|
+
model=resolved_model,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
async def run_agent(prompt: str, model: Any = None) -> str:
|
|
85
|
+
"""Run the agent with a single prompt and return the final text output.
|
|
86
|
+
|
|
87
|
+
Automatically retries with backoff if a rate limit (429) is encountered,
|
|
88
|
+
which is common when using free tier API keys.
|
|
89
|
+
"""
|
|
90
|
+
import asyncio
|
|
91
|
+
from openai import RateLimitError
|
|
92
|
+
|
|
93
|
+
agent = create_agent(model)
|
|
94
|
+
max_attempts = 4
|
|
95
|
+
for attempt in range(max_attempts):
|
|
96
|
+
try:
|
|
97
|
+
result = await Runner.run(agent, prompt)
|
|
98
|
+
return result.final_output
|
|
99
|
+
except RateLimitError:
|
|
100
|
+
if attempt == max_attempts - 1:
|
|
101
|
+
raise
|
|
102
|
+
wait_time = 12 * (attempt + 1)
|
|
103
|
+
print(f"\n[RateLimit 429] Free-tier RPM window saturated. Waiting {wait_time}s before retry {attempt + 2}/{max_attempts}...")
|
|
104
|
+
await asyncio.sleep(wait_time)
|