-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Google VertexAI support. Support VertexAI framework. Support detection and error handling. * Improvements and cleanup as suggested by package owners: * Fix whitespace * Remove duplicate code * Move certain functions to be methods. * Better error message grammar. * Remove commented-out unneeded code. * Fix sample code. * Integration test for VertexAI * Refactor vertex changes to an interface. * Run golines. * Unit tests for Vertex functionality.
- Loading branch information
1 parent
04cc4c4
commit 63bad02
Showing
21 changed files
with
816 additions
and
18 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
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 ( | ||
"net/http" | ||
) | ||
|
||
// ClientAdapter is an interface that defines the methods that allow use of the anthropic API with different providers. | ||
type ClientAdapter interface { | ||
// Translate provider specific errors. Responds with an error and a boolean indicating if the error has been successfully parsed. | ||
TranslateError(resp *http.Response, body []byte) (error, bool) | ||
// Prepare the request for the provider and return the full URL | ||
PrepareRequest(c *Client, method, urlSuffix string, body any) (string, error) | ||
// Set the request headers for the provider | ||
SetRequestHeaders(c *Client, req *http.Request) error | ||
} |
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
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,36 @@ | ||
package anthropic | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
var _ ClientAdapter = (*DefaultAdapter)(nil) | ||
|
||
type DefaultAdapter struct { | ||
} | ||
|
||
func (v *DefaultAdapter) TranslateError(resp *http.Response, body []byte) (error, bool) { | ||
return nil, false | ||
} | ||
|
||
func (v *DefaultAdapter) fullURL(baseUrl string, suffix string) string { | ||
// replace the first slash with a colon | ||
return fmt.Sprintf("%s%s", baseUrl, suffix) | ||
} | ||
|
||
func (v *DefaultAdapter) PrepareRequest( | ||
c *Client, | ||
method string, | ||
urlSuffix string, | ||
body any, | ||
) (string, error) { | ||
return v.fullURL(c.config.BaseURL, urlSuffix), nil | ||
} | ||
|
||
func (v *DefaultAdapter) SetRequestHeaders(c *Client, req *http.Request) error { | ||
req.Header.Set("X-Api-Key", c.config.GetApiKey()) | ||
req.Header.Set("Anthropic-Version", string(c.config.APIVersion)) | ||
|
||
return 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module github.com/liushuangls/go-anthropic/v2 | ||
|
||
go 1.21 | ||
|
||
require golang.org/x/oauth2 v0.24.0 | ||
|
||
require cloud.google.com/go/compute/metadata v0.3.0 // indirect |
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,6 @@ | ||
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= | ||
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= | ||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= | ||
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= |
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
Oops, something went wrong.