MCPcopy Index your code
hub / github.com/coder/coder / anthropicDataStream

Function anthropicDataStream

coderd/taskname/taskname.go:332–351  ·  view source on GitHub ↗
(ctx context.Context, client anthropic.Client, model anthropic.Model, input []aisdk.Message)

Source from the content-addressed store, hash-verified

330}
331
332func 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}

Callers 1

generateFromAnthropicFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected