Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,10 @@ const (

// ArgDedicatedInferenceTokenName is the name for a dedicated inference auth token.
ArgDedicatedInferenceTokenName = "token-name"

// ArgDedicatedInferenceAcceleratorPage is the page number for paginated accelerator results.
ArgDedicatedInferenceAcceleratorPage = "page"

// ArgDedicatedInferenceAcceleratorPerPage is the number of accelerator results per page.
ArgDedicatedInferenceAcceleratorPerPage = "per-page"
)
28 changes: 20 additions & 8 deletions commands/dedicated_inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ func DedicatedInferenceCmd() *Command {
"Create a dedicated inference endpoint",
`Creates a dedicated inference endpoint on your account using a spec file in JSON or YAML format.
Use the `+"`"+`--spec`+"`"+` flag to provide the path to the spec file.
Optionally provide a Hugging Face access token using `+"`"+`--hugging-face-token`+"`"+`.`,
Optionally provide a Hugging Face access token using `+"`"+`--hugging-face-token`+"`"+` for gated models.
For more information, see https://docs.digitalocean.com/reference/api/digitalocean/#tag/Dedicated-Inference/operation/dedicatedInferences_create`,
Writer,
aliasOpt("c"),
displayerType(&displayers.DedicatedInference{}),
)
AddStringFlag(cmdCreate, doctl.ArgDedicatedInferenceSpec, "", "", `Path to a dedicated inference spec in JSON or YAML format. Set to "-" to read from stdin.`, requiredOpt())
AddStringFlag(cmdCreate, doctl.ArgDedicatedInferenceHuggingFaceToken, "", "", "Hugging Face token for accessing gated models (optional)")
cmdCreate.Example = `The following example creates a dedicated inference endpoint using a spec file: doctl dedicated-inference create --spec spec.yaml --hugging-face-token "hf_mytoken"
cmdCreate.Example = `The following example creates a dedicated inference endpoint using a YAML spec file: doctl dedicated-inference create --spec spec.yaml

For more information, see https://docs.digitalocean.com/reference/api/digitalocean/#tag/Dedicated-Inference/operation/dedicatedInferences_create`
The following example creates a dedicated inference endpoint for a gated Hugging Face model by also providing an access token: doctl dedicated-inference create --spec spec.yaml --hugging-face-token "hf_mytoken"

The following example creates a dedicated inference endpoint by piping the spec from stdin: cat spec.yaml | doctl dedicated-inference create --spec -`

cmdGet := CmdBuilder(
cmd,
Expand Down Expand Up @@ -89,16 +92,19 @@ For more information, see https://docs.digitalocean.com/reference/api/digitaloce
"Update a dedicated inference endpoint",
`Updates a dedicated inference endpoint using a spec file in JSON or YAML format.
Use the `+"`"+`--spec`+"`"+` flag to provide the path to the spec file.
Optionally provide a Hugging Face access token using `+"`"+`--hugging-face-token`+"`"+`.`,
Optionally provide a Hugging Face access token using `+"`"+`--hugging-face-token`+"`"+` for gated models.
For more information, see https://docs.digitalocean.com/reference/api/digitalocean/#tag/Dedicated-Inference/operation/dedicatedInferences_update`,
Writer,
aliasOpt("u"),
displayerType(&displayers.DedicatedInference{}),
)
AddStringFlag(cmdUpdate, doctl.ArgDedicatedInferenceSpec, "", "", `Path to a dedicated inference spec in JSON or YAML format. Set to "-" to read from stdin.`, requiredOpt())
AddStringFlag(cmdUpdate, doctl.ArgDedicatedInferenceHuggingFaceToken, "", "", "Hugging Face token for accessing gated models (optional)")
cmdUpdate.Example = `The following example updates a dedicated inference endpoint using a spec file: doctl dedicated-inference update 12345678-1234-1234-1234-123456789012 --spec spec.yaml
cmdUpdate.Example = `The following example updates a dedicated inference endpoint using a YAML spec file: doctl dedicated-inference update 12345678-1234-1234-1234-123456789012 --spec spec.yaml

The following example updates a dedicated inference endpoint for a gated Hugging Face model by also providing an access token: doctl dedicated-inference update 12345678-1234-1234-1234-123456789012 --spec spec.yaml --hugging-face-token "hf_mytoken"

For more information, see https://docs.digitalocean.com/reference/api/digitalocean/#tag/Dedicated-Inference/operation/dedicatedInferences_update`
The following example updates a dedicated inference endpoint by piping the spec from stdin: cat spec.yaml | doctl dedicated-inference update 12345678-1234-1234-1234-123456789012 --spec -`

cmdList := CmdBuilder(
cmd,
Expand Down Expand Up @@ -131,9 +137,13 @@ Optionally use `+"`"+`--slug`+"`"+` to filter by accelerator slug.`,
displayerType(&displayers.DedicatedInferenceAccelerator{}),
)
AddStringFlag(cmdListAccelerators, doctl.ArgDedicatedInferenceAcceleratorSlug, "", "", "Filter accelerators by slug (optional)")
AddIntFlag(cmdListAccelerators, doctl.ArgDedicatedInferenceAcceleratorPage, "", 1, "Page number for paginated results (optional)")
AddIntFlag(cmdListAccelerators, doctl.ArgDedicatedInferenceAcceleratorPerPage, "", 20, "Number of results per page (optional)")
cmdListAccelerators.Example = `The following example lists accelerators for a dedicated inference endpoint: doctl dedicated-inference list-accelerators 12345678-1234-1234-1234-123456789012

The following example filters by slug: doctl dedicated-inference list-accelerators 12345678-1234-1234-1234-123456789012 --slug gpu-mi300x1-192gb`
The following example filters by slug: doctl dedicated-inference list-accelerators 12345678-1234-1234-1234-123456789012 --slug gpu-mi300x1-192gb

The following example retrieves the second page of accelerators with 10 results per page: doctl dedicated-inference list-accelerators 12345678-1234-1234-1234-123456789012 --page 2 --per-page 10`

cmdCreateToken := CmdBuilder(
cmd,
Expand Down Expand Up @@ -304,8 +314,10 @@ func RunDedicatedInferenceListAccelerators(c *CmdConfig) error {
diID := c.Args[0]

slug, _ := c.Doit.GetString(c.NS, doctl.ArgDedicatedInferenceAcceleratorSlug)
page, _ := c.Doit.GetInt(c.NS, doctl.ArgDedicatedInferenceAcceleratorPage)
perPage, _ := c.Doit.GetInt(c.NS, doctl.ArgDedicatedInferenceAcceleratorPerPage)

accelerators, err := c.DedicatedInferences().ListAccelerators(diID, slug)
accelerators, err := c.DedicatedInferences().ListAccelerators(diID, slug, page, perPage)
if err != nil {
return err
}
Expand Down
32 changes: 30 additions & 2 deletions commands/dedicated_inference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,11 @@ func TestRunDedicatedInferenceListAccelerators(t *testing.T) {
},
}

tm.dedicatedInferences.EXPECT().ListAccelerators("00000000-0000-4000-8000-000000000000", "").Return(testAccelerators, nil)
tm.dedicatedInferences.EXPECT().ListAccelerators("00000000-0000-4000-8000-000000000000", "", 1, 20).Return(testAccelerators, nil)

config.Args = append(config.Args, "00000000-0000-4000-8000-000000000000")
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorPage, 1)
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorPerPage, 20)

err := RunDedicatedInferenceListAccelerators(config)
assert.NoError(t, err)
Expand All @@ -403,10 +405,36 @@ func TestRunDedicatedInferenceListAccelerators_WithSlug(t *testing.T) {
},
}

tm.dedicatedInferences.EXPECT().ListAccelerators("00000000-0000-4000-8000-000000000000", "gpu-mi300x1-192gb").Return(testAccelerators, nil)
tm.dedicatedInferences.EXPECT().ListAccelerators("00000000-0000-4000-8000-000000000000", "gpu-mi300x1-192gb", 1, 20).Return(testAccelerators, nil)

config.Args = append(config.Args, "00000000-0000-4000-8000-000000000000")
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorSlug, "gpu-mi300x1-192gb")
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorPage, 1)
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorPerPage, 20)

err := RunDedicatedInferenceListAccelerators(config)
assert.NoError(t, err)
})
}

func TestRunDedicatedInferenceListAccelerators_WithPagination(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
testAccelerators := do.DedicatedInferenceAcceleratorInfos{
{
DedicatedInferenceAcceleratorInfo: &godo.DedicatedInferenceAcceleratorInfo{
ID: "accel-3",
Name: "gpu-h100x1-80gb",
Slug: "gpu-h100x1-80gb",
Status: "ACTIVE",
},
},
}

tm.dedicatedInferences.EXPECT().ListAccelerators("00000000-0000-4000-8000-000000000000", "", 2, 10).Return(testAccelerators, nil)

config.Args = append(config.Args, "00000000-0000-4000-8000-000000000000")
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorPage, 2)
config.Doit.Set(config.NS, doctl.ArgDedicatedInferenceAcceleratorPerPage, 10)

err := RunDedicatedInferenceListAccelerators(config)
assert.NoError(t, err)
Expand Down
30 changes: 11 additions & 19 deletions do/dedicated_inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type DedicatedInferenceService interface {
Update(id string, req *godo.DedicatedInferenceUpdateRequest) (*DedicatedInference, error)
List(region string, name string) (DedicatedInferenceListItems, error)
Delete(id string) error
ListAccelerators(diID string, slug string) (DedicatedInferenceAcceleratorInfos, error)
ListAccelerators(diID string, slug string, page int, perPage int) (DedicatedInferenceAcceleratorInfos, error)
CreateToken(diID string, req *godo.DedicatedInferenceTokenCreateRequest) (*DedicatedInferenceToken, error)
ListTokens(diID string) (DedicatedInferenceTokens, error)
RevokeToken(diID string, tokenID string) error
Expand Down Expand Up @@ -161,31 +161,23 @@ func (s *dedicatedInferenceService) List(region string, name string) (DedicatedI
}

// ListAccelerators lists accelerators for a dedicated inference endpoint.
func (s *dedicatedInferenceService) ListAccelerators(diID string, slug string) (DedicatedInferenceAcceleratorInfos, error) {
f := func(opt *godo.ListOptions) ([]any, *godo.Response, error) {
list, resp, err := s.client.DedicatedInference.ListAccelerators(context.TODO(), diID, &godo.DedicatedInferenceListAcceleratorsOptions{Slug: slug, ListOptions: *opt})
if err != nil {
return nil, nil, err
}

items := make([]any, len(list))
for i := range list {
items[i] = list[i]
}
return items, resp, nil
func (s *dedicatedInferenceService) ListAccelerators(diID string, slug string, page int, perPage int) (DedicatedInferenceAcceleratorInfos, error) {
opts := &godo.DedicatedInferenceListAcceleratorsOptions{
Slug: slug,
ListOptions: godo.ListOptions{Page: page, PerPage: perPage},
}

si, err := PaginateResp(f)
list, _, err := s.client.DedicatedInference.ListAccelerators(context.TODO(), diID, opts)
if err != nil {
return nil, err
}

list := make(DedicatedInferenceAcceleratorInfos, len(si))
for i := range si {
a := si[i].(godo.DedicatedInferenceAcceleratorInfo)
list[i] = DedicatedInferenceAcceleratorInfo{DedicatedInferenceAcceleratorInfo: &a}
result := make(DedicatedInferenceAcceleratorInfos, len(list))
for i := range list {
a := list[i]
result[i] = DedicatedInferenceAcceleratorInfo{DedicatedInferenceAcceleratorInfo: &a}
}
return list, nil
return result, nil
}

// CreateToken creates a new auth token for a dedicated inference endpoint.
Expand Down
Loading