From 81a9d1f315e137a18361e12b1703be3767c5799f Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 13 Dec 2024 16:55:56 -0600 Subject: [PATCH] search functionality --- api/search.go | 151 ++++++++++++++++++++++++++++++++++++++++++ api/types.go | 63 ++++++++++++++++++ api/utilities.go | 5 ++ cmd/quickvast/main.go | 17 ----- 4 files changed, 219 insertions(+), 17 deletions(-) create mode 100644 api/search.go create mode 100644 api/utilities.go diff --git a/api/search.go b/api/search.go new file mode 100644 index 0000000..6b02303 --- /dev/null +++ b/api/search.go @@ -0,0 +1,151 @@ +package api + +import ( + "encoding/json" + "net/http" +) + +type ComparableInteger struct { + eq *int `json:"eq,omitempty"` + lt *int `json:"lt,omitempty"` + le *int `json:"le,omitempty"` + gt *int `json:"gt,omitempty"` + ge *int `json:"ge,omitempty"` +} + +type ComparableFloat struct { + eq *float64 `json:"eq,omitempty"` + lt *float64 `json:"lt,omitempty"` + le *float64 `json:"le,omitempty"` + gt *float64 `json:"gt,omitempty"` + ge *float64 `json:"ge,omitempty"` +} + +type AdvancedSearch struct { + Verified *bool `json:"verified,omitempty"` + ComputeCap *ComparableInteger `json:"compute_cap,omitempty"` + DiskSpace *ComparableInteger `json:"disk_space,omitempty"` + Order []string `json:"order,omitempty"` + Type string `json:"type,omitempty"` + BwNVLink *ComparableInteger `json:"bw_nvlink,omitempty"` + CPUCores *ComparableInteger `json:"cpu_cores,omitempty"` + CPUCoresEffective *ComparableInteger `json:"cpu_cores_effective,omitempty"` + CPURam *ComparableInteger `json:"cpu_ram,omitempty"` + CudaVers *ComparableInteger `json:"cuda_vers,omitempty"` + DirectPortCount *ComparableInteger `json:"direct_port_count,omitempty"` + DiskBw *ComparableFloat `json:"disk_bw,omitempty"` + DLPerf *ComparableFloat `json:"dlperf,omitempty"` + DLPerfUSD *ComparableFloat `json:"dlperf_usd,omitempty"` + DPH *ComparableFloat `json:"dph,omitempty"` + DriverVersion *string `json:"driver_version,omitempty"` + Duration *ComparableFloat `json:"duration,omitempty"` + External *bool `json:"external,omitempty"` + FlopsUSD *ComparableFloat `json:"flops_usd,omitempty"` + GPUMemBw *ComparableFloat `json:"gpu_mem_bw,omitempty"` + GPUName *string `json:"gpu_name,omitempty"` + GPURam *ComparableInteger `json:"gpu_ram,omitempty"` + GPUFrac *ComparableFloat `json:"gpu_frac,omitempty"` + HasAVX *bool `json:"has_avx,omitempty"` + ID *ComparableInteger `json:"id,omitempty"` + InetDown *ComparableFloat `json:"inet_down,omitempty"` + InetDownCost *ComparableFloat `json:"inet_down_cost,omitempty"` + InetUp *ComparableFloat `json:"inet_up,omitempty"` + InetUpCost *ComparableFloat `json:"inet_up_cost,omitempty"` + MachineID *ComparableInteger `json:"machine_id,omitempty"` + MinBid *ComparableFloat `json:"min_bid,omitempty"` + NumGPUs *ComparableInteger `json:"num_gpus,omitempty"` + PCIGen *ComparableInteger `json:"pci_gen,omitempty"` + PCIeBw *ComparableFloat `json:"pcie_bw,omitempty"` + Reliability *ComparableFloat `json:"reliability,omitempty"` + Rentable *bool `json:"rentable,omitempty"` + Rented *bool `json:"rented,omitempty"` + StorageCost *ComparableFloat `json:"storage_cost,omitempty"` + TotalFlops *ComparableFloat `json:"total_flops,omitempty"` +} + +func NewSearch() *AdvancedSearch { + return &AdvancedSearch{ + Rented: Pointer(false), + } +} + +type Offer struct { + IsBid bool `json:"is_bid"` + InetUpBilled *float64 `json:"inet_up_billed"` + InetDownBilled *float64 `json:"inet_down_billed"` + External bool `json:"external"` + Webpage *string `json:"webpage"` + Logo string `json:"logo"` + Rentable bool `json:"rentable"` + ComputeCap int `json:"compute_cap"` + DriverVersion string `json:"driver_version"` + CudaMaxGood int `json:"cuda_max_good"` + MachineID int `json:"machine_id"` + HostingType *string `json:"hosting_type"` + PublicIPAddr string `json:"public_ipaddr"` + Geolocation string `json:"geolocation"` + FlopsPerDPHTotal float64 `json:"flops_per_dphtotal"` + DLPerfPerDPHTotal float64 `json:"dlperf_per_dphtotal"` + Reliability2 float64 `json:"reliability2"` + HostRunTime int `json:"host_run_time"` + HostID int `json:"host_id"` + ID int `json:"id"` + BundleID int `json:"bundle_id"` + NumGPUs int `json:"num_gpus"` + TotalFlops float64 `json:"total_flops"` + MinBid float64 `json:"min_bid"` + DPHBase float64 `json:"dph_base"` + DPHTotal float64 `json:"dph_total"` + GPUName string `json:"gpu_name"` + GPURam int `json:"gpu_ram"` + GPUDisplayActive bool `json:"gpu_display_active"` + GPUMemBw float64 `json:"gpu_mem_bw"` + BwNVLink int `json:"bw_nvlink"` + DirectPortCount int `json:"direct_port_count"` + GPULanes int `json:"gpu_lanes"` + PCIeBw float64 `json:"pcie_bw"` + PCIGen int `json:"pci_gen"` + DLPerf float64 `json:"dlperf"` + CPUName string `json:"cpu_name"` + MoboName string `json:"mobo_name"` + CPURam int `json:"cpu_ram"` + CPUCores int `json:"cpu_cores"` + CPUCoresEffective int `json:"cpu_cores_effective"` + GPUFrac float64 `json:"gpu_frac"` + HasAVX int `json:"has_avx"` + DiskSpace float64 `json:"disk_space"` + DiskName string `json:"disk_name"` + DiskBw float64 `json:"disk_bw"` + InetUp float64 `json:"inet_up"` + InetDown float64 `json:"inet_down"` + StartDate float64 `json:"start_date"` + EndDate *float64 `json:"end_date"` + Duration *float64 `json:"duration"` + StorageCost float64 `json:"storage_cost"` + InetUpCost float64 `json:"inet_up_cost"` + InetDownCost float64 `json:"inet_down_cost"` + StorageTotalCost float64 `json:"storage_total_cost"` + Verification string `json:"verification"` + Score float64 `json:"score"` + Rented bool `json:"rented"` + BundledResults int `json:"bundled_results"` + PendingCount int `json:"pending_count"` +} + +type SearchResponse struct { + Offers []Offer `json:"offers"` +} + +func (c *Client) Search(search *AdvancedSearch) (*SearchResponse, error) { + resp, err := c.makeRequest(http.MethodPost, "/bundles/", nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var result SearchResponse + if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { + return nil, err + } + return &result, nil +} diff --git a/api/types.go b/api/types.go index b513933..1c7b7fe 100644 --- a/api/types.go +++ b/api/types.go @@ -97,3 +97,66 @@ type Instance struct { MachineDirSSHPort int `json:"machine_dir_ssh_port"` Ports Ports `json:"ports"` } + +type Offer struct { + IsBid bool `json:"is_bid"` + InetUpBilled *float64 `json:"inet_up_billed"` + InetDownBilled *float64 `json:"inet_down_billed"` + External bool `json:"external"` + Webpage *string `json:"webpage"` + Logo string `json:"logo"` + Rentable bool `json:"rentable"` + ComputeCap int `json:"compute_cap"` + DriverVersion string `json:"driver_version"` + CudaMaxGood int `json:"cuda_max_good"` + MachineID int `json:"machine_id"` + HostingType *string `json:"hosting_type"` + PublicIPAddr string `json:"public_ipaddr"` + Geolocation string `json:"geolocation"` + FlopsPerDPHTotal float64 `json:"flops_per_dphtotal"` + DLPerfPerDPHTotal float64 `json:"dlperf_per_dphtotal"` + Reliability2 float64 `json:"reliability2"` + HostRunTime int `json:"host_run_time"` + HostID int `json:"host_id"` + ID int `json:"id"` + BundleID int `json:"bundle_id"` + NumGPUs int `json:"num_gpus"` + TotalFlops float64 `json:"total_flops"` + MinBid float64 `json:"min_bid"` + DPHBase float64 `json:"dph_base"` + DPHTotal float64 `json:"dph_total"` + GPUName string `json:"gpu_name"` + GPURam int `json:"gpu_ram"` + GPUDisplayActive bool `json:"gpu_display_active"` + GPUMemBw float64 `json:"gpu_mem_bw"` + BwNVLink int `json:"bw_nvlink"` + DirectPortCount int `json:"direct_port_count"` + GPULanes int `json:"gpu_lanes"` + PCIeBw float64 `json:"pcie_bw"` + PCIGen int `json:"pci_gen"` + DLPerf float64 `json:"dlperf"` + CPUName string `json:"cpu_name"` + MoboName string `json:"mobo_name"` + CPURam int `json:"cpu_ram"` + CPUCores int `json:"cpu_cores"` + CPUCoresEffective int `json:"cpu_cores_effective"` + GPUFrac float64 `json:"gpu_frac"` + HasAVX int `json:"has_avx"` + DiskSpace float64 `json:"disk_space"` + DiskName string `json:"disk_name"` + DiskBw float64 `json:"disk_bw"` + InetUp float64 `json:"inet_up"` + InetDown float64 `json:"inet_down"` + StartDate float64 `json:"start_date"` + EndDate *float64 `json:"end_date"` + Duration *float64 `json:"duration"` + StorageCost float64 `json:"storage_cost"` + InetUpCost float64 `json:"inet_up_cost"` + InetDownCost float64 `json:"inet_down_cost"` + StorageTotalCost float64 `json:"storage_total_cost"` + Verification string `json:"verification"` + Score float64 `json:"score"` + Rented bool `json:"rented"` + BundledResults int `json:"bundled_results"` + PendingCount int `json:"pending_count"` +} diff --git a/api/utilities.go b/api/utilities.go new file mode 100644 index 0000000..5b0616e --- /dev/null +++ b/api/utilities.go @@ -0,0 +1,5 @@ +package api + +func Pointer[T any](d T) *T { + return &d +} diff --git a/cmd/quickvast/main.go b/cmd/quickvast/main.go index 922d89a..2bee063 100644 --- a/cmd/quickvast/main.go +++ b/cmd/quickvast/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "os" @@ -24,20 +23,4 @@ func main() { // Create client client := api.NewClient(apiKey) - - // Get instances - resp, err := client.GetInstances() - if err != nil { - log.Fatalf("Error getting instances: %v", err) - } - - if len(resp.Instances) == 0 { - fmt.Println("No instances found") - return - } - - // Print instances - for _, instance := range resp.Instances { - fmt.Printf("Instance %d: %+v\n", instance.ID, instance) - } }