fix: update API endpoints to use /api/v1 prefix, fix blockchain node URL, resolve variable scoping issues, and accept multiple success status codes
- Change marketplace endpoints from /v1/* to /api/v1/* for consistency - Update blockchain status node 1 URL from localhost:8082 to localhost:8003 - Fix blockchain health endpoint to use /health instead of /v1/health - Generate unique workflow_id using uuid.uuid4() instead of undefined agent_id variable - Accept both 200 and 202 status codes for agent
This commit is contained in:
@@ -35,7 +35,7 @@ def create(ctx, name: str, description: str, workflow_file, verification: str,
|
||||
"name": name,
|
||||
"description": description,
|
||||
"verification_level": verification,
|
||||
"workflow_id": agent_id,
|
||||
"workflow_id": str(uuid.uuid4()),
|
||||
"inputs": {},
|
||||
"max_execution_time": max_execution_time,
|
||||
"max_cost_budget": max_cost_budget
|
||||
@@ -150,7 +150,7 @@ def execute(ctx, agent_id: str, inputs, verification: str, priority: str, timeou
|
||||
json=execution_data
|
||||
)
|
||||
|
||||
if response.status_code == 202:
|
||||
if response.status_code in (200, 202):
|
||||
execution = response.json()
|
||||
success(f"Agent execution started: {execution['id']}")
|
||||
output(execution, ctx.obj['output_format'])
|
||||
@@ -344,7 +344,7 @@ def execute(ctx, network_id: str, task, priority: str):
|
||||
json=execution_data
|
||||
)
|
||||
|
||||
if response.status_code == 202:
|
||||
if response.status_code in (200, 202):
|
||||
execution = response.json()
|
||||
success(f"Network execution started: {execution['id']}")
|
||||
output(execution, ctx.obj['output_format'])
|
||||
@@ -503,7 +503,7 @@ def train(ctx, agent_id: str, feedback, epochs: int):
|
||||
json=training_data
|
||||
)
|
||||
|
||||
if response.status_code == 202:
|
||||
if response.status_code in (200, 202):
|
||||
training = response.json()
|
||||
success(f"Training started: {training['id']}")
|
||||
output(training, ctx.obj['output_format'])
|
||||
|
||||
@@ -108,7 +108,7 @@ def status(ctx, node: int):
|
||||
|
||||
# Map node to RPC URL
|
||||
node_urls = {
|
||||
1: "http://localhost:8082",
|
||||
1: "http://localhost:8003",
|
||||
2: "http://localhost:9080/rpc", # Use RPC API with correct endpoint
|
||||
3: "http://aitbc.keisanki.net/rpc"
|
||||
}
|
||||
@@ -120,8 +120,8 @@ def status(ctx, node: int):
|
||||
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
# First get health for general status
|
||||
health_url = rpc_url.replace("/rpc", "") + "/v1/health" if "/rpc" in rpc_url else rpc_url + "/v1/health"
|
||||
# Use health endpoint that exists
|
||||
health_url = rpc_url + "/health"
|
||||
response = client.get(
|
||||
health_url,
|
||||
timeout=5
|
||||
|
||||
@@ -51,7 +51,7 @@ def register(ctx, name: str, memory: Optional[int], cuda_cores: Optional[int],
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/register",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/register",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"X-Api-Key": config.api_key or "",
|
||||
@@ -96,7 +96,7 @@ def list(ctx, available: bool, model: Optional[str], memory_min: Optional[int],
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/list",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/list",
|
||||
params=params,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
@@ -120,7 +120,7 @@ def details(ctx, gpu_id: str):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/{gpu_id}",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/{gpu_id}",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -152,7 +152,7 @@ def book(ctx, gpu_id: str, hours: float, job_id: Optional[str]):
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/{gpu_id}/book",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/{gpu_id}/book",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"X-Api-Key": config.api_key or ""
|
||||
@@ -180,7 +180,7 @@ def release(ctx, gpu_id: str):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/{gpu_id}/release",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/{gpu_id}/release",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -208,7 +208,7 @@ def orders(ctx, status: Optional[str], limit: int):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/orders",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/orders",
|
||||
params=params,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
@@ -232,7 +232,7 @@ def pricing(ctx, model: str):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/pricing/{model}",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/pricing/{model}",
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -256,7 +256,7 @@ def reviews(ctx, gpu_id: str, limit: int):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/{gpu_id}/reviews",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/{gpu_id}/reviews",
|
||||
params={"limit": limit},
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
@@ -291,7 +291,7 @@ def review(ctx, gpu_id: str, rating: int, comment: Optional[str]):
|
||||
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/gpu/{gpu_id}/reviews",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/gpu/{gpu_id}/reviews",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"X-Api-Key": config.api_key or ""
|
||||
@@ -344,7 +344,7 @@ def submit(ctx, provider: str, capacity: int, price: float, notes: Optional[str]
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/bids",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/bids",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"X-Api-Key": config.api_key or ""
|
||||
@@ -383,7 +383,7 @@ def list(ctx, status: Optional[str], provider: Optional[str], limit: int):
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/bids",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/bids",
|
||||
params=params,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
@@ -450,7 +450,7 @@ def create(ctx, gpu_id: str, price_per_hour: float, min_hours: float,
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/offers",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/offers",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"X-Api-Key": config.api_key or ""
|
||||
@@ -499,7 +499,7 @@ def list(ctx, status: Optional[str], gpu_model: Optional[str], price_max: Option
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
f"{config.coordinator_url}/v1/marketplace/offers",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/offers",
|
||||
params=params,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
@@ -622,7 +622,7 @@ def list_resource(ctx, resource_id: str, resource_type: str, compute_power: floa
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/list",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/list",
|
||||
json=resource_data,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
@@ -661,7 +661,7 @@ def rent(ctx, resource_id: str, consumer_id: str, duration: int, max_price: Opti
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
response = client.post(
|
||||
f"{config.coordinator_url}/v1/marketplace/rent",
|
||||
f"{config.coordinator_url}/api/v1/marketplace/rent",
|
||||
json=rental_data,
|
||||
headers={"X-Api-Key": config.api_key or ""}
|
||||
)
|
||||
|
||||
@@ -107,6 +107,7 @@ def wallet(ctx, wallet_name: Optional[str], wallet_path: Optional[str]):
|
||||
if not wallet_name:
|
||||
# Try to get from config or use 'default'
|
||||
config_file = Path.home() / ".aitbc" / "config.yaml"
|
||||
config = None
|
||||
if config_file.exists():
|
||||
with open(config_file, "r") as f:
|
||||
config = yaml.safe_load(f)
|
||||
@@ -116,10 +117,18 @@ def wallet(ctx, wallet_name: Optional[str], wallet_path: Optional[str]):
|
||||
wallet_name = "default"
|
||||
else:
|
||||
wallet_name = "default"
|
||||
else:
|
||||
# Load config for other operations
|
||||
config_file = Path.home() / ".aitbc" / "config.yaml"
|
||||
config = None
|
||||
if config_file.exists():
|
||||
with open(config_file, "r") as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
ctx.obj["wallet_name"] = wallet_name
|
||||
ctx.obj["wallet_dir"] = wallet_dir
|
||||
ctx.obj["wallet_path"] = wallet_dir / f"{wallet_name}.json"
|
||||
ctx.obj["config"] = config
|
||||
|
||||
|
||||
@wallet.command()
|
||||
@@ -499,7 +508,7 @@ def balance(ctx):
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
blockchain_balance = result.get("balance", 0)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
# Method 2: Try addresses list endpoint
|
||||
@@ -550,7 +559,7 @@ def balance(ctx):
|
||||
ctx.obj.get("output_format", "table"),
|
||||
)
|
||||
return
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
# Fallback to local balance only
|
||||
|
||||
Reference in New Issue
Block a user