Documentation
¶
Index ¶
- Constants
- func NewHistory(messages []openai.ChatCompletionMessage) (*gollem.History, error)
- func ToMessages(h *gollem.History) ([]openai.ChatCompletionMessage, error)
- type Client
- type Option
- func WithBaseURL(url string) Option
- func WithContentType(contentType gollem.ContentType) Option
- func WithEmbeddingModel(modelName string) Option
- func WithFrequencyPenalty(penalty float32) Option
- func WithMaxTokens(maxTokens int) Option
- func WithModel(modelName string) Option
- func WithPresencePenalty(penalty float32) Option
- func WithReasoningEffort(effort string) Option
- func WithSystemPrompt(prompt string) Option
- func WithTemperature(temp float32) Option
- func WithTopP(topP float32) Option
- func WithVerbosity(verbosity string) Option
- type Session
- func (s *Session) AppendHistory(h *gollem.History) error
- func (s *Session) CountToken(ctx context.Context, input ...gollem.Input) (int, error)
- func (s *Session) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
- func (s *Session) GenerateContent(ctx context.Context, input ...gollem.Input) (*gollem.Response, error)deprecated
- func (s *Session) GenerateStream(ctx context.Context, input ...gollem.Input) (<-chan *gollem.Response, error)deprecated
- func (s *Session) History() (*gollem.History, error)
- func (s *Session) Stream(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (<-chan *gollem.Response, error)
Constants ¶
const ( DefaultModel = "gpt-5" DefaultEmbeddingModel = "text-embedding-3-small" )
Variables ¶
This section is empty.
Functions ¶
func NewHistory ¶
func NewHistory(messages []openai.ChatCompletionMessage) (*gollem.History, error)
NewHistory creates gollem.History from OpenAI messages
func ToMessages ¶
func ToMessages(h *gollem.History) ([]openai.ChatCompletionMessage, error)
ToMessages converts gollem.History to OpenAI messages
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the OpenAI API. It provides methods to interact with OpenAI's OpenAI models.
func New ¶
New creates a new client for the OpenAI API. It requires an API key and can be configured with additional options.
func (*Client) GenerateEmbedding ¶
func (c *Client) GenerateEmbedding(ctx context.Context, dimension int, input []string) ([][]float64, error)
GenerateEmbedding generates embeddings for the given input text.
func (*Client) NewSession ¶
func (c *Client) NewSession(ctx context.Context, options ...gollem.SessionOption) (gollem.Session, error)
NewSession creates a new session for the OpenAI API. It converts the provided tools to OpenAI's tool format and initializes a new chat session.
type Option ¶
type Option func(*Client)
Option is a function that configures a Client.
func WithBaseURL ¶
WithBaseURL sets the custom base URL for the OpenAI API. Allows usage with compatible endpoints, proxies, or self-hosted instances. If empty, uses the default OpenAI API endpoints. Reference: Brain Memory c4705651-435d-4cca-95eb-d39d1ea69a9c
func WithContentType ¶
func WithContentType(contentType gollem.ContentType) Option
WithContentType sets the content type for text generation. This determines the format of the generated content.
func WithEmbeddingModel ¶
WithEmbeddingModel sets the embedding model to use for embeddings. The model name should be a valid OpenAI model identifier. See default embedding model in DefaultEmbeddingModel. Model list is at https://platform.openai.com/docs/guides/embeddings#embedding-models
func WithFrequencyPenalty ¶
WithFrequencyPenalty sets the frequency penalty parameter. Decreases the model's likelihood to repeat the same line verbatim.
func WithMaxTokens ¶
WithMaxTokens sets the maximum number of tokens to generate.
func WithModel ¶
WithModel sets the default model to use for chat completions. The model name should be a valid OpenAI model identifier. See default model in DefaultModel.
func WithPresencePenalty ¶
WithPresencePenalty sets the presence penalty parameter. Increases the model's likelihood to talk about new topics.
func WithReasoningEffort ¶
WithReasoningEffort sets the reasoning_effort parameter for GPT-5 models. Supported values (as of 2025-10-04): "minimal", "medium", "high".
func WithSystemPrompt ¶
WithSystemPrompt sets the system prompt to use for chat completions.
func WithTemperature ¶
WithTemperature sets the temperature parameter for text generation. Higher values make the output more random, lower values make it more focused. Range: 0.0 to 1.0 Default: 0.7
func WithTopP ¶
WithTopP sets the top_p parameter for text generation. Controls diversity via nucleus sampling.
func WithVerbosity ¶
WithVerbosity sets the verbosity parameter for GPT-5 models. Supported values (as of 2025-10-04): "low", "medium", "high".
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a session for the OpenAI chat. It maintains the conversation state and handles message generation.
func (*Session) CountToken ¶
CountToken calculates the total number of tokens for the given inputs, including system prompt, history messages, and new inputs. This uses tiktoken library for local token counting without API calls.
func (*Session) Generate ¶
func (s *Session) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
Generate processes the input and generates a response with optional per-call overrides. It handles both text messages and function responses.
func (*Session) Stream ¶
func (s *Session) Stream(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (<-chan *gollem.Response, error)
Stream processes the input and generates a response stream with optional per-call overrides. It handles both text messages and function responses, and returns a channel for streaming responses.