-
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.
chore: Improve documentation in source files
- Loading branch information
Showing
8 changed files
with
149 additions
and
51 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.editorconfig export-ignore | ||
.github/ export-ignore |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Anthropic SDK for Go | ||
|
||
> [!NOTE] | ||
> This is not an official SDK and I have no affiliation with [Anthropic]. | ||
Client library for interacting with the [Anthropic] safety-first language model | ||
REST APIs. | ||
|
||
|
@@ -29,7 +32,7 @@ func main() { | |
claude := anthropic.NewClient(transport.Client()) | ||
|
||
if resp, httpResp, err := claude.Messages.Create(ctx, &anthropic.CreateMessageInput{ | ||
MaxTokens: 100, | ||
MaxTokens: 1024, | ||
Messages: []anthropic.Message{ | ||
{Content: "Hello, Claude!", Role: "user"}, | ||
}, | ||
|
@@ -53,6 +56,8 @@ git clone [email protected]:unfunco/anthropic-sdk-go.git | |
cd anthropic-sdk-go | ||
``` | ||
|
||
## References | ||
|
||
## License | ||
|
||
© 2024 [Daniel Morris]\ | ||
|
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 |
---|---|---|
@@ -1,16 +1,31 @@ | ||
package anthropic | ||
|
||
import "testing" | ||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestNewClient(t *testing.T) { | ||
c1 := NewClient(nil) | ||
c2 := NewClient(nil) | ||
|
||
if c1.client == c2.client { | ||
if c1.httpClient == c2.httpClient { | ||
t.Error("NewClient returned equal http.Clients but they should differ") | ||
} | ||
} | ||
|
||
func TestClient_NewRequest(t *testing.T) { | ||
_ = NewClient(nil) | ||
c := NewClient(nil) | ||
req, err := c.NewRequest(http.MethodPost, "example", nil) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if req.Method != http.MethodPost { | ||
t.Errorf("req.Method = %q, want %q", req.Method, http.MethodPost) | ||
} | ||
|
||
if req.URL.String() != "https://api.anthropic.com/v1/example" { | ||
t.Errorf("req.URL = %q, want %q", req.URL.String(), "https://api.anthropic.com/v1/example") | ||
} | ||
} |
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
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 | ||
|
||
import "fmt" | ||
|
||
// Usage defines billing and rate-limit usage information. Billing and | ||
// rate-limiting are driven by token counts. | ||
type Usage struct { | ||
InputTokens int `json:"input_tokens"` | ||
OutputTokens int `json:"output_tokens"` | ||
} | ||
|
||
// String implements the fmt.Stringer interface for Usage. | ||
func (u *Usage) String() string { | ||
return fmt.Sprintf("Input: %d, Output: %d", u.InputTokens, u.OutputTokens) | ||
} |
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,39 @@ | ||
package anthropic | ||
|
||
import "testing" | ||
|
||
func TestUsage_String(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
usage *Usage | ||
want string | ||
}{ | ||
{ | ||
name: "empty", | ||
usage: &Usage{}, | ||
want: "Input: 0, Output: 0", | ||
}, | ||
{ | ||
name: "input", | ||
usage: &Usage{InputTokens: 1}, | ||
want: "Input: 1, Output: 0", | ||
}, | ||
{ | ||
name: "output", | ||
usage: &Usage{OutputTokens: 2}, | ||
want: "Input: 0, Output: 2", | ||
}, | ||
{ | ||
name: "both", | ||
usage: &Usage{InputTokens: 3, OutputTokens: 4}, | ||
want: "Input: 3, Output: 4", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.usage.String(); got != tt.want { | ||
t.Errorf("Usage.String() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |