(ctx context.Context, client anthropic.Client, model anthropic.Model, input []aisdk.Message)
| 330 | } |
| 331 | |
| 332 | func anthropicDataStream(ctx context.Context, client anthropic.Client, model anthropic.Model, input []aisdk.Message) (aisdk.DataStream, error) { |
| 333 | messages, system, err := aisdk.MessagesToAnthropic(input) |
| 334 | if err != nil { |
| 335 | return nil, xerrors.Errorf("convert messages to anthropic format: %w", err) |
| 336 | } |
| 337 | |
| 338 | return aisdk.AnthropicToDataStream(client.Messages.NewStreaming(ctx, anthropic.MessageNewParams{ |
| 339 | Model: model, |
| 340 | // MaxTokens is set to 100 based on the maximum expected output size. |
| 341 | // The worst-case JSON output is 134 characters: |
| 342 | // - Base structure: 43 chars (including formatting) |
| 343 | // - task_name: 27 chars max |
| 344 | // - display_name: 64 chars max |
| 345 | // Using Anthropic's token counting API, this worst-case output tokenizes to 70 tokens. |
| 346 | // We set MaxTokens to 100 to provide a safety buffer. |
| 347 | MaxTokens: 100, |
| 348 | System: system, |
| 349 | Messages: messages, |
| 350 | })), nil |
| 351 | } |
no test coverage detected