Anthropic-SDK-Go
Golang SDK for AnthRopic Claude AI
Features
- Contextual sequential memory
- Prompt automatically handles / Contextual automated processing
- Concise and easy-to-use API
- Fast data processing
Claude Docs: https://console.anthropic.com/docs
Start
Usage:
$ go get github.com/3JoB/anthropic-sdk-go/v2@v2.1.0
Example usage:
package main
import (
"fmt"
"github.com/3JoB/anthropic-sdk-go/v2"
"github.com/3JoB/anthropic-sdk-go/v2/data"
"github.com/3JoB/anthropic-sdk-go/v2/resp"
)
func main() {
c, err := anthropic.New(&anthropic.Client{Key: "your keys", DefaultModel: data.ModelFullInstant})
if err != nil {
panic(err)
}
d, err := c.Send(&anthropic.Opts{
Message: data.MessageModule{
Human: "Do you know Golang, please answer me in the shortest possible way.",
},
Sender: &resp.Sender{MaxToken: 1200},
})
if err != nil {
panic(err)
}
fmt.Println(d.Response.String())
}
Return:
{"detail":null,"completion":"Hello world! \nfmt.Println(\"Hello world!\")\n\nDone.","stop_reason":"stop_sequence","stop":"\n\nHuman:","log_id":"nop","exception":"","model":"claude-instant-v1.2","truncated":false}
Context Example:
package main
import (
"fmt"
"github.com/3JoB/anthropic-sdk-go/v2"
"github.com/3JoB/anthropic-sdk-go/v2/resp"
"github.com/3JoB/anthropic-sdk-go/v2/data"
)
func main() {
c, err := anthropic.New(&anthropic.Client{Key: "your keys", DefaultModel: data.ModelFullInstant})
if err != nil {
panic(err)
}
d, err := c.Send(&anthropic.Opts{
Message: data.MessageModule{
Human: "Do you know Golang, please answer me in the shortest possible way.",
},
Sender: &resp.Sender{MaxToken: 1200},
})
if err != nil {
panic(err)
}
fmt.Println(d.Response.String())
ds, err := c.Send(&anthropic.Opts{
Message: data.MessageModule{
Human: "What is its current version number?",
},
SessionID: d.ID,
Sender: &resp.Sender{MaxToken: 1200},
})
if err != nil {
panic(err)
}
fmt.Println(ds.Response.String())
}
Return:
{"detail":null,"completion":"Hello world! \nfmt.Println(\"Hello world!\")\n\nDone.","stop_reason":"stop_sequence","stop":"\n\nHuman:","log_id":"nop","exception":"","model":"claude-instant-v1","truncated":false}
{"detail":null,"completion":"1.14.4 ","stop_reason":"stop_sequence","stop":"\n\nHuman:","log_id":"nop","exception":"","model":"claude-instant-v1.2","truncated":false}
Delete the session in an ID
c, err := anthropic.New(&anthropic.Client{Key: "your keys", DefaultModel: anthropic.Model.Full.Instant1})
if err != nil {
panic(err)
}
d, err := c.Send(&anthropic.Opts{
Message: data.MessageModule{
Human: "Do you know Golang, please answer me in the shortest possible way.",
},
Sender: &resp.Sender{MaxToken: 1200},
})
if err != nil {
panic(err)
}
c.CloseSession(d)
Contribute
Move => CONTRIBUTING
Organize EMAIL: admin#zxda.top
[# => @]
License
This software is distributed under MIT license.