Skip to content

Commit

Permalink
error handling; default autotx params and setting port in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
nerfZael committed Jun 10, 2024
1 parent cfc648c commit d393fd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion autotx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def serve(verbose: bool, logs: str | None, max_rounds: int | None, cache: bool,
print_autotx_info()

setup_server(verbose, logs, max_rounds, cache, dev, check_valid_safe=True)
uvicorn.run("autotx.server:app", host="localhost", port=8000, workers=1)
uvicorn.run("autotx.server:app", host="localhost", port=port if port else 8000, workers=1)

@main.command()
@click.option("-n", "--name", type=str, help="Name of the application to create")
Expand Down
15 changes: 13 additions & 2 deletions autotx/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self,
self.max_rounds = max_rounds
self.is_dev = is_dev

autotx_params: AutoTxParams | None = None
autotx_params: AutoTxParams = AutoTxParams(verbose=False, logs=None, cache=False, max_rounds=None, is_dev=False)

app_router = APIRouter()

Expand Down Expand Up @@ -107,7 +107,15 @@ def on_notify_user(message: str) -> None:
)

async def run_task() -> None:
await autotx.a_run(prompt, non_interactive=True)
try:
await autotx.a_run(prompt, non_interactive=True)
except Exception as e:
task = tasks.get(task_id)
if task is None:
raise Exception("Task not found: " + task_id)

task.messages.append(str(e))
tasks.update(task)
tasks.stop(task_id)

background_tasks.add_task(run_task)
Expand Down Expand Up @@ -180,6 +188,9 @@ def send_transactions(task_id: str, model: models.SendTransactionsParams, author
global autotx_params
if autotx_params is None:
raise HTTPException(status_code=500, detail="AutoTx not started")

if task.transactions is None or len(task.transactions) == 0:
raise HTTPException(status_code=400, detail="No transactions to send")

if autotx_params.is_dev:
print("Dev mode: skipping transaction submission")
Expand Down

0 comments on commit d393fd3

Please sign in to comment.