# API Generated from the package comment and every exported declaration. Do not edit. Regenerate with `UPDATE_API_DOCS=1 go test -run TestAPIDoc -count=1`. ## Package gollm Package gollm is a chat LLM wire client: Chat, Stream, and List Models through an Ollama-native or OpenAI-compatible Adapter. ## Types ### Adapter ```go type Adapter string ``` Adapter selects the wire protocol a Client speaks. [AdapterOpenAI](#adapteropenai) uses POST /v1/chat/completions and GET /v1/models. [AdapterOllama](#adapterollama) uses POST /api/chat and GET /api/tags. #### AdapterOpenAI #### AdapterOllama ```go const ( // AdapterOpenAI selects the OpenAI-compatible protocol. AdapterOpenAI Adapter = "openai" // AdapterOllama selects the Ollama native protocol. AdapterOllama Adapter = "ollama" ) ``` ### Client ```go type Client struct { // contains filtered or unexported fields } ``` Client calls one Adapter at one base URL. An empty API key sends no Authorization header. A non-empty key is sent as a Bearer token on every request. #### NewClient ```go func NewClient(adapter Adapter, baseURL, apiKey string) (*Client, error) ``` NewClient checks adapter and baseURL. It returns an error when adapter is not [AdapterOpenAI](#adapteropenai) or [AdapterOllama](#adapterollama), or when baseURL is empty or only whitespace. A trailing slash on baseURL is removed. apiKey may be empty. #### Client.Chat ```go func (c *Client) Chat(ctx context.Context, messages []Message, opt Options) (string, error) ``` Chat sends messages and returns the assistant text. It returns an error when ctx is canceled, the HTTP status is not 2xx, the body cannot be decoded, or an OpenAI response contains no choices. An HTTP failure includes a short prefix of the response body. #### Client.ListModels ```go func (c *Client) ListModels(ctx context.Context) ([]string, error) ``` ListModels returns model names reported by the server. [AdapterOpenAI](#adapteropenai) reads data\[].id from GET /v1/models. [AdapterOllama](#adapterollama) reads models\[].name from GET /api/tags. It returns an error when ctx is canceled, the HTTP status is not 2xx, or the body cannot be decoded. Empty names are omitted. #### Client.Stream ```go func (c *Client) Stream(ctx context.Context, messages []Message, opt Options, yield func(chunk string) error) error ``` Stream sends the same request as Chat with streaming enabled and calls yield for each non-empty text chunk, in order. It returns the error from yield. It also returns an error when ctx is canceled, the HTTP status is not 2xx, or a stream line cannot be decoded. [AdapterOpenAI](#adapteropenai) ends the stream when a data line is the token DONE. [AdapterOllama](#adapterollama) reads one JSON object per line and yields message content. ### Message ```go type Message struct { Role Role Content string } ``` Message is one chat turn. Role and Content are sent unchanged. ### Options ```go type Options struct { Model string Temperature *float64 MaxTokens *int } ``` Options configures one Chat or Stream call. Model is the server-side model name. The Client does not check that it is set; the server rejects an empty model. A nil Temperature or MaxTokens is left out of the request. On [AdapterOllama](#adapterollama), MaxTokens is sent as num\_predict. ### Role ```go type Role string ``` Role is the speaker of one Message. #### RoleSystem #### RoleUser #### RoleAssistant ```go const ( // RoleSystem is a system instruction. RoleSystem Role = "system" // RoleUser is the caller's turn. RoleUser Role = "user" // RoleAssistant is a previous model turn. RoleAssistant Role = "assistant" ) ```