Skip to content

Commit

Permalink
fix: handle nil pagination responses when HTTP status is 200 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 31, 2024
1 parent 757a326 commit ad38619
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 765 deletions.
84 changes: 16 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func main() {
)
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
}),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
Content: anthropic.F([]anthropic.MessageParamContentUnion{anthropic.TextBlockParam{Type: anthropic.F(anthropic.TextBlockParamTypeText), Text: anthropic.F("What is a quaternion?")}}),
}}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
})
if err != nil {
Expand Down Expand Up @@ -180,9 +181,10 @@ To handle errors, we recommend that you use the `errors.As` pattern:
```go
_, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
}),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
Content: anthropic.F([]anthropic.MessageParamContentUnion{anthropic.TextBlockParam{Type: anthropic.F(anthropic.TextBlockParamTypeText), Text: anthropic.F("What is a quaternion?")}}),
}}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
})
if err != nil {
Expand Down Expand Up @@ -213,9 +215,10 @@ client.Messages.New(
ctx,
anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
}),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
Content: anthropic.F([]anthropic.MessageParamContentUnion{anthropic.TextBlockParam{Type: anthropic.F(anthropic.TextBlockParamTypeText), Text: anthropic.F("What is a quaternion?")}}),
}}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
},
// This sets the per-retry timeout
Expand Down Expand Up @@ -255,9 +258,10 @@ client.Messages.New(
context.TODO(),
anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
}),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
Content: anthropic.F([]anthropic.MessageParamContentUnion{anthropic.TextBlockParam{Type: anthropic.F(anthropic.TextBlockParamTypeText), Text: anthropic.F("What is a quaternion?")}}),
}}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
},
option.WithMaxRetries(5),
Expand Down Expand Up @@ -350,62 +354,6 @@ You may also replace the default `http.Client` with
accepted (this overwrites any previous client) and receives requests after any
middleware has been applied.

## Amazon Bedrock

To use this library with [Amazon Bedrock](https://aws.amazon.com/bedrock/claude/),
use the bedrock request option `bedrock.WithLoadDefaultConfig(…)` which reads the
[default config](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).

Importing the `bedrock` library also globally registers a decoder for `application/vnd.amazon.eventstream` for
streaming.

```go
package main

import (
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/bedrock"
)

func main() {
client := anthropic.NewClient(
bedrock.WithLoadDefaultConfig(context.Background()),
)
}
```

If you already have an `aws.Config`, you can also use it directly with `bedrock.WithConfig(cfg)`.

Read more about Anthropic and Amazon Bedrock [here](https://docs.anthropic.com/en/api/claude-on-amazon-bedrock).

## Google Vertex AI

To use this library with [Google Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude),
use the request option `vertex.WithGoogleAuth(…)` which reads the
[Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials).

```go
package main

import (
"context"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/vertex"
)

func main() {
client := anthropic.NewClient(
vertex.WithGoogleAuth(context.Background(), "us-central1", "stainless-399616"),
)
}
```

If you already have `*google.Credentials`, you can also use it directly with
`vertex.WithCredentials(ctx, region, projectId, creds)`.

Read more about Anthropic and Google Vertex [here](https://docs.anthropic.com/en/api/claude-on-vertex-ai).

## Semantic versioning

This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
Expand Down
210 changes: 0 additions & 210 deletions bedrock/bedrock.go

This file was deleted.

2 changes: 1 addition & 1 deletion examples/tools-streaming-jsonschema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"

"github.com/invopop/jsonschema"
"github.com/anthropics/anthropic-sdk-go"
"github.com/invopop/jsonschema"
)

func main() {
Expand Down
43 changes: 1 addition & 42 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,9 @@ module github.com/anthropics/anthropic-sdk-go
go 1.19

require (
cloud.google.com/go/auth v0.7.2 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.3 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.27 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.27 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.22.4 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.189.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading

0 comments on commit ad38619

Please sign in to comment.