( ctx context.Context, systemPrompt string, messages []map[string]any, tools []map[string]any, options *LLMRequestOptions, )
| 322 | } |
| 323 | |
| 324 | return false |
| 325 | } |
| 326 | |
| 327 | type AnthropicClient struct { |
| 328 | LLMClientBase |
| 329 | } |
| 330 | |
| 331 | var _ LLMClient = (*AnthropicClient)(nil) |
| 332 | |
| 333 | func (c *AnthropicClient) buildHeaders() map[string]string { |
| 334 | headers := map[string]string{"anthropic-version": "2023-06-01", "content-type": "application/json"} |
| 335 | if isDeepSeekModel(c.Model) || strings.Contains(strings.ToLower(c.BaseURL), "api.deepseek.com") { |
| 336 | headers["Authorization"] = "Bearer " + c.APIKey |
| 337 | } else { |
| 338 | headers["x-api-key"] = c.APIKey |
| 339 | } |
| 340 | return headers |
| 341 | } |
| 342 | |
| 343 | func (c *AnthropicClient) Complete( |
| 344 | ctx context.Context, |
| 345 | systemPrompt string, |
| 346 | messages []map[string]any, |
| 347 | opts CompleteOptions, |
| 348 | ) (string, error) { |
| 349 | response, err := collectCompletionStream(c.StreamChat(ctx, systemPrompt, messages, opts.Tools, |
| 350 | &LLMRequestOptions{MaxTokens: opts.MaxTokens, Temperature: opts.Temperature})) |
| 351 | if err != nil { |
| 352 | return "", err |
| 353 | } |
| 354 | return response.Text, nil |
| 355 | } |
| 356 | |
| 357 | func (c *AnthropicClient) CompleteStructured( |
| 358 | ctx context.Context, |
| 359 | systemPrompt string, |
| 360 | messages []map[string]any, |
| 361 | opts StructuredCompletionOptions, |
| 362 | ) (Response, error) { |
| 363 | return collectCompletionStream(c.StreamChat(ctx, systemPrompt, messages, opts.Tools, &LLMRequestOptions{ |
| 364 | MaxTokens: opts.MaxTokens, RequiredTool: opts.RequiredTool, DisableThinking: opts.DisableThinking, |
| 365 | Temperature: opts.Temperature, |
| 366 | })) |
| 367 | } |
| 368 | |
| 369 | func (c *AnthropicClient) StreamChat( |
| 370 | ctx context.Context, |
| 371 | systemPrompt string, |
| 372 | messages []map[string]any, |
| 373 | tools []map[string]any, |
| 374 | options *LLMRequestOptions, |
| 375 | ) <-chan EventResult { |
| 376 | url := c.BaseURL + "/v1/messages" |
| 377 | headers := c.buildHeaders() |
| 378 | |
| 379 | apiTools := make([]map[string]any, 0, len(tools)) |
| 380 | for _, tool := range tools { |
| 381 | parameters, ok := tool["input_schema"] |
nothing calls this directly
no test coverage detected