|
5 | 5 | "errors"
|
6 | 6 |
|
7 | 7 | "github.com/appleboy/CodeGPT/core"
|
| 8 | + "github.com/appleboy/CodeGPT/provider/anthropic" |
8 | 9 | "github.com/appleboy/CodeGPT/provider/gemini"
|
9 | 10 | "github.com/appleboy/CodeGPT/provider/openai"
|
10 | 11 |
|
@@ -44,13 +45,35 @@ func NewGemini(ctx context.Context) (*gemini.Client, error) {
|
44 | 45 | )
|
45 | 46 | }
|
46 | 47 |
|
| 48 | +// NewAnthropic creates a new instance of the anthropic.Client using configuration |
| 49 | +// values retrieved from Viper. The configuration values include the API key, |
| 50 | +// model, maximum tokens, temperature, and top_p. |
| 51 | +// |
| 52 | +// Parameters: |
| 53 | +// - ctx: The context for the client. |
| 54 | +// |
| 55 | +// Returns: |
| 56 | +// - A pointer to an anthropic.Client instance. |
| 57 | +// - An error if the client could not be created. |
| 58 | +func NewAnthropic(ctx context.Context) (*anthropic.Client, error) { |
| 59 | + return anthropic.New( |
| 60 | + anthropic.WithAPIKey(viper.GetString("openai.api_key")), |
| 61 | + anthropic.WithModel(viper.GetString("openai.model")), |
| 62 | + anthropic.WithMaxTokens(viper.GetInt("openai.max_tokens")), |
| 63 | + anthropic.WithTemperature(float32(viper.GetFloat64("openai.temperature"))), |
| 64 | + anthropic.WithTopP(float32(viper.GetFloat64("openai.top_p"))), |
| 65 | + ) |
| 66 | +} |
| 67 | + |
47 | 68 | // GetClient returns the generative client based on the platform
|
48 | 69 | func GetClient(ctx context.Context, p core.Platform) (core.Generative, error) {
|
49 | 70 | switch p {
|
50 | 71 | case core.Gemini:
|
51 | 72 | return NewGemini(ctx)
|
52 | 73 | case core.OpenAI, core.Azure:
|
53 | 74 | return NewOpenAI()
|
| 75 | + case core.Anthropic: |
| 76 | + return NewAnthropic(ctx) |
54 | 77 | }
|
55 | 78 | return nil, errors.New("invalid provider")
|
56 | 79 | }
|
0 commit comments