-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add the initial Anthropic SDK implementation
- Loading branch information
Showing
10 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: PR | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- .editorconfig | ||
- .gitignore | ||
- LICENSE.md | ||
- README.md | ||
|
||
jobs: | ||
verify: | ||
name: Verify | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
- name: Check formatting | ||
run: test -z "$(go fmt ./...)" | ||
|
||
build: | ||
name: Build | ||
needs: [ verify ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Package anthropic provides a client library for interacting with the | ||
// Anthropic safety-first language model REST APIs. | ||
package anthropic | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// Client manages communication with the Anthropic REST API. | ||
type Client struct { | ||
client *http.Client | ||
} | ||
|
||
// NewClient returns a new Anthropic REST API client. | ||
func NewClient(client *http.Client) *Client { | ||
if client == nil { | ||
client = &http.Client{} | ||
} | ||
|
||
return &Client{ | ||
client: client, | ||
} | ||
} | ||
|
||
// NewRequest creates an API request. | ||
func (c *Client) NewRequest(url string) (*http.Request, error) { | ||
return http.NewRequest(http.MethodGet, url, nil) | ||
} | ||
|
||
// Do sends an API request and returns the API response. | ||
func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error) { | ||
return c.client.Do(req.WithContext(ctx)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package anthropic | ||
|
||
import "testing" | ||
|
||
func TestNewClient(t *testing.T) { | ||
c1 := NewClient(nil) | ||
c2 := NewClient(nil) | ||
if c1.client == c2.client { | ||
t.Errorf("NewClient() = %v, want %v", c1.client, c2.client) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package anthropic | ||
|
||
import "net/http" | ||
|
||
type MessagesService struct{} | ||
|
||
// Message defines ... | ||
type Message struct { | ||
Content string | ||
Role string | ||
} | ||
|
||
// CreateMessageOptions defines ... | ||
type CreateMessageOptions struct { | ||
// MaxTokens defines the maximum number of tokens to generate before | ||
// stopping. Token generation may stop before reaching this limit, this only | ||
// specifies the absolute maximum number of tokens to generate. Different | ||
// models have different maximum token limits. | ||
MaxTokens int | ||
// Messages ... | ||
Messages []Message | ||
// Model defines the language model that will be used to complete the | ||
// prompt. See model.go for a list of available models. | ||
Model LanguageModel | ||
// StopSequences defines custom text sequences that will cause the model to | ||
// stop generating. | ||
StopSequences []string | ||
// System provides a means of specifying context and instructions to the | ||
// model, such as specifying a particular goal or role. | ||
System string | ||
// Temperature defines the amount of randomness injected into the response. | ||
// Note that even with a temperature of 0.0, results will not be fully | ||
// deterministic. | ||
Temperature *float64 | ||
// TopK is used to remove long tail low probability responses. | ||
TopK *int | ||
// TopP defines the cumulative probability of the highest probability. | ||
TopP *float64 | ||
} | ||
|
||
// Create creates a new message using the provided options. | ||
func (c *MessagesService) Create(options *CreateMessageOptions) (*Message, *http.Response, error) { | ||
return nil, nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package anthropic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package anthropic | ||
|
||
// LanguageModel represents a language model that can be used to complete | ||
// a prompt. | ||
// https://docs.anthropic.com/claude/docs/models-overview | ||
type LanguageModel string | ||
|
||
const ( | ||
Claude3Opus20240229 LanguageModel = "claude-3-opus-20240229" | ||
Claude3Sonnet20240229 LanguageModel = "claude-3-sonnet-20240229" | ||
Claude3Haiku20240229 LanguageModel = "claude-3-haiku-20240307" | ||
Claude21 LanguageModel = "claude-2.1" | ||
Claude20 LanguageModel = "claude-2.0" | ||
ClaudeInstant12 LanguageModel = "claude-instant-1.2" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package anthropic | ||
|
||
// Transport provides ... | ||
type Transport struct { | ||
APIKey string | ||
} | ||
|
||
func (t *Transport) Client() *Client { | ||
return NewClient(nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package anthropic |