-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BaseURL for Anthropic configuration. (#336)
This will allow Anthropic requests to be issued via a proxy.
- Loading branch information
Showing
3 changed files
with
68 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,57 @@ | ||
package anthropic | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/jlewi/foyle/app/pkg/config" | ||
"github.com/liushuangls/go-anthropic/v2" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func Test_AnthropicClient(t *testing.T) { | ||
if os.Getenv("GITHUB_ACTIONS") != "" { | ||
t.Skipf("TestAnthropicClient is a manual test that is skipped in CICD") | ||
} | ||
|
||
// N.B since this test isn't using a valid endpoint we don't expect it to succceed | ||
// But hopefully the error message will let us confirm that the baseURL is being used | ||
|
||
// Test non standard base URL | ||
cfg := config.Config{ | ||
Anthropic: &config.AnthropicConfig{ | ||
APIKeyFile: "/Users/jlewi/secrets/anthropic.key", | ||
BaseURL: "https://localhost:8844", | ||
}, | ||
} | ||
|
||
client, err := NewClient(cfg) | ||
if err != nil { | ||
t.Fatalf("Failed to create Anthropic client: %v", err) | ||
} | ||
|
||
message := "Say hello a funny way" | ||
messages := []anthropic.Message{ | ||
{Role: anthropic.RoleUser, | ||
Content: []anthropic.MessageContent{ | ||
{Type: anthropic.MessagesContentTypeText, | ||
Text: proto.String(message), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
request := anthropic.MessagesRequest{ | ||
Model: cfg.GetModel(), | ||
Messages: messages, | ||
MaxTokens: 2000, | ||
Temperature: proto.Float32(temperature), | ||
System: "You are a helper", | ||
} | ||
|
||
_, err = client.CreateMessages(context.Background(), request) | ||
if err != nil { | ||
t.Logf("Error: %+v", err) | ||
} | ||
} |
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