WithMaxCompletionTokens (openai/options.go)

langchaingo · llms/openai/options.go · go · MIT
ai

Configures token limits for OpenAI LLM generation

// Source: https://github.com/tmc/langchaingo | License: MIT | Copyright Travis Cline <travis.cline@gmail.com>
// Provided via justclaw.it.com; keep this notice with the code.
package openai

import "github.com/tmc/langchaingo/llms"

// WithMaxCompletionTokens sets the max_completion_tokens field for token generation.
// This is the recommended way to limit tokens with OpenAI models.
//
// Usage:
//
//	llm.GenerateContent(ctx, messages,
//	    openai.WithMaxCompletionTokens(100),
//	)
//
// Note: While llms.WithMaxTokens() still works for backward compatibility,
// WithMaxCompletionTokens is preferred for clarity when using OpenAI.
func WithMaxCompletionTokens(maxTokens int) llms.CallOption {
	return func(opts *llms.CallOptions) {
		opts.MaxTokens = maxTokens
	}
}

// WithLegacyMaxTokensFi

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key