github.com/anthropics/anthropic-sdk-go@v1.70.1/messagebatch_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 TestMessageBatchNewWithOptionalParams(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.Messages.Batches.New(context.TODO(), anthropic.MessageBatchNewParams{ 29 Requests: []anthropic.MessageBatchNewParamsRequest{{ 30 CustomID: "my-custom-id-1", 31 Params: anthropic.MessageBatchNewParamsRequestParams{ 32 MaxTokens: 1024, 33 Messages: []anthropic.MessageParam{{ 34 Content: []anthropic.ContentBlockParamUnion{{ 35 OfText: &anthropic.TextBlockParam{ 36 Text: "x", 37 CacheControl: anthropic.CacheControlEphemeralParam{ 38 TTL: anthropic.CacheControlEphemeralTTLTTL5m, 39 }, 40 Citations: []anthropic.TextCitationParamUnion{{ 41 OfCharLocation: &anthropic.CitationCharLocationParam{ 42 CitedText: "The grass is green. The sky is blue.", 43 DocumentIndex: 0, 44 DocumentTitle: anthropic.String("x"), 45 EndCharIndex: 0, 46 StartCharIndex: 0, 47 }, 48 }}, 49 }, 50 }}, 51 Role: anthropic.MessageParamRoleUser, 52 }}, 53 Model: anthropic.ModelClaudeOpus5, 54 CacheControl: anthropic.CacheControlEphemeralParam{ 55 TTL: anthropic.CacheControlEphemeralTTLTTL5m, 56 }, 57 Container: anthropic.MessageCreateParamsContainerUnion{ 58 OfContainers: &anthropic.ContainerParams{ 59 ID: anthropic.String("id"), 60 Skills: []anthropic.SkillParams{{ 61 SkillID: "pdf", 62 Type: anthropic.SkillParamsTypeAnthropic, 63 Version: anthropic.String("latest"), 64 }}, 65 }, 66 }, 67 InferenceGeo: anthropic.String("inference_geo"), 68 Metadata: anthropic.MetadataParam{ 69 UserID: anthropic.String("13803d75-b4b5-4c3e-b2a2-6f21399b021b"), 70 }, 71 OutputConfig: anthropic.OutputConfigParam{ 72 Effort: anthropic.OutputConfigEffortLow, 73 Format: anthropic.JSONOutputFormatParam{ 74 Schema: map[string]any{ 75 "foo": "bar", 76 }, 77 }, 78 }, 79 ServiceTier: "auto", 80 StopSequences: []string{"string"}, 81 Stream: anthropic.Bool(false), 82 System: []anthropic.TextBlockParam{{ 83 Text: "Today's date is 2024-06-01.", 84 CacheControl: anthropic.CacheControlEphemeralParam{ 85 TTL: anthropic.CacheControlEphemeralTTLTTL5m, 86 }, 87 Citations: []anthropic.TextCitationParamUnion{{ 88 OfCharLocation: &anthropic.CitationCharLocationParam{ 89 CitedText: "The grass is green. The sky is blue.", 90 DocumentIndex: 0, 91 DocumentTitle: anthropic.String("x"), 92 EndCharIndex: 0, 93 StartCharIndex: 0, 94 }, 95 }}, 96 }}, 97 Temperature: anthropic.Float(1), 98 Thinking: anthropic.ThinkingConfigParamUnion{ 99 OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{ 100 Display: anthropic.ThinkingConfigAdaptiveDisplaySummarized, 101 }, 102 }, 103 ToolChoice: anthropic.ToolChoiceUnionParam{ 104 OfAuto: &anthropic.ToolChoiceAutoParam{ 105 DisableParallelToolUse: anthropic.Bool(true), 106 }, 107 }, 108 Tools: []anthropic.ToolUnionParam{{ 109 OfTool: &anthropic.ToolParam{ 110 InputSchema: anthropic.ToolInputSchemaParam{ 111 Properties: map[string]any{ 112 "location": "bar", 113 "unit": "bar", 114 }, 115 Required: []string{"location"}, 116 }, 117 Name: "name", 118 AllowedCallers: []string{"direct"}, 119 CacheControl: anthropic.CacheControlEphemeralParam{ 120 TTL: anthropic.CacheControlEphemeralTTLTTL5m, 121 }, 122 DeferLoading: anthropic.Bool(true), 123 Description: anthropic.String("Get the current weather in a given location"), 124 EagerInputStreaming: anthropic.Bool(true), 125 InputExamples: []map[string]any{{ 126 "foo": "bar", 127 }}, 128 Strict: anthropic.Bool(true), 129 Type: anthropic.ToolTypeCustom, 130 }, 131 }}, 132 TopK: anthropic.Int(5), 133 TopP: anthropic.Float(0.7), 134 }, 135 }}, 136 UserProfileID: anthropic.String("anthropic-user-profile-id"), 137 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 138 }) 139 if err != nil { 140 var apierr *anthropic.Error 141 if errors.As(err, &apierr) { 142 t.Log(string(apierr.DumpRequest(true))) 143 } 144 t.Fatalf("err should be nil: %s", err.Error()) 145 } 146 } 147 148 func TestMessageBatchGetWithOptionalParams(t *testing.T) { 149 baseURL := "http://localhost:4010" 150 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 151 baseURL = envURL 152 } 153 if !testutil.CheckTestServer(t, baseURL) { 154 return 155 } 156 client := anthropic.NewClient( 157 option.WithBaseURL(baseURL), 158 option.WithAPIKey("my-anthropic-api-key"), 159 ) 160 _, err := client.Messages.Batches.Get( 161 context.TODO(), 162 "message_batch_id", 163 anthropic.MessageBatchGetParams{ 164 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 165 }, 166 ) 167 if err != nil { 168 var apierr *anthropic.Error 169 if errors.As(err, &apierr) { 170 t.Log(string(apierr.DumpRequest(true))) 171 } 172 t.Fatalf("err should be nil: %s", err.Error()) 173 } 174 } 175 176 func TestMessageBatchListWithOptionalParams(t *testing.T) { 177 baseURL := "http://localhost:4010" 178 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 179 baseURL = envURL 180 } 181 if !testutil.CheckTestServer(t, baseURL) { 182 return 183 } 184 client := anthropic.NewClient( 185 option.WithBaseURL(baseURL), 186 option.WithAPIKey("my-anthropic-api-key"), 187 ) 188 _, err := client.Messages.Batches.List(context.TODO(), anthropic.MessageBatchListParams{ 189 AfterID: anthropic.String("after_id"), 190 BeforeID: anthropic.String("before_id"), 191 Limit: anthropic.Int(1), 192 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 193 }) 194 if err != nil { 195 var apierr *anthropic.Error 196 if errors.As(err, &apierr) { 197 t.Log(string(apierr.DumpRequest(true))) 198 } 199 t.Fatalf("err should be nil: %s", err.Error()) 200 } 201 } 202 203 func TestMessageBatchDeleteWithOptionalParams(t *testing.T) { 204 baseURL := "http://localhost:4010" 205 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 206 baseURL = envURL 207 } 208 if !testutil.CheckTestServer(t, baseURL) { 209 return 210 } 211 client := anthropic.NewClient( 212 option.WithBaseURL(baseURL), 213 option.WithAPIKey("my-anthropic-api-key"), 214 ) 215 _, err := client.Messages.Batches.Delete( 216 context.TODO(), 217 "message_batch_id", 218 anthropic.MessageBatchDeleteParams{ 219 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 220 }, 221 ) 222 if err != nil { 223 var apierr *anthropic.Error 224 if errors.As(err, &apierr) { 225 t.Log(string(apierr.DumpRequest(true))) 226 } 227 t.Fatalf("err should be nil: %s", err.Error()) 228 } 229 } 230 231 func TestMessageBatchCancelWithOptionalParams(t *testing.T) { 232 baseURL := "http://localhost:4010" 233 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 234 baseURL = envURL 235 } 236 if !testutil.CheckTestServer(t, baseURL) { 237 return 238 } 239 client := anthropic.NewClient( 240 option.WithBaseURL(baseURL), 241 option.WithAPIKey("my-anthropic-api-key"), 242 ) 243 _, err := client.Messages.Batches.Cancel( 244 context.TODO(), 245 "message_batch_id", 246 anthropic.MessageBatchCancelParams{ 247 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 248 }, 249 ) 250 if err != nil { 251 var apierr *anthropic.Error 252 if errors.As(err, &apierr) { 253 t.Log(string(apierr.DumpRequest(true))) 254 } 255 t.Fatalf("err should be nil: %s", err.Error()) 256 } 257 }