github.com/anthropics/anthropic-sdk-go@v1.70.1/betadeployment_test.go (about)

     1  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
     2  
     3  package anthropic_test
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"os"
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/anthropics/anthropic-sdk-go"
    13  	"github.com/anthropics/anthropic-sdk-go/internal/testutil"
    14  	"github.com/anthropics/anthropic-sdk-go/option"
    15  )
    16  
    17  func TestBetaDeploymentNewWithOptionalParams(t *testing.T) {
    18  	baseURL := "http://localhost:4010"
    19  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    20  		baseURL = envURL
    21  	}
    22  	if !testutil.CheckTestServer(t, baseURL) {
    23  		return
    24  	}
    25  	client := anthropic.NewClient(
    26  		option.WithBaseURL(baseURL),
    27  		option.WithAPIKey("my-anthropic-api-key"),
    28  	)
    29  	_, err := client.Beta.Deployments.New(context.TODO(), anthropic.BetaDeploymentNewParams{
    30  		Agent: anthropic.BetaDeploymentNewParamsAgentUnion{
    31  			OfString: anthropic.String("string"),
    32  		},
    33  		EnvironmentID: "x",
    34  		InitialEvents: []anthropic.BetaManagedAgentsDeploymentInitialEventParamsUnion{{
    35  			OfUserMessage: &anthropic.BetaManagedAgentsUserMessageEventParams{
    36  				Content: []anthropic.BetaManagedAgentsUserMessageEventParamsContentUnion{{
    37  					OfText: &anthropic.BetaManagedAgentsTextBlockParam{
    38  						Text: "Where is my order #1234?",
    39  						Type: anthropic.BetaManagedAgentsTextBlockTypeText,
    40  					},
    41  				}},
    42  				Type: anthropic.BetaManagedAgentsUserMessageEventParamsTypeUserMessage,
    43  			},
    44  		}},
    45  		Name: "x",
    46  		Budget: anthropic.BetaManagedAgentsBudgetLimitParam{
    47  			MaxListCost: anthropic.BetaMonetaryAmountParam{
    48  				Amount:   "2500",
    49  				Currency: anthropic.BetaCurrencyUSD,
    50  			},
    51  			Type: anthropic.BetaManagedAgentsBudgetLimitTypeLimit,
    52  		},
    53  		Description: anthropic.String("description"),
    54  		Metadata: map[string]string{
    55  			"foo": "string",
    56  		},
    57  		Resources: []anthropic.BetaDeploymentNewParamsResourceUnion{{
    58  			OfFile: &anthropic.BetaManagedAgentsFileResourceParams{
    59  				FileID:    "file_011CNha8iCJcU1wXNR6q4V8w",
    60  				Type:      anthropic.BetaManagedAgentsFileResourceParamsTypeFile,
    61  				MountPath: anthropic.String("/uploads/receipt.pdf"),
    62  			},
    63  		}},
    64  		Schedule: anthropic.BetaManagedAgentsScheduleParams{
    65  			Expression: "0 9 * * 1-5",
    66  			Timezone:   "America/Los_Angeles",
    67  			Type:       anthropic.BetaManagedAgentsScheduleParamsTypeCron,
    68  		},
    69  		VaultIDs:    []string{"string"},
    70  		Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    71  		WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    72  	})
    73  	if err != nil {
    74  		var apierr *anthropic.Error
    75  		if errors.As(err, &apierr) {
    76  			t.Log(string(apierr.DumpRequest(true)))
    77  		}
    78  		t.Fatalf("err should be nil: %s", err.Error())
    79  	}
    80  }
    81  
    82  func TestBetaDeploymentGetWithOptionalParams(t *testing.T) {
    83  	t.Skip("buildURL drops path-level query params (SDK-4349)")
    84  	baseURL := "http://localhost:4010"
    85  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    86  		baseURL = envURL
    87  	}
    88  	if !testutil.CheckTestServer(t, baseURL) {
    89  		return
    90  	}
    91  	client := anthropic.NewClient(
    92  		option.WithBaseURL(baseURL),
    93  		option.WithAPIKey("my-anthropic-api-key"),
    94  	)
    95  	_, err := client.Beta.Deployments.Get(
    96  		context.TODO(),
    97  		"depl_011CZkZcDH3vPqd7xnEfwTai",
    98  		anthropic.BetaDeploymentGetParams{
    99  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   100  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   101  		},
   102  	)
   103  	if err != nil {
   104  		var apierr *anthropic.Error
   105  		if errors.As(err, &apierr) {
   106  			t.Log(string(apierr.DumpRequest(true)))
   107  		}
   108  		t.Fatalf("err should be nil: %s", err.Error())
   109  	}
   110  }
   111  
   112  func TestBetaDeploymentUpdateWithOptionalParams(t *testing.T) {
   113  	baseURL := "http://localhost:4010"
   114  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   115  		baseURL = envURL
   116  	}
   117  	if !testutil.CheckTestServer(t, baseURL) {
   118  		return
   119  	}
   120  	client := anthropic.NewClient(
   121  		option.WithBaseURL(baseURL),
   122  		option.WithAPIKey("my-anthropic-api-key"),
   123  	)
   124  	_, err := client.Beta.Deployments.Update(
   125  		context.TODO(),
   126  		"depl_011CZkZcDH3vPqd7xnEfwTai",
   127  		anthropic.BetaDeploymentUpdateParams{
   128  			Agent: anthropic.BetaDeploymentUpdateParamsAgentUnion{
   129  				OfString: anthropic.String("string"),
   130  			},
   131  			Budget: anthropic.BetaManagedAgentsBudgetLimitParam{
   132  				MaxListCost: anthropic.BetaMonetaryAmountParam{
   133  					Amount:   "2500",
   134  					Currency: anthropic.BetaCurrencyUSD,
   135  				},
   136  				Type: anthropic.BetaManagedAgentsBudgetLimitTypeLimit,
   137  			},
   138  			Description:   anthropic.String("description"),
   139  			EnvironmentID: anthropic.String("environment_id"),
   140  			InitialEvents: []anthropic.BetaManagedAgentsDeploymentInitialEventParamsUnion{{
   141  				OfUserMessage: &anthropic.BetaManagedAgentsUserMessageEventParams{
   142  					Content: []anthropic.BetaManagedAgentsUserMessageEventParamsContentUnion{{
   143  						OfText: &anthropic.BetaManagedAgentsTextBlockParam{
   144  							Text: "Where is my order #1234?",
   145  							Type: anthropic.BetaManagedAgentsTextBlockTypeText,
   146  						},
   147  					}},
   148  					Type: anthropic.BetaManagedAgentsUserMessageEventParamsTypeUserMessage,
   149  				},
   150  			}},
   151  			Metadata: map[string]string{
   152  				"foo": "string",
   153  			},
   154  			Name: anthropic.String("name"),
   155  			Resources: []anthropic.BetaDeploymentUpdateParamsResourceUnion{{
   156  				OfFile: &anthropic.BetaManagedAgentsFileResourceParams{
   157  					FileID:    "file_011CNha8iCJcU1wXNR6q4V8w",
   158  					Type:      anthropic.BetaManagedAgentsFileResourceParamsTypeFile,
   159  					MountPath: anthropic.String("/uploads/receipt.pdf"),
   160  				},
   161  			}},
   162  			Schedule: anthropic.BetaManagedAgentsScheduleParams{
   163  				Expression: "0 9 * * 1-5",
   164  				Timezone:   "America/Los_Angeles",
   165  				Type:       anthropic.BetaManagedAgentsScheduleParamsTypeCron,
   166  			},
   167  			VaultIDs:    []string{"string"},
   168  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   169  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   170  		},
   171  	)
   172  	if err != nil {
   173  		var apierr *anthropic.Error
   174  		if errors.As(err, &apierr) {
   175  			t.Log(string(apierr.DumpRequest(true)))
   176  		}
   177  		t.Fatalf("err should be nil: %s", err.Error())
   178  	}
   179  }
   180  
   181  func TestBetaDeploymentListWithOptionalParams(t *testing.T) {
   182  	t.Skip("buildURL drops path-level query params (SDK-4349)")
   183  	baseURL := "http://localhost:4010"
   184  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   185  		baseURL = envURL
   186  	}
   187  	if !testutil.CheckTestServer(t, baseURL) {
   188  		return
   189  	}
   190  	client := anthropic.NewClient(
   191  		option.WithBaseURL(baseURL),
   192  		option.WithAPIKey("my-anthropic-api-key"),
   193  	)
   194  	_, err := client.Beta.Deployments.List(context.TODO(), anthropic.BetaDeploymentListParams{
   195  		AgentID:         anthropic.String("agent_id"),
   196  		CreatedAtGte:    anthropic.Time(time.Now()),
   197  		CreatedAtLte:    anthropic.Time(time.Now()),
   198  		IncludeArchived: anthropic.Bool(true),
   199  		Limit:           anthropic.Int(0),
   200  		Page:            anthropic.String("page"),
   201  		Status:          anthropic.BetaManagedAgentsDeploymentStatusActive,
   202  		Betas:           []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   203  		WorkspaceID:     anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   204  	})
   205  	if err != nil {
   206  		var apierr *anthropic.Error
   207  		if errors.As(err, &apierr) {
   208  			t.Log(string(apierr.DumpRequest(true)))
   209  		}
   210  		t.Fatalf("err should be nil: %s", err.Error())
   211  	}
   212  }
   213  
   214  func TestBetaDeploymentArchiveWithOptionalParams(t *testing.T) {
   215  	baseURL := "http://localhost:4010"
   216  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   217  		baseURL = envURL
   218  	}
   219  	if !testutil.CheckTestServer(t, baseURL) {
   220  		return
   221  	}
   222  	client := anthropic.NewClient(
   223  		option.WithBaseURL(baseURL),
   224  		option.WithAPIKey("my-anthropic-api-key"),
   225  	)
   226  	_, err := client.Beta.Deployments.Archive(
   227  		context.TODO(),
   228  		"depl_011CZkZcDH3vPqd7xnEfwTai",
   229  		anthropic.BetaDeploymentArchiveParams{
   230  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   231  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   232  		},
   233  	)
   234  	if err != nil {
   235  		var apierr *anthropic.Error
   236  		if errors.As(err, &apierr) {
   237  			t.Log(string(apierr.DumpRequest(true)))
   238  		}
   239  		t.Fatalf("err should be nil: %s", err.Error())
   240  	}
   241  }
   242  
   243  func TestBetaDeploymentPauseWithOptionalParams(t *testing.T) {
   244  	baseURL := "http://localhost:4010"
   245  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   246  		baseURL = envURL
   247  	}
   248  	if !testutil.CheckTestServer(t, baseURL) {
   249  		return
   250  	}
   251  	client := anthropic.NewClient(
   252  		option.WithBaseURL(baseURL),
   253  		option.WithAPIKey("my-anthropic-api-key"),
   254  	)
   255  	_, err := client.Beta.Deployments.Pause(
   256  		context.TODO(),
   257  		"depl_011CZkZcDH3vPqd7xnEfwTai",
   258  		anthropic.BetaDeploymentPauseParams{
   259  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   260  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   261  		},
   262  	)
   263  	if err != nil {
   264  		var apierr *anthropic.Error
   265  		if errors.As(err, &apierr) {
   266  			t.Log(string(apierr.DumpRequest(true)))
   267  		}
   268  		t.Fatalf("err should be nil: %s", err.Error())
   269  	}
   270  }
   271  
   272  func TestBetaDeploymentRunWithOptionalParams(t *testing.T) {
   273  	baseURL := "http://localhost:4010"
   274  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   275  		baseURL = envURL
   276  	}
   277  	if !testutil.CheckTestServer(t, baseURL) {
   278  		return
   279  	}
   280  	client := anthropic.NewClient(
   281  		option.WithBaseURL(baseURL),
   282  		option.WithAPIKey("my-anthropic-api-key"),
   283  	)
   284  	_, err := client.Beta.Deployments.Run(
   285  		context.TODO(),
   286  		"depl_011CZkZcDH3vPqd7xnEfwTai",
   287  		anthropic.BetaDeploymentRunParams{
   288  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   289  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   290  		},
   291  	)
   292  	if err != nil {
   293  		var apierr *anthropic.Error
   294  		if errors.As(err, &apierr) {
   295  			t.Log(string(apierr.DumpRequest(true)))
   296  		}
   297  		t.Fatalf("err should be nil: %s", err.Error())
   298  	}
   299  }
   300  
   301  func TestBetaDeploymentUnpauseWithOptionalParams(t *testing.T) {
   302  	baseURL := "http://localhost:4010"
   303  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   304  		baseURL = envURL
   305  	}
   306  	if !testutil.CheckTestServer(t, baseURL) {
   307  		return
   308  	}
   309  	client := anthropic.NewClient(
   310  		option.WithBaseURL(baseURL),
   311  		option.WithAPIKey("my-anthropic-api-key"),
   312  	)
   313  	_, err := client.Beta.Deployments.Unpause(
   314  		context.TODO(),
   315  		"depl_011CZkZcDH3vPqd7xnEfwTai",
   316  		anthropic.BetaDeploymentUnpauseParams{
   317  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   318  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   319  		},
   320  	)
   321  	if err != nil {
   322  		var apierr *anthropic.Error
   323  		if errors.As(err, &apierr) {
   324  			t.Log(string(apierr.DumpRequest(true)))
   325  		}
   326  		t.Fatalf("err should be nil: %s", err.Error())
   327  	}
   328  }