github.com/anthropics/anthropic-sdk-go@v1.70.1/betamemorystorememory_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 11 "github.com/anthropics/anthropic-sdk-go" 12 "github.com/anthropics/anthropic-sdk-go/internal/testutil" 13 "github.com/anthropics/anthropic-sdk-go/option" 14 ) 15 16 func TestBetaMemoryStoreMemoryNewWithOptionalParams(t *testing.T) { 17 baseURL := "http://localhost:4010" 18 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 19 baseURL = envURL 20 } 21 if !testutil.CheckTestServer(t, baseURL) { 22 return 23 } 24 client := anthropic.NewClient( 25 option.WithBaseURL(baseURL), 26 option.WithAPIKey("my-anthropic-api-key"), 27 ) 28 _, err := client.Beta.MemoryStores.Memories.New( 29 context.TODO(), 30 "memory_store_id", 31 anthropic.BetaMemoryStoreMemoryNewParams{ 32 Content: anthropic.String("content"), 33 Path: "xx", 34 View: anthropic.BetaManagedAgentsMemoryViewBasic, 35 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 36 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 37 }, 38 ) 39 if err != nil { 40 var apierr *anthropic.Error 41 if errors.As(err, &apierr) { 42 t.Log(string(apierr.DumpRequest(true))) 43 } 44 t.Fatalf("err should be nil: %s", err.Error()) 45 } 46 } 47 48 func TestBetaMemoryStoreMemoryGetWithOptionalParams(t *testing.T) { 49 baseURL := "http://localhost:4010" 50 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 51 baseURL = envURL 52 } 53 if !testutil.CheckTestServer(t, baseURL) { 54 return 55 } 56 client := anthropic.NewClient( 57 option.WithBaseURL(baseURL), 58 option.WithAPIKey("my-anthropic-api-key"), 59 ) 60 _, err := client.Beta.MemoryStores.Memories.Get( 61 context.TODO(), 62 "memory_id", 63 anthropic.BetaMemoryStoreMemoryGetParams{ 64 MemoryStoreID: "memory_store_id", 65 View: anthropic.BetaManagedAgentsMemoryViewBasic, 66 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 67 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 68 }, 69 ) 70 if err != nil { 71 var apierr *anthropic.Error 72 if errors.As(err, &apierr) { 73 t.Log(string(apierr.DumpRequest(true))) 74 } 75 t.Fatalf("err should be nil: %s", err.Error()) 76 } 77 } 78 79 func TestBetaMemoryStoreMemoryUpdateWithOptionalParams(t *testing.T) { 80 baseURL := "http://localhost:4010" 81 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 82 baseURL = envURL 83 } 84 if !testutil.CheckTestServer(t, baseURL) { 85 return 86 } 87 client := anthropic.NewClient( 88 option.WithBaseURL(baseURL), 89 option.WithAPIKey("my-anthropic-api-key"), 90 ) 91 _, err := client.Beta.MemoryStores.Memories.Update( 92 context.TODO(), 93 "memory_id", 94 anthropic.BetaMemoryStoreMemoryUpdateParams{ 95 MemoryStoreID: "memory_store_id", 96 View: anthropic.BetaManagedAgentsMemoryViewBasic, 97 Content: anthropic.String("content"), 98 Path: anthropic.String("xx"), 99 Precondition: anthropic.BetaManagedAgentsPreconditionParam{ 100 Type: anthropic.BetaManagedAgentsPreconditionTypeContentSha256, 101 ContentSha256: anthropic.String("content_sha256"), 102 }, 103 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 104 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 105 }, 106 ) 107 if err != nil { 108 var apierr *anthropic.Error 109 if errors.As(err, &apierr) { 110 t.Log(string(apierr.DumpRequest(true))) 111 } 112 t.Fatalf("err should be nil: %s", err.Error()) 113 } 114 } 115 116 func TestBetaMemoryStoreMemoryListWithOptionalParams(t *testing.T) { 117 t.Skip("buildURL drops path-level query params (SDK-4349)") 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.MemoryStores.Memories.List( 130 context.TODO(), 131 "memory_store_id", 132 anthropic.BetaMemoryStoreMemoryListParams{ 133 Depth: anthropic.Int(0), 134 Limit: anthropic.Int(0), 135 Page: anthropic.String("page"), 136 PathPrefix: anthropic.String("path_prefix"), 137 View: anthropic.BetaManagedAgentsMemoryViewBasic, 138 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 139 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 140 }, 141 ) 142 if err != nil { 143 var apierr *anthropic.Error 144 if errors.As(err, &apierr) { 145 t.Log(string(apierr.DumpRequest(true))) 146 } 147 t.Fatalf("err should be nil: %s", err.Error()) 148 } 149 } 150 151 func TestBetaMemoryStoreMemoryDeleteWithOptionalParams(t *testing.T) { 152 baseURL := "http://localhost:4010" 153 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 154 baseURL = envURL 155 } 156 if !testutil.CheckTestServer(t, baseURL) { 157 return 158 } 159 client := anthropic.NewClient( 160 option.WithBaseURL(baseURL), 161 option.WithAPIKey("my-anthropic-api-key"), 162 ) 163 _, err := client.Beta.MemoryStores.Memories.Delete( 164 context.TODO(), 165 "memory_id", 166 anthropic.BetaMemoryStoreMemoryDeleteParams{ 167 MemoryStoreID: "memory_store_id", 168 ExpectedContentSha256: anthropic.String("expected_content_sha256"), 169 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 170 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 171 }, 172 ) 173 if err != nil { 174 var apierr *anthropic.Error 175 if errors.As(err, &apierr) { 176 t.Log(string(apierr.DumpRequest(true))) 177 } 178 t.Fatalf("err should be nil: %s", err.Error()) 179 } 180 }