feat: Add RunPod start and improved pod creation
- Added a new `start_on_demand_pod` function to the RunPod client. - Improved the `create_on_demand_pod` function to handle nested machine structure in the response. - Updated the example to use the new functions and handle the new response structure. - Updated the API key for the example. - Added more descriptive field names in the `create_on_demand_pod` input. Co-authored-by: mariobassem12 <mariobassem12@gmail.com>
This commit is contained in:
@@ -6,23 +6,23 @@ import freeflowuniverse.herolib.clients.runpod
|
|||||||
// Example 1: Create client with direct API key
|
// Example 1: Create client with direct API key
|
||||||
mut rp := runpod.get_or_create(
|
mut rp := runpod.get_or_create(
|
||||||
name: 'example1'
|
name: 'example1'
|
||||||
api_key: 'rpa_JDYDWBS0PDTC55T1BYT1PX85CL4D5YEBZ48LETRXyf4gxr'
|
api_key: 'rpa_YYQ2HSM1AVP55MKX39R3LTH5KDCSWJBVKG5Y52Z2oryd46'
|
||||||
)!
|
)!
|
||||||
|
|
||||||
// Create a new on demand pod
|
// Create a new on demand pod
|
||||||
pod_response := rp.create_on_demand_pod(
|
on_demand_pod_response := rp.create_on_demand_pod(
|
||||||
name: 'RunPod Tensorflow'
|
name: 'RunPod Tensorflow'
|
||||||
image_name: 'runpod/tensorflow'
|
image_name: 'runpod/tensorflow'
|
||||||
cloud_type: .all
|
cloud_type: .all
|
||||||
gpu_count: 1
|
gpu_count: 1
|
||||||
volume_in_gb: 40
|
volume_in_gb: 40
|
||||||
container_disk_in_gb: 40
|
container_disk_in_gb: 40
|
||||||
min_memory_in_gb: 15
|
min_memory_in_gb: 15
|
||||||
min_vcpu_count: 2
|
min_vcpu_count: 2
|
||||||
gpu_type_id: "NVIDIA RTX A6000"
|
gpu_type_id: 'NVIDIA RTX A6000'
|
||||||
ports: "8888/http"
|
ports: '8888/http'
|
||||||
volume_mount_path: "/workspace"
|
volume_mount_path: '/workspace'
|
||||||
env: [
|
env: [
|
||||||
runpod.EnvironmentVariableInput{
|
runpod.EnvironmentVariableInput{
|
||||||
key: 'JUPYTER_PASSWORD'
|
key: 'JUPYTER_PASSWORD'
|
||||||
value: 'rn51hunbpgtltcpac3ol'
|
value: 'rn51hunbpgtltcpac3ol'
|
||||||
@@ -30,7 +30,7 @@ pod_response := rp.create_on_demand_pod(
|
|||||||
]
|
]
|
||||||
)!
|
)!
|
||||||
|
|
||||||
println('Created pod with ID: ${pod_response.id}')
|
println('Created pod with ID: ${on_demand_pod_response.id}')
|
||||||
|
|
||||||
// create a spot pod
|
// create a spot pod
|
||||||
spot_pod_resp := rp.create_spot_pod(
|
spot_pod_resp := rp.create_spot_pod(
|
||||||
@@ -56,3 +56,7 @@ spot_pod_resp := rp.create_spot_pod(
|
|||||||
]
|
]
|
||||||
)!
|
)!
|
||||||
println('Created spot pod with ID: ${spot_pod_resp.id}')
|
println('Created spot pod with ID: ${spot_pod_resp.id}')
|
||||||
|
|
||||||
|
// start on-demand pod
|
||||||
|
start_on_demand_pod := rp.start_on_demand_pod(pod_id: '${on_demand_pod_response.id}', gpu_count: 1)!
|
||||||
|
println('Started pod with ID: ${start_on_demand_pod.id}')
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
module runpod
|
module runpod
|
||||||
|
|
||||||
|
// Represents the nested machine structure in the response
|
||||||
|
pub struct Machine {
|
||||||
|
pub:
|
||||||
|
pod_host_id string @[json: 'podHostId']
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response structure for the mutation
|
||||||
|
pub struct PodResult {
|
||||||
|
pub:
|
||||||
|
id string @[json: 'id']
|
||||||
|
image_name string @[json: 'imageName']
|
||||||
|
env []string @[json: 'env']
|
||||||
|
machine_id int @[json: 'machineId']
|
||||||
|
machine Machine @[json: 'machine']
|
||||||
|
desired_status string @[json: 'desiredStatus']
|
||||||
|
}
|
||||||
|
|
||||||
// Input structure for the mutation
|
// Input structure for the mutation
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PodFindAndDeployOnDemandRequest {
|
pub struct PodFindAndDeployOnDemandRequest {
|
||||||
@@ -19,7 +36,7 @@ pub mut:
|
|||||||
env []EnvironmentVariableInput @[json: 'env']
|
env []EnvironmentVariableInput @[json: 'env']
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_endpoint creates a new endpoint
|
// Create On-Demand Pod
|
||||||
pub fn (mut rp RunPod) create_on_demand_pod(input PodFindAndDeployOnDemandRequest) !PodResult {
|
pub fn (mut rp RunPod) create_on_demand_pod(input PodFindAndDeployOnDemandRequest) !PodResult {
|
||||||
return rp.create_pod_find_and_deploy_on_demand_request(input)!
|
return rp.create_pod_find_and_deploy_on_demand_request(input)!
|
||||||
}
|
}
|
||||||
@@ -59,6 +76,19 @@ pub mut:
|
|||||||
allowed_cuda_versions []string @[json: 'allowedCudaVersions']
|
allowed_cuda_versions []string @[json: 'allowedCudaVersions']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create Spot Pod
|
||||||
pub fn (mut rp RunPod) create_spot_pod(input PodRentInterruptableInput) !PodResult {
|
pub fn (mut rp RunPod) create_spot_pod(input PodRentInterruptableInput) !PodResult {
|
||||||
return rp.create_create_spot_pod_request(input)!
|
return rp.create_create_spot_pod_request(input)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct PodResume {
|
||||||
|
pub mut:
|
||||||
|
pod_id string @[json: 'podId']
|
||||||
|
gpu_count int @[json: 'gpuCount']
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start On-Demand Pod
|
||||||
|
pub fn (mut rp RunPod) start_on_demand_pod(input PodResume) !PodResult {
|
||||||
|
return rp.start_on_demand_pod_request(input)!
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,3 +41,17 @@ fn (mut rp RunPod) create_create_spot_pod_request(input PodRentInterruptableInpu
|
|||||||
return error('Could not find podRentInterruptable in response data: ${response_.data}')
|
return error('Could not find podRentInterruptable in response data: ${response_.data}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start On-Demand Pod
|
||||||
|
fn (mut rp RunPod) start_on_demand_pod_request(input PodResume) !PodResult {
|
||||||
|
gql := build_query(
|
||||||
|
query_type: .mutation
|
||||||
|
method_name: 'podResume'
|
||||||
|
request_model: input
|
||||||
|
response_model: PodResult{}
|
||||||
|
)
|
||||||
|
response_ := rp.make_request[GqlResponse[PodResult]](.post, '/graphql', gql)!
|
||||||
|
return response_.data['podResume'] or {
|
||||||
|
return error('Could not find podRentInterruptable in response data: ${response_.data}')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,22 +49,6 @@ pub:
|
|||||||
value string
|
value string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents the nested machine structure in the response
|
|
||||||
pub struct Machine {
|
|
||||||
pub:
|
|
||||||
pod_host_id string @[json: 'podHostId']
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response structure for the mutation
|
|
||||||
pub struct PodResult {
|
|
||||||
pub:
|
|
||||||
id string @[json: 'id']
|
|
||||||
image_name string @[json: 'imageName']
|
|
||||||
env []string @[json: 'env']
|
|
||||||
machine_id int @[json: 'machineId']
|
|
||||||
machine Machine @[json: 'machine']
|
|
||||||
}
|
|
||||||
|
|
||||||
// new creates a new RunPod client
|
// new creates a new RunPod client
|
||||||
pub fn new(api_key string) !&RunPod {
|
pub fn new(api_key string) !&RunPod {
|
||||||
if api_key == '' {
|
if api_key == '' {
|
||||||
|
|||||||
Reference in New Issue
Block a user