llm

package module
v0.0.0-...-310b2b4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 10 Imported by: 0

README

llm

Logo

GoDoc Go

LLM tools and helpers in Go.

⚠️ This library is in development. Things will probably break, but existing functionality is usable. ⚠️

go get maragu.dev/llm

Made with ✨sparkles✨ by maragu.

Does your company depend on this project? Contact me at markus@maragu.dk to discuss options for a one-time or recurring invoice to ensure its continued thriving.

Usage

This test will only run with go test -run TestEval ./... and otherwise be skipped:

package examples_test

import (
	"testing"

	"maragu.dev/llm/eval"
)

// TestEvalPrompt evaluates the Prompt method.
// All evals must be prefixed with "TestEval".
func TestEvalPrompt(t *testing.T) {
	// Evals only run if "go test" is being run with "-test.run=TestEval", e.g.: "go test -test.run=TestEval ./..."
	eval.Run(t, "answers with a pong", func(e *eval.E) {
		// Initialize our intensely powerful LLM.
		llm := &llm{response: "plong"}

		// Send our input to the LLM and get an output back.
		input := "ping"
		output := llm.Prompt(input)

		// Create a sample to pass to the scorer.
		sample := eval.Sample{
			Expected: "pong",
			Input:    input,
			Output:   output,
		}

		// Score the sample using the Levenshtein distance scorer.
		// The scorer is created inline, but for scorers that need more setup, this can be done elsewhere.
		result := e.Score(sample, eval.LevenshteinDistanceScorer())

		// Log the result to stdout.
		e.Log(result)
	})
}

type llm struct {
	response string
}

func (l *llm) Prompt(request string) string {
	return l.response
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnthropicClient

type AnthropicClient struct {
	Client *anthropic.Client
	// contains filtered or unexported fields
}

func NewAnthropicClient

func NewAnthropicClient(opts NewAnthropicClientOptions) *AnthropicClient

type GoogleClient

type GoogleClient struct {
	Client *genai.Client
	// contains filtered or unexported fields
}

func NewGoogleClient

func NewGoogleClient(opts NewGoogleClientOptions) *GoogleClient

type NewAnthropicClientOptions

type NewAnthropicClientOptions struct {
	Key string
	Log *slog.Logger
}

type NewGoogleClientOptions

type NewGoogleClientOptions struct {
	Key string
	Log *slog.Logger
}

type NewOpenAIClientOptions

type NewOpenAIClientOptions struct {
	BaseURL string
	Key     string
	Log     *slog.Logger
}

type OpenAIClient

type OpenAIClient struct {
	Client *openai.Client
	// contains filtered or unexported fields
}

func NewOpenAIClient

func NewOpenAIClient(opts NewOpenAIClientOptions) *OpenAIClient

Directories

Path Synopsis
Package eval lets you evaluate LLM output by scoring it with various scoring methods, and logging the result.
Package eval lets you evaluate LLM output by scoring it with various scoring methods, and logging the result.

Jump to

Keyboard shortcuts

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