Files
herolib/lib/clients/runpod/runpod_http.v
mariobassem 4422d67701 wip: add spot pod creation
- Add support for creating spot pods using the RunPod API.
- Implement `create_spot_pod` function in the `RunPod` client.
- Refactor RunPod client to handle different query types and response structures.
- Improve error handling and logging for GraphQL requests.
- Update example to demonstrate spot pod creation.

Co-authored-by: mahmmoud.hassanein <mahmmoud.hassanein@gmail.com>
2025-01-20 21:34:16 +02:00

53 lines
1.4 KiB
V

module runpod
import freeflowuniverse.herolib.core.httpconnection
import json
fn (mut rp RunPod) httpclient() !&httpconnection.HTTPConnection {
mut http_conn := httpconnection.new(
name: 'runpod_${rp.name}'
url: 'https://api.runpod.io'
cache: true
retry: 3
)!
// Add authorization header
http_conn.default_header.add(.authorization, 'Bearer ${rp.api_key}')
return http_conn
}
// Represents the entire mutation and input structure
struct PodFindAndDeployOnDemand[T, V] {
input T @[json: 'input']
response V @[json: 'response']
}
// GraphQL query structs
struct GqlQuery {
query string
}
// GraphQL response wrapper
struct GqlResponse[T] {
data map[string]T
}
// struct GqlResponseData[T] {
// pod_find_and_deploy_on_demand T @[json: 'podFindAndDeployOnDemand']
// }
fn (mut rp RunPod) create_pop_find_and_deploy_on_demand_request(request PodFindAndDeployOnDemandRequest) !PodFindAndDeployOnDemandResponse {
gql := build_query(BuildQueryArgs{
query_type: .mutation
method_name: 'podFindAndDeployOnDemand'
}, request, PodFindAndDeployOnDemandResponse{})
println('gql: ${gql}')
response_ := rp.make_request[GqlResponse[PodFindAndDeployOnDemandResponse]](.post,
'/graphql', gql)!
println('response: ${json.encode(response_)}')
return response_.data['podFindAndDeployOnDemand'] or {
return error('Could not find podFindAndDeployOnDemand in response data: ${response_.data}')
}
// return response.data.pod_find_and_deploy_on_demand
}