Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.1.0-alpha.1 #1

Merged
merged 13 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:

- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod

- name: Run lints
run: ./scripts/lint
Expand All @@ -32,6 +34,8 @@ jobs:

- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod

- name: Bootstrap
run: ./scripts/bootstrap
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.1-alpha.0"
".": "0.1.0-alpha.1"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 2
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-15089862b682046b13deff5bf5f09d786d9ec4aecc40b9f7ef40b84ef17d3348.yml
configured_endpoints: 3
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fb94a03f85580f7eacef034518becfb463502e6d74b0f7932f6153239de23a5b.yml
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

## 0.1.0-alpha.1 (2024-08-14)

Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/anthropics/anthropic-sdk-go/compare/v0.0.1-alpha.0...v0.1.0-alpha.1)

### Features

* **api:** add prompt caching beta ([#11](https://github.com/anthropics/anthropic-sdk-go/issues/11)) ([78f8c72](https://github.com/anthropics/anthropic-sdk-go/commit/78f8c7266dd98ef5f76d258f485ee284b7a0e590))
* publish ([5ff0ff8](https://github.com/anthropics/anthropic-sdk-go/commit/5ff0ff8cc5706c39a6dde75ae69d11c892ef8bb3))
* simplify system prompt ([#3](https://github.com/anthropics/anthropic-sdk-go/issues/3)) ([cd3fcef](https://github.com/anthropics/anthropic-sdk-go/commit/cd3fcefad20baef3c28375adf16ab266f97e7d94))
* simplify system prompt ([#4](https://github.com/anthropics/anthropic-sdk-go/issues/4)) ([85e1b34](https://github.com/anthropics/anthropic-sdk-go/commit/85e1b349619e7dd26c06ed0d9f566ddbbe80db2a))


### Bug Fixes

* deserialization of struct unions that implement json.Unmarshaler ([#6](https://github.com/anthropics/anthropic-sdk-go/issues/6)) ([a883a3a](https://github.com/anthropics/anthropic-sdk-go/commit/a883a3a8232dfca1ce8a139047a0356a3fd6015f))
* handle nil pagination responses when HTTP status is 200 ([#2](https://github.com/anthropics/anthropic-sdk-go/issues/2)) ([2bb2325](https://github.com/anthropics/anthropic-sdk-go/commit/2bb232557a9f75d58b7e7145c69771c927574dd3))
* message accumulation with union content block ([09457cb](https://github.com/anthropics/anthropic-sdk-go/commit/09457cb2ef8019cc23bcdefa0d3102e642d64b3d))


### Chores

* add back custom code ([106c404](https://github.com/anthropics/anthropic-sdk-go/commit/106c40466382daaa403e7f472647248e14d939d7))
* bump Go to v1.21 ([#7](https://github.com/anthropics/anthropic-sdk-go/issues/7)) ([928ed50](https://github.com/anthropics/anthropic-sdk-go/commit/928ed50c83154eb4f56575cf9f405a132000888e))
* **ci:** bump prism mock server version ([#5](https://github.com/anthropics/anthropic-sdk-go/issues/5)) ([0b326c6](https://github.com/anthropics/anthropic-sdk-go/commit/0b326c6b18effa222b8b03a17c1e562d0aedce1d))
* **examples:** minor formatting changes ([#8](https://github.com/anthropics/anthropic-sdk-go/issues/8)) ([4195c55](https://github.com/anthropics/anthropic-sdk-go/commit/4195c5541a1a517a3890bfe43eb84e3ddc496bfe))


### Documentation

* add examples to README ([df47298](https://github.com/anthropics/anthropic-sdk-go/commit/df4729897b782faeaa6a0795359ecf20b4a833ca))
237 changes: 217 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Or to pin the version:
<!-- x-release-please-start-version -->

```sh
go get -u 'github.com/anthropics/anthropic-sdk-go@v0.0.1-alpha.0'
go get -u 'github.com/anthropics/anthropic-sdk-go@v0.1.0-alpha.1'
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -51,11 +51,11 @@ func main() {
option.WithAPIKey("my-anthropic-api-key"), // defaults to os.LookupEnv("ANTHROPIC_API_KEY")
)
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
anthropic.NewUserMessage(anthropic.NewTextBlock("What is a quaternion?")),
}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
})
if err != nil {
panic(err.Error())
Expand All @@ -65,6 +65,205 @@ func main() {

```

<details>
<summary>Conversations</summary>

```go
messages := []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is my first name?")),
}

message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
Messages: anthropic.F(messages),
MaxTokens: anthropic.F(int64(1024)),
})

messages = append(messages, message.ToParam())
messages = append(messages, anthropic.NewUserMessage(
anthropic.NewTextBlock("My full name is John Doe"),
))

message, err = client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
Messages: anthropic.F(messages),
MaxTokens: anthropic.F(int64(1024)),
})
```

</details>

<details>
<summary>System prompts</summary>

```go
messages := []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is my first name?")),
}

message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
MaxTokens: anthropic.Int(1024),
System: anthropic.F([]anthropic.TextBlockParam{
anthropic.NewTextBlock("Be very serious at all times."),
}),
Messages: anthropic.F(messages),
})
```

</details>

<details>
<summary>Streaming</summary>

```go
stream := client.Messages.NewStreaming(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
MaxTokens: anthropic.Int(1024),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock(content)),
}),
})

message := anthropic.Message{}
for stream.Next() {
event := stream.Current()
message.Accumulate(event)

switch delta := event.Delta.(type) {
case anthropic.ContentBlockDeltaEventDelta:
if delta.Text != "" {
print(delta.Text)
}
}
}

if stream.Err() != nil {
panic(stream.Err())
}
```

</details>

<details>
<summary>Tool calling</summary>

```go
package main

import (
"context"
"encoding/json"
"fmt"

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

func main() {
client := anthropic.NewClient()

content := "Where is San Francisco?"

println("[user]: " + content)

messages := []anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock(content)),
}

tools := []anthropic.ToolParam{
{
Name: anthropic.F("get_coordinates"),
Description: anthropic.F("Accepts a place as an address, then returns the latitude and longitude coordinates."),
InputSchema: anthropic.F(GetCoordinatesInputSchema),
},
}

for {
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
MaxTokens: anthropic.Int(1024),
Messages: anthropic.F(messages),
Tools: anthropic.F(tools),
})

if err != nil {
panic(err)
}

print(color("[assistant]: "))
for _, block := range message.Content {
switch block := block.AsUnion().(type) {
case anthropic.TextBlock:
println(block.Text)
case anthropic.ToolUseBlock:
println(block.Name + ": " + string(block.Input))
}
}

messages = append(messages, message.ToParam())
toolResults := []anthropic.MessageParamContentUnion{}

for _, block := range message.Content {
if block.Type == anthropic.ContentBlockTypeToolUse {
print("[user (" + block.Name + ")]: ")

var response interface{}
switch block.Name {
case "get_coordinates":
input := GetCoordinatesInput{}
err := json.Unmarshal(block.Input, &input)
if err != nil {
panic(err)
}
response = GetCoordinates(input.Location)
}

b, err := json.Marshal(response)
if err != nil {
panic(err)
}

toolResults = append(toolResults, anthropic.NewToolResultBlock(block.ID, string(b), false))
}
}
if len(toolResults) == 0 {
break
}
messages = append(messages, anthropic.NewUserMessage(toolResults...))
}
}

type GetCoordinatesInput struct {
Location string `json:"location" jsonschema_description:"The location to look up."`
}

var GetCoordinatesInputSchema = GenerateSchema[GetCoordinatesInput]()

type GetCoordinateResponse struct {
Long float64 `json:"long"`
Lat float64 `json:"lat"`
}

func GetCoordinates(location string) GetCoordinateResponse {
return GetCoordinateResponse{
Long: -122.4194,
Lat: 37.7749,
}
}

func GenerateSchema[T any]() interface{} {
reflector := jsonschema.Reflector{
AllowAdditionalProperties: false,
DoNotReference: true,
}
var v T
return reflector.Reflect(v)
}
```

</details>

### Request fields

All request parameters are wrapped in a generic `Field` type,
Expand Down Expand Up @@ -180,9 +379,7 @@ 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?")),
}),

Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
})
if err != nil {
Expand Down Expand Up @@ -214,7 +411,7 @@ client.Messages.New(
anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
anthropic.NewUserMessage(anthropic.NewTextBlock("What is a quaternion?")),
}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
},
Expand Down Expand Up @@ -256,7 +453,7 @@ client.Messages.New(
anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("What is the weather in SF?")),
anthropic.NewUserMessage(anthropic.NewTextBlock("What is a quaternion?")),
}),
Model: anthropic.F(anthropic.ModelClaude_3_5_Sonnet_20240620),
},
Expand All @@ -276,17 +473,17 @@ To make requests to undocumented endpoints, you can use `client.Get`, `client.Po

```go
var (
// params can be an io.Reader, a []byte, an encoding/json serializable object,
// or a "…Params" struct defined in this library.
params map[string]interface{}
// params can be an io.Reader, a []byte, an encoding/json serializable object,
// or a "…Params" struct defined in this library.
params map[string]interface{}

// result can be an []byte, *http.Response, a encoding/json deserializable object,
// or a model defined in this library.
result *http.Response
// result can be an []byte, *http.Response, a encoding/json deserializable object,
// or a model defined in this library.
result *http.Response
)
err := client.Post(context.Background(), "/unspecified", params, &result)
if err != nil {
}
```

Expand All @@ -297,10 +494,10 @@ or the `option.WithJSONSet()` methods.

```go
params := FooNewParams{
ID: anthropic.F("id_xxxx"),
Data: anthropic.F(FooNewParamsData{
FirstName: anthropic.F("John"),
}),
ID: anthropic.F("id_xxxx"),
Data: anthropic.F(FooNewParamsData{
FirstName: anthropic.F("John"),
}),
}
client.Foo.New(context.Background(), params, option.WithJSONSet("data.last_name", "Doe"))
```
Expand Down Expand Up @@ -331,7 +528,7 @@ func Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response,
end := time.Now()
LogRes(res, err, start - end)

return res, err
return res, err
}

client := anthropic.NewClient(
Expand Down
27 changes: 27 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,30 @@ Response Types:
Methods:

- <code title="post /v1/messages">client.Messages.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#MessageService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#MessageNewParams">MessageNewParams</a>) (<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#Message">Message</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# Beta

## PromptCaching

### Messages

Params Types:

- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaCacheControlEphemeralParam">PromptCachingBetaCacheControlEphemeralParam</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaImageBlockParam">PromptCachingBetaImageBlockParam</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaMessageParam">PromptCachingBetaMessageParam</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaTextBlockParam">PromptCachingBetaTextBlockParam</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaToolParam">PromptCachingBetaToolParam</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaToolResultBlockParam">PromptCachingBetaToolResultBlockParam</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaToolUseBlockParam">PromptCachingBetaToolUseBlockParam</a>

Response Types:

- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaMessage">PromptCachingBetaMessage</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaUsage">PromptCachingBetaUsage</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#RawPromptCachingBetaMessageStartEvent">RawPromptCachingBetaMessageStartEvent</a>
- <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#RawPromptCachingBetaMessageStreamEvent">RawPromptCachingBetaMessageStreamEvent</a>

Methods:

- <code title="post /v1/messages?beta=prompt_caching">client.Beta.PromptCaching.Messages.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#BetaPromptCachingMessageService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#BetaPromptCachingMessageNewParams">BetaPromptCachingMessageNewParams</a>) (<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go">anthropic</a>.<a href="https://pkg.go.dev/github.com/anthropics/anthropic-sdk-go#PromptCachingBetaMessage">PromptCachingBetaMessage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
Loading
Loading