Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Latest commit

 

History

History
166 lines (126 loc) · 4.53 KB

README.md

File metadata and controls

166 lines (126 loc) · 4.53 KB

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



Start

Usage:

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

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}

Delete the session in an ID

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

Contact

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


License

This software is distributed under MIT license.