github.com/anthropics/anthropic-sdk-go@v1.70.1/betadream_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 TestBetaDreamNewWithOptionalParams(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.Dreams.New(context.TODO(), anthropic.BetaDreamNewParams{
    30  		Inputs: []anthropic.BetaDreamInputUnionParam{{
    31  			OfMemoryStore: &anthropic.BetaDreamMemoryStoreInputParam{
    32  				MemoryStoreID: "x",
    33  				Type:          anthropic.BetaDreamMemoryStoreInputTypeMemoryStore,
    34  			},
    35  		}},
    36  		Model: anthropic.BetaDreamNewParamsModelUnion{
    37  			OfString: anthropic.String("string"),
    38  		},
    39  		Instructions: anthropic.String("x"),
    40  		OutputBehavior: anthropic.BetaOutputBehaviorUnionParam{
    41  			OfCreateNew: &anthropic.BetaOutputBehaviorCreateNewParam{
    42  				Type: anthropic.BetaOutputBehaviorCreateNewTypeCreateNew,
    43  			},
    44  		},
    45  		Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    46  		WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    47  	})
    48  	if err != nil {
    49  		var apierr *anthropic.Error
    50  		if errors.As(err, &apierr) {
    51  			t.Log(string(apierr.DumpRequest(true)))
    52  		}
    53  		t.Fatalf("err should be nil: %s", err.Error())
    54  	}
    55  }
    56  
    57  func TestBetaDreamGetWithOptionalParams(t *testing.T) {
    58  	baseURL := "http://localhost:4010"
    59  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    60  		baseURL = envURL
    61  	}
    62  	if !testutil.CheckTestServer(t, baseURL) {
    63  		return
    64  	}
    65  	client := anthropic.NewClient(
    66  		option.WithBaseURL(baseURL),
    67  		option.WithAPIKey("my-anthropic-api-key"),
    68  	)
    69  	_, err := client.Beta.Dreams.Get(
    70  		context.TODO(),
    71  		"dream_id",
    72  		anthropic.BetaDreamGetParams{
    73  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    74  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    75  		},
    76  	)
    77  	if err != nil {
    78  		var apierr *anthropic.Error
    79  		if errors.As(err, &apierr) {
    80  			t.Log(string(apierr.DumpRequest(true)))
    81  		}
    82  		t.Fatalf("err should be nil: %s", err.Error())
    83  	}
    84  }
    85  
    86  func TestBetaDreamListWithOptionalParams(t *testing.T) {
    87  	baseURL := "http://localhost:4010"
    88  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    89  		baseURL = envURL
    90  	}
    91  	if !testutil.CheckTestServer(t, baseURL) {
    92  		return
    93  	}
    94  	client := anthropic.NewClient(
    95  		option.WithBaseURL(baseURL),
    96  		option.WithAPIKey("my-anthropic-api-key"),
    97  	)
    98  	_, err := client.Beta.Dreams.List(context.TODO(), anthropic.BetaDreamListParams{
    99  		CreatedAtGt:     anthropic.Time(time.Now()),
   100  		CreatedAtLt:     anthropic.Time(time.Now()),
   101  		IncludeArchived: anthropic.Bool(true),
   102  		Limit:           anthropic.Int(0),
   103  		Page:            anthropic.String("page"),
   104  		Statuses:        []anthropic.BetaDreamStatus{anthropic.BetaDreamStatusPending},
   105  		Betas:           []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   106  		WorkspaceID:     anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   107  	})
   108  	if err != nil {
   109  		var apierr *anthropic.Error
   110  		if errors.As(err, &apierr) {
   111  			t.Log(string(apierr.DumpRequest(true)))
   112  		}
   113  		t.Fatalf("err should be nil: %s", err.Error())
   114  	}
   115  }
   116  
   117  func TestBetaDreamArchiveWithOptionalParams(t *testing.T) {
   118  	baseURL := "http://localhost:4010"
   119  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   120  		baseURL = envURL
   121  	}
   122  	if !testutil.CheckTestServer(t, baseURL) {
   123  		return
   124  	}
   125  	client := anthropic.NewClient(
   126  		option.WithBaseURL(baseURL),
   127  		option.WithAPIKey("my-anthropic-api-key"),
   128  	)
   129  	_, err := client.Beta.Dreams.Archive(
   130  		context.TODO(),
   131  		"dream_id",
   132  		anthropic.BetaDreamArchiveParams{
   133  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   134  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   135  		},
   136  	)
   137  	if err != nil {
   138  		var apierr *anthropic.Error
   139  		if errors.As(err, &apierr) {
   140  			t.Log(string(apierr.DumpRequest(true)))
   141  		}
   142  		t.Fatalf("err should be nil: %s", err.Error())
   143  	}
   144  }
   145  
   146  func TestBetaDreamCancelWithOptionalParams(t *testing.T) {
   147  	baseURL := "http://localhost:4010"
   148  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   149  		baseURL = envURL
   150  	}
   151  	if !testutil.CheckTestServer(t, baseURL) {
   152  		return
   153  	}
   154  	client := anthropic.NewClient(
   155  		option.WithBaseURL(baseURL),
   156  		option.WithAPIKey("my-anthropic-api-key"),
   157  	)
   158  	_, err := client.Beta.Dreams.Cancel(
   159  		context.TODO(),
   160  		"dream_id",
   161  		anthropic.BetaDreamCancelParams{
   162  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   163  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   164  		},
   165  	)
   166  	if err != nil {
   167  		var apierr *anthropic.Error
   168  		if errors.As(err, &apierr) {
   169  			t.Log(string(apierr.DumpRequest(true)))
   170  		}
   171  		t.Fatalf("err should be nil: %s", err.Error())
   172  	}
   173  }