feat: add Anthropic API support with custom version header (#934)

* feat: add Anthropic API support with custom version header

* refactor: use switch statement for API type header handling

* refactor: add OpenAI & AzureAD types to be exhaustive

* Update client.go

need explicit fallthrough in empty case statements

* constant for APIVersion; addtl tests
This commit is contained in:
Dan Ackerson
2025-02-25 12:03:38 +01:00
committed by GitHub
parent 85f578b865
commit be2e2387d4
4 changed files with 89 additions and 6 deletions

View File

@@ -39,6 +39,21 @@ func TestClient(t *testing.T) {
}
}
func TestSetCommonHeadersAnthropic(t *testing.T) {
config := DefaultAnthropicConfig("mock-token", "")
client := NewClientWithConfig(config)
req, err := http.NewRequest("GET", "http://example.com", nil)
if err != nil {
t.Fatalf("Failed to create request: %v", err)
}
client.setCommonHeaders(req)
if got := req.Header.Get("anthropic-version"); got != AnthropicAPIVersion {
t.Errorf("Expected anthropic-version header to be %q, got %q", AnthropicAPIVersion, got)
}
}
func TestDecodeResponse(t *testing.T) {
stringInput := ""