-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (54 loc) · 1.75 KB
/
Copy pathmain.py
File metadata and controls
64 lines (54 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import argparse
import asyncio
from pathlib import Path
from qoder_agent_sdk import (
AssistantMessage,
QoderAgentOptions,
ResultMessage,
TextBlock,
access_token_from_env,
query,
)
async def run(workspace: Path, prompt: str) -> None:
options = QoderAgentOptions(
auth=access_token_from_env(),
cwd=workspace,
model="auto",
tools=["Read", "Glob", "Grep"],
allowed_tools=["Read", "Glob", "Grep"],
max_turns=4,
)
completed = False
async for message in query(prompt=prompt, options=options):
if isinstance(message, AssistantMessage):
for block in message.content:
if isinstance(block, TextBlock):
print(block.text, end="", flush=True)
elif isinstance(message, ResultMessage):
if message.subtype != "success":
raise RuntimeError("\n".join(message.errors or [message.subtype]))
completed = True
if not completed:
raise RuntimeError("The query ended without a success result.")
print()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("workspace", nargs="?", type=Path, default=Path.cwd())
parser.add_argument(
"prompt",
nargs="*",
default=[],
help="Optional custom prompt",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
prompt = " ".join(args.prompt) or (
"Explain the purpose of this repository and identify its most important files."
)
asyncio.run(run(args.workspace.resolve(), prompt))
if __name__ == "__main__":
try:
main()
except (RuntimeError, OSError) as error:
raise SystemExit(str(error)) from error