Documentation
¶
Overview ¶
Package llm provides a Starlark module that calls OpenAI models.
Configuration options:
- openai_provider: Provider type (openai, azure, anthropic)
- openai_endpoint_url: API endpoint URL
- openai_api_key: API key for authentication
- openai_gpt_model: Default GPT model name
- openai_dalle_model: Default DALL-E model name
- api_version: API version (used by Azure and Anthropic)
- legacy_mode: Use legacy mode for data conversion (default: true)
The chat function supports both blocking and streaming modes:
- In blocking mode (default), the function waits for the complete response
- In streaming mode (stream=True), responses are received incrementally and can be processed via a callback
- Streaming mode can improve responsiveness for large responses or when displaying partial results is desired
- To use streaming mode, set stream=True and optionally provide stream_callback=function
- The stream_callback receives each chunk of the response as it arrives
- In both streaming and blocking modes, the function returns the same format: either the complete content or full response
- For streaming, the content is automatically aggregated from all chunks
Custom parameters support:
- The kwargs parameter allows passing custom or non-standard parameters to the API
- Useful for provider-specific features, experimental parameters, or custom deployments
- Any dictionary passed as kwargs will be included in the ChatTemplateKwargs field of the API request
Token parameters for different models:
- max_tokens: Maximum number of tokens to generate; 0 (the default) leaves it unset so the API applies its own default - works with most models
- max_completion_tokens: Upper bound for generated completion tokens - for o1 series models
- For o1, o3, o4 series models, use max_completion_tokens instead of max_tokens
When legacy_mode is true (default), response objects are converted using direct struct access (ConvertJSONStruct). When false, JSON conversion is used (GoToStarlarkViaJSON).
Index ¶
Constants ¶
const ( // ProviderOpenAI represents the default OpenAI API provider ProviderOpenAI = "openai" // ProviderAzure represents the Azure OpenAI Service provider ProviderAzure = "azure" // ProviderAnthropic represents the Anthropic Claude API provider ProviderAnthropic = "anthropic" )
Provider type constants
const ModuleName = "llm"
ModuleName defines the expected name for this module when used in Starlark's load() function, e.g., load('llm', 'chat')
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module wraps the ConfigurableModule with specific functionality for calling OpenAI models.
func NewModule ¶
func NewModule() *Module
NewModule creates a new instance of Module with default empty configurations.
func NewModuleWithConfig ¶
func NewModuleWithConfig(serviceProvider, endpointURL, apiKey, gptModel, dalleModel, apiVersion string) *Module
NewModuleWithConfig creates a new instance of Module with the given configuration values.
func (*Module) LoadModule ¶
func (m *Module) LoadModule() starlet.ModuleLoader
LoadModule returns the Starlark module loader exposing the llm builtins (message, chat, draw) plus the generated config setters/getters.