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
34 changes: 17 additions & 17 deletions commands/displayers/gradientai.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (v *Agent) JSON(out io.Writer) error {

func (a *Agent) Cols() []string {
return []string{
"Id",
"ID",
"Name",
"Region",
"Project-id",
Expand All @@ -38,7 +38,7 @@ func (a *Agent) Cols() []string {

func (a *Agent) ColMap() map[string]string {
return map[string]string{
"Id": "ID",
"ID": "ID",
"Name": "Name",
"Region": "Region",
"Project-id": "Project ID",
Expand All @@ -59,7 +59,7 @@ func (a *Agent) KV() []map[string]any {
modelID = agent.Model.Uuid
}
out = append(out, map[string]any{
"Id": agent.Uuid,
"ID": agent.Uuid,
"Name": agent.Name,
"Region": agent.Region,
"Project-id": agent.ProjectId,
Expand Down Expand Up @@ -372,7 +372,7 @@ func (f *FunctionRoute) JSON(out io.Writer) error {

func (f *FunctionRoute) Cols() []string {
return []string{
"Uuid",
"UUID",
"Name",
"Description",
"FaasName",
Expand All @@ -384,7 +384,7 @@ func (f *FunctionRoute) Cols() []string {

func (f *FunctionRoute) ColMap() map[string]string {
return map[string]string{
"Uuid": "UUID",
"UUID": "UUID",
"Name": "Name",
"Description": "Description",
"FaasName": "FaaS Name",
Expand All @@ -402,7 +402,7 @@ func (f *FunctionRoute) KV() []map[string]any {
out := make([]map[string]any, 0, len(f.Agent.Functions))
for _, fn := range f.Agent.Functions {
out = append(out, map[string]any{
"Uuid": fn.Uuid,
"UUID": fn.Uuid,
"Name": fn.Name,
"Description": fn.Description,
"FaasName": fn.FaasName,
Expand All @@ -426,7 +426,7 @@ func (a *AgentRoute) JSON(out io.Writer) error {

func (a *AgentRoute) Cols() []string {
return []string{
"Id",
"ID",
"ParentAgentId",
"ChildAgentId",
"Rollback",
Expand All @@ -435,9 +435,9 @@ func (a *AgentRoute) Cols() []string {

func (a *AgentRoute) ColMap() map[string]string {
return map[string]string{
"Id": "Id",
"ParentAgentId": "Parent Agent Id",
"ChildAgentId": "Child Agent Id",
"ID": "ID",
"ParentAgentId": "Parent Agent ID",
"ChildAgentId": "Child Agent ID",
"Rollback": "Rollback",
}
}
Expand All @@ -450,7 +450,7 @@ func (a *AgentRoute) KV() []map[string]any {

for _, response := range a.AgentRouteResponses {
o := map[string]any{
"Id": response.UUID,
"ID": response.UUID,
"ParentAgentId": response.ParentAgentUuid,
"ChildAgentId": response.ChildAgentUuid,
"Rollback": response.Rollback,
Expand All @@ -469,7 +469,7 @@ func (v *ApiKeyInfo) JSON(out io.Writer) error {

func (a *ApiKeyInfo) Cols() []string {
return []string{
"Id",
"ID",
"Name",
"CreatedBy",
"SecretKey",
Expand All @@ -480,7 +480,7 @@ func (a *ApiKeyInfo) Cols() []string {

func (a *ApiKeyInfo) ColMap() map[string]string {
return map[string]string{
"Id": "ID",
"ID": "ID",
"Name": "Name",
"SecretKey": "Secret Key",
"CreatedBy": "Created By",
Expand All @@ -497,7 +497,7 @@ func (a *ApiKeyInfo) KV() []map[string]any {
for _, apikey := range a.ApiKeyInfo {

out = append(out, map[string]any{
"Id": apikey.Uuid,
"ID": apikey.Uuid,
"Name": apikey.Name,
"SecretKey": apikey.SecretKey,
"CreatedBy": apikey.CreatedBy,
Expand Down Expand Up @@ -625,7 +625,7 @@ func (m *Model) JSON(out io.Writer) error {
}
func (m *Model) Cols() []string {
return []string{
"Id",
"ID",
"Name",
"Agreement",
"CreatedAt",
Expand All @@ -640,7 +640,7 @@ func (m *Model) Cols() []string {

func (m *Model) ColMap() map[string]string {
return map[string]string{
"Id": "ID",
"ID": "ID",
"Name": "Name",
"Agreement": "Agreement",
"CreatedAt": "Created At",
Expand Down Expand Up @@ -672,7 +672,7 @@ func (m *Model) KV() []map[string]any {
}

out = append(out, map[string]any{
"Id": model.Uuid,
"ID": model.Uuid,
"Name": model.Name,
"Agreement": agreementName,
"CreatedAt": model.CreatedAt,
Expand Down
4 changes: 2 additions & 2 deletions commands/gradientai.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func GradientAI() *Command {
// Add the knowledgebase command as a subcommand to Gradient AI
cmd.AddCommand(KnowledgeBaseCmd())
// Add the model command as a subcommand to Gradient AI
cmd.AddCommand(ListModelsCmd())
cmd.AddCommand(ListModelsCmd(cmd))
// Add the region command as a subcommand to Gradient AI
cmd.AddCommand(ListRegionsCmd())
cmd.AddCommand(ListRegionsCmd(cmd))
// Add the OpenAI keys command as a subcommand to Gradient AI
cmd.AddCommand(OpenAIKeyCmd())

Expand Down
4 changes: 2 additions & 2 deletions commands/gradientai_list_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/digitalocean/doctl/commands/displayers"
)

func ListModelsCmd() *Command {
cmd := CmdBuilder(nil, RunGradientAIListModels, "list-models", "List Gradient AI models", `The `+"`doctl gradient list-models`"+` command lists all available Gradient AI models.
func ListModelsCmd(parent *Command) *Command {
cmd := CmdBuilder(parent, RunGradientAIListModels, "list-models", "List Gradient AI models", `The `+"`doctl gradient list-models`"+` command lists all available Gradient AI models.

The command returns the following details for each model:
- The model ID
Expand Down
22 changes: 21 additions & 1 deletion commands/gradientai_list_models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ limitations under the License.
package commands

import (
"bytes"
"testing"
"time"

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/do"
"github.com/digitalocean/godo"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -78,7 +81,8 @@ var (
)

func TestListModelsCommand(t *testing.T) {
cmd := ListModelsCmd()
parent := &Command{Command: &cobra.Command{Use: "gradient"}}
cmd := ListModelsCmd(parent)
assert.NotNil(t, cmd)
assert.Equal(t, "list-models", cmd.Use)
assert.Contains(t, cmd.Aliases, "models")
Expand All @@ -104,3 +108,19 @@ func TestRunGradientAIListModelsError(t *testing.T) {
assert.Error(t, err)
})
}

func TestRunGradientAIListModelsFormatNoHeader(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.gradientAI.EXPECT().ListAvailableModels().Return(testModels, nil)

var buf bytes.Buffer
config.NS = "gradient.list-models"
config.Out = &buf
config.Doit.Set(config.NS, doctl.ArgFormat, "ID,Name")
config.Doit.Set(config.NS, doctl.ArgNoHeader, true)

err := RunGradientAIListModels(config)
assert.NoError(t, err)
assert.Equal(t, "model-1 GPT-4 Turbo\nmodel-2 Claude 3.5 Sonnet\n", buf.String())
})
}
4 changes: 2 additions & 2 deletions commands/gradientai_list_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/digitalocean/doctl/commands/displayers"
)

func ListRegionsCmd() *Command {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list-models and list-regions are now registered twice
After this PR, both commands appear duplicated in doctl gradient --help:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @DO-rrao! Good catch. I'll spend a little bit more time on that.

cmd := CmdBuilder(nil, RunGradientAIListRegions, "list-regions", "List Gradient AI regions", `The `+"`doctl gradient list-regions`"+` command lists all available Gradient AI regions.
func ListRegionsCmd(parent *Command) *Command {
cmd := CmdBuilder(parent, RunGradientAIListRegions, "list-regions", "List Gradient AI regions", `The `+"`doctl gradient list-regions`"+` command lists all available Gradient AI regions.

The command returns the following details for each region:
- Inference URL: The URL for the inference server
Expand Down
26 changes: 25 additions & 1 deletion commands/gradientai_list_regions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ limitations under the License.
package commands

import (
"bytes"
"testing"

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/do"
"github.com/digitalocean/godo"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -62,7 +64,8 @@ var (
)

func TestListRegionsCommand(t *testing.T) {
cmd := ListRegionsCmd()
parent := &Command{Command: &cobra.Command{Use: "gradient"}}
cmd := ListRegionsCmd(parent)
assert.NotNil(t, cmd)
assert.Equal(t, "list-regions", cmd.Use)
assert.Equal(t, "List Gradient AI regions", cmd.Short)
Expand Down Expand Up @@ -90,3 +93,24 @@ func TestRunGradientAIListRegionsError(t *testing.T) {
assert.Error(t, err)
})
}

func TestRunGradientAIListRegionsFormatNoHeader(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.gradientAI.EXPECT().ListDatacenterRegions(nil, nil).Return(testDatacenterRegions, nil)

var buf bytes.Buffer
config.NS = "gradient.list-regions"
config.Out = &buf
config.Command = &cobra.Command{}
config.Doit.Set(config.NS, doctl.ArgFormat, "Region,InferenceURL")
config.Doit.Set(config.NS, doctl.ArgNoHeader, true)

err := RunGradientAIListRegions(config)
assert.NoError(t, err)
expected := "" +
"nyc1 https://inference.nyc1.digitalocean.com\n" +
"sfo3 https://inference.sfo3.digitalocean.com\n" +
"tor1 https://inference.tor1.digitalocean.com\n"
assert.Equal(t, expected, buf.String())
})
}
6 changes: 3 additions & 3 deletions integration/gradientai_agent_route_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ var _ = suite("gen-ai/agent/route/update", func(t *testing.T, when spec.G, it sp
expect.NoError(err, fmt.Sprintf("received error output: %s", output))
outputStr := string(output)

expect.Contains(outputStr, "Id")
expect.Contains(outputStr, "Parent Agent Id")
expect.Contains(outputStr, "Child Agent Id")
expect.Contains(outputStr, "ID")
expect.Contains(outputStr, "Parent Agent ID")
expect.Contains(outputStr, "Child Agent ID")
expect.Contains(outputStr, "Rollback")

expect.Contains(outputStr, "00000000-0000-4000-a000-000000000000")
Expand Down
Loading