Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/3job/anthropic-sdk-go

(Need to be maintained) Golang SDK for AnthRopic Claude AI. Provide complete encapsulated interfaces that are easy to quickly get started with.
https://github.com/3job/anthropic-sdk-go

ai anthropic claude claude-ai golang golang-library sdk sdk-go

Last synced: about 1 month ago
JSON representation

(Need to be maintained) Golang SDK for AnthRopic Claude AI. Provide complete encapsulated interfaces that are easy to quickly get started with.

Awesome Lists containing this project

README

        

Anthropic-SDK-Go


Go Reference
MIT
Go Version
GitHub release (latest by date)



GitHub Issues
GitHub Repo stars
GitHub repo size
GitHub commit activity


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](https://console.anthropic.com/docs)



## Start

Usage:
```sh
$ go get github.com/3JoB/anthropic-sdk-go/[email protected]
```



Example usage:

```go
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:
```json
{"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:
```go
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:
```json
{"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
```golang
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)
```


# Contribute
Move => [CONTRIBUTING](/CONTRIBUTING.md)

# Contact
Organize EMAIL: `admin#zxda.top` [# => @]


# License
This software is distributed under MIT license.