Golang SDK for AnthRopic Claude AI
- 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
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.Config{Key: "your keys", DefaultModel: data.ModelFullInstant})
if err != nil {
panic(err)
}
d, err := c.Send(&anthropic.Sender{
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.Config{Key: "your keys", DefaultModel: data.ModelFullInstant})
if err != nil {
panic(err)
}
d, err := c.Send(&anthropic.Sender{
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.Sender{
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}
c, err := anthropic.New(&anthropic.Config{Key: "your keys", DefaultModel: data.Model_FullInstant_1_0})
if err != nil {
panic(err)
}
d, err := c.Send(&anthropic.Sender{
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)
Move => CONTRIBUTING
Organize EMAIL: admin#zxda.top
[# => @]
This software is distributed under MIT license.