@@ -9,19 +9,28 @@ import (
99 "github.com/modelcontextprotocol/go-sdk/mcp"
1010)
1111
12- type ClaudeProvider struct {
12+ type AnthropicProvider struct {
1313 client anthropic.Client
1414}
1515
16- func NewClaudeProvider (apiKey string ) * ClaudeProvider {
17- return & ClaudeProvider {
16+ func NewClaudeProvider (apiKey string ) * AnthropicProvider {
17+ return & AnthropicProvider {
1818 client : anthropic .NewClient (option .WithAPIKey (apiKey )),
1919 }
2020}
2121
22- func (p * ClaudeProvider ) Chat (ctx context.Context , opts ChatOptions ) (* LLMResponse , error ) {
23- messages := convertMessagesToClaude (opts .Messages )
24- tools := convertToolsToClaude (opts .Tools )
22+ func NewOllamaProvider (baseURL string ) * AnthropicProvider {
23+ return & AnthropicProvider {
24+ client : anthropic .NewClient (
25+ option .WithBaseURL (baseURL ),
26+ option .WithAPIKey ("ollama" ),
27+ ),
28+ }
29+ }
30+
31+ func (p * AnthropicProvider ) Chat (ctx context.Context , opts ChatOptions ) (* LLMResponse , error ) {
32+ messages := convertMessagesToAnthropic (opts .Messages )
33+ tools := convertToolsToAnthropic (opts .Tools )
2534
2635 response , err := p .client .Messages .New (ctx , anthropic.MessageNewParams {
2736 Model : anthropic .Model (opts .Model ),
@@ -31,13 +40,13 @@ func (p *ClaudeProvider) Chat(ctx context.Context, opts ChatOptions) (*LLMRespon
3140 Tools : tools ,
3241 })
3342 if err != nil {
34- return nil , fmt .Errorf ("claude API error: %w" , err )
43+ return nil , fmt .Errorf ("LLM API error: %w" , err )
3544 }
3645
37- return parseClaudeResponse (response ), nil
46+ return parseAnthropicResponse (response ), nil
3847}
3948
40- func convertMessagesToClaude (messages []Message ) []anthropic.MessageParam {
49+ func convertMessagesToAnthropic (messages []Message ) []anthropic.MessageParam {
4150 result := make ([]anthropic.MessageParam , 0 , len (messages ))
4251
4352 i := 0
@@ -77,15 +86,15 @@ func convertMessagesToClaude(messages []Message) []anthropic.MessageParam {
7786 return result
7887}
7988
80- func convertToolsToClaude (tools []* mcp.Tool ) []anthropic.ToolUnionParam {
89+ func convertToolsToAnthropic (tools []* mcp.Tool ) []anthropic.ToolUnionParam {
8190 result := make ([]anthropic.ToolUnionParam , 0 , len (tools ))
8291 for _ , tool := range tools {
83- result = append (result , convertMCPToolToClaude (tool ))
92+ result = append (result , convertMCPToolToAnthropic (tool ))
8493 }
8594 return result
8695}
8796
88- func convertMCPToolToClaude (tool * mcp.Tool ) anthropic.ToolUnionParam {
97+ func convertMCPToolToAnthropic (tool * mcp.Tool ) anthropic.ToolUnionParam {
8998 inputSchemaMap , ok := tool .InputSchema .(map [string ]any )
9099 if ! ok || inputSchemaMap == nil {
91100 inputSchemaMap = map [string ]any {}
@@ -120,7 +129,7 @@ func convertMCPToolToClaude(tool *mcp.Tool) anthropic.ToolUnionParam {
120129 return toolParam
121130}
122131
123- func parseClaudeResponse (response * anthropic.Message ) * LLMResponse {
132+ func parseAnthropicResponse (response * anthropic.Message ) * LLMResponse {
124133 result := & LLMResponse {}
125134
126135 for _ , block := range response .Content {
0 commit comments