gollm

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2025 License: MIT Imports: 6 Imported by: 0

README

gollm

gollm is a Go library which provides a simple interface for interacting with any LLM in Go.

Usage

go get github.com/dickeyy/gollm
model, err := gollm.InitializeModel("gpt-4o-mini", "your-api-key")
if err != nil { panic(err) }

res, err := model.Chat(gollm.ChatStructure{
    Messages: []gollm.ChatMessage{
        {
            Role: "user",
            Content: "Hello, how are you?"
        },
    },
})
if err != nil { panic(err) }

fmt.Println(res.Text)

Supported Models

  • OpenAI:
    • GPT-4o-mini (gpt-4o-mini)
    • GPT-4o (gpt-4o)
    • GPT-3.5-turbo (gpt-3.5-turbo)

More models coming soon!

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterModel

func RegisterModel(modelName string, constructor ModelConstructor)

RegisterModel allows LLM providers to register their constructors. This function is intended to be called from the init() function of provider packages.

Types

type ChatChoice

type ChatChoice struct {
	Index        int         `json:"index"`
	Message      ChatMessage `json:"message"`
	FinishReason string      `json:"finish_reason"`
}

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatResponse

type ChatResponse struct {
	Text string `json:"text"`
}

type ChatStructure

type ChatStructure struct {
	Messages []ChatMessage `json:"messages"`
}

type LLM

type LLM interface {
	Chat(structure ChatStructure) (*ChatResponse, error)
}

func InitializeModel

func InitializeModel(modelName string, apiKey string) (LLM, error)

InitializeModel creates an LLM instance based on the model name using the registry. It takes modelName and apiKey. The apiURL is handled by the constructor if needed.

type ModelConstructor

type ModelConstructor func(modelName string, apiKey string, apiURL string) (LLM, error)

ModelConstructor defines the function signature for creating an LLM instance. It takes apiKey and an optional apiURL.

type OpenAIModel added in v0.1.1

type OpenAIModel struct {
	// contains filtered or unexported fields
}

OpenAIModel implements the gollm.LLM interface for OpenAI models.

func NewOpenAiModel added in v0.1.1

func NewOpenAiModel(modelName string, apiKey string, apiURL string) (*OpenAIModel, error)

NewOpenAiModel creates a new instance of OpenAIModel. This is the function that will be registered with the factory.

func (*OpenAIModel) Chat added in v0.1.1

func (m *OpenAIModel) Chat(structure ChatStructure) (*ChatResponse, error)

Chat implements the gollm.LLM interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL