github.com/anthropics/anthropic-sdk-go@v1.70.1/betamemorystore_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 TestBetaMemoryStoreNewWithOptionalParams(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.MemoryStores.New(context.TODO(), anthropic.BetaMemoryStoreNewParams{
    30  		Name:        "x",
    31  		Description: anthropic.String("description"),
    32  		Metadata: map[string]string{
    33  			"foo": "string",
    34  		},
    35  		Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    36  		WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    37  	})
    38  	if err != nil {
    39  		var apierr *anthropic.Error
    40  		if errors.As(err, &apierr) {
    41  			t.Log(string(apierr.DumpRequest(true)))
    42  		}
    43  		t.Fatalf("err should be nil: %s", err.Error())
    44  	}
    45  }
    46  
    47  func TestBetaMemoryStoreGetWithOptionalParams(t *testing.T) {
    48  	baseURL := "http://localhost:4010"
    49  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    50  		baseURL = envURL
    51  	}
    52  	if !testutil.CheckTestServer(t, baseURL) {
    53  		return
    54  	}
    55  	client := anthropic.NewClient(
    56  		option.WithBaseURL(baseURL),
    57  		option.WithAPIKey("my-anthropic-api-key"),
    58  	)
    59  	_, err := client.Beta.MemoryStores.Get(
    60  		context.TODO(),
    61  		"memory_store_id",
    62  		anthropic.BetaMemoryStoreGetParams{
    63  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    64  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    65  		},
    66  	)
    67  	if err != nil {
    68  		var apierr *anthropic.Error
    69  		if errors.As(err, &apierr) {
    70  			t.Log(string(apierr.DumpRequest(true)))
    71  		}
    72  		t.Fatalf("err should be nil: %s", err.Error())
    73  	}
    74  }
    75  
    76  func TestBetaMemoryStoreUpdateWithOptionalParams(t *testing.T) {
    77  	baseURL := "http://localhost:4010"
    78  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    79  		baseURL = envURL
    80  	}
    81  	if !testutil.CheckTestServer(t, baseURL) {
    82  		return
    83  	}
    84  	client := anthropic.NewClient(
    85  		option.WithBaseURL(baseURL),
    86  		option.WithAPIKey("my-anthropic-api-key"),
    87  	)
    88  	_, err := client.Beta.MemoryStores.Update(
    89  		context.TODO(),
    90  		"memory_store_id",
    91  		anthropic.BetaMemoryStoreUpdateParams{
    92  			Description: anthropic.String("description"),
    93  			Metadata: map[string]string{
    94  				"foo": "string",
    95  			},
    96  			Name:        anthropic.String("x"),
    97  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    98  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    99  		},
   100  	)
   101  	if err != nil {
   102  		var apierr *anthropic.Error
   103  		if errors.As(err, &apierr) {
   104  			t.Log(string(apierr.DumpRequest(true)))
   105  		}
   106  		t.Fatalf("err should be nil: %s", err.Error())
   107  	}
   108  }
   109  
   110  func TestBetaMemoryStoreListWithOptionalParams(t *testing.T) {
   111  	t.Skip("buildURL drops path-level query params (SDK-4349)")
   112  	baseURL := "http://localhost:4010"
   113  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   114  		baseURL = envURL
   115  	}
   116  	if !testutil.CheckTestServer(t, baseURL) {
   117  		return
   118  	}
   119  	client := anthropic.NewClient(
   120  		option.WithBaseURL(baseURL),
   121  		option.WithAPIKey("my-anthropic-api-key"),
   122  	)
   123  	_, err := client.Beta.MemoryStores.List(context.TODO(), anthropic.BetaMemoryStoreListParams{
   124  		CreatedAtGte:    anthropic.Time(time.Now()),
   125  		CreatedAtLte:    anthropic.Time(time.Now()),
   126  		IncludeArchived: anthropic.Bool(true),
   127  		Limit:           anthropic.Int(0),
   128  		Page:            anthropic.String("page"),
   129  		Betas:           []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   130  		WorkspaceID:     anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   131  	})
   132  	if err != nil {
   133  		var apierr *anthropic.Error
   134  		if errors.As(err, &apierr) {
   135  			t.Log(string(apierr.DumpRequest(true)))
   136  		}
   137  		t.Fatalf("err should be nil: %s", err.Error())
   138  	}
   139  }
   140  
   141  func TestBetaMemoryStoreDeleteWithOptionalParams(t *testing.T) {
   142  	baseURL := "http://localhost:4010"
   143  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   144  		baseURL = envURL
   145  	}
   146  	if !testutil.CheckTestServer(t, baseURL) {
   147  		return
   148  	}
   149  	client := anthropic.NewClient(
   150  		option.WithBaseURL(baseURL),
   151  		option.WithAPIKey("my-anthropic-api-key"),
   152  	)
   153  	_, err := client.Beta.MemoryStores.Delete(
   154  		context.TODO(),
   155  		"memory_store_id",
   156  		anthropic.BetaMemoryStoreDeleteParams{
   157  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   158  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   159  		},
   160  	)
   161  	if err != nil {
   162  		var apierr *anthropic.Error
   163  		if errors.As(err, &apierr) {
   164  			t.Log(string(apierr.DumpRequest(true)))
   165  		}
   166  		t.Fatalf("err should be nil: %s", err.Error())
   167  	}
   168  }
   169  
   170  func TestBetaMemoryStoreArchiveWithOptionalParams(t *testing.T) {
   171  	baseURL := "http://localhost:4010"
   172  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   173  		baseURL = envURL
   174  	}
   175  	if !testutil.CheckTestServer(t, baseURL) {
   176  		return
   177  	}
   178  	client := anthropic.NewClient(
   179  		option.WithBaseURL(baseURL),
   180  		option.WithAPIKey("my-anthropic-api-key"),
   181  	)
   182  	_, err := client.Beta.MemoryStores.Archive(
   183  		context.TODO(),
   184  		"memory_store_id",
   185  		anthropic.BetaMemoryStoreArchiveParams{
   186  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   187  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   188  		},
   189  	)
   190  	if err != nil {
   191  		var apierr *anthropic.Error
   192  		if errors.As(err, &apierr) {
   193  			t.Log(string(apierr.DumpRequest(true)))
   194  		}
   195  		t.Fatalf("err should be nil: %s", err.Error())
   196  	}
   197  }