llms

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AnthropicAPIKeyNotSetError = "ZEP_ANTHROPIC_API_KEY is not set" //nolint:gosec
View Source
const AnthropicAPITimeout = 30 * time.Second
View Source
const DefaultTemperature = 0.0
View Source
const InvalidLLMModelError = "llm model is not set or is invalid"
View Source
const LocalEmbedderTimeout = 60 * time.Second
View Source
const MaxLocalEmbedderRetryAttempts = 5
View Source
const MaxOpenAIAPIRequestAttempts = 5
View Source
const OpenAIAPIKeyNotSetError = "ZEP_OPENAI_API_KEY is not set" //nolint:gosec
View Source
const OpenAIAPITimeout = 20 * time.Second
View Source
const OpenAICallTimeout = 60 * time.Second
View Source
const OtelLLMTracerName = "llm"

Variables

View Source
var MaxLLMTokensMap = map[string]int{
	"gpt-3.5-turbo":              4096,
	"gpt-3.5-turbo-16k":          16_385,
	"gpt-3.5-turbo-1106":         16_385,
	"gpt-4":                      8192,
	"gpt-4-32k":                  32_768,
	"gpt-4-1106-preview":         128_000,
	"gpt-4-turbo":                128_000,
	"gpt-4o":                     128_000,
	"gpt-4o-mini":                128_000,
	"claude-instant-1":           100_000,
	"claude-2":                   100_000,
	"claude-3-5-sonnet-20240620": 200_000,
	"claude-3-haiku-20240307":    200_000,
	"claude-3-opus-20240229":     200_000,
	"claude-3-sonnet-20240229":   200_000,
}
View Source
var ValidAnthropicLLMs = map[string]bool{
	"claude-instant-1":           true,
	"claude-2":                   true,
	"claude-3-5-sonnet-20240620": true,
	"claude-3-opus-20240229":     true,
	"claude-3-sonnet-20240229":   true,
	"claude-3-haiku-20240307":    true,
}
View Source
var ValidOpenAILLMs = map[string]bool{
	"gpt-3.5-turbo":          true,
	"gpt-4":                  true,
	"gpt-3.5-turbo-16k":      true,
	"gpt-3.5-turbo-1106":     true,
	"gpt-4-32k":              true,
	"gpt-4-1106-preview":     true,
	"gpt-4-turbo":            true,
	"gpt-4o":                 true,
	"gpt-4o-2024-08-06":      true,
	"gpt-4o-mini":            true,
	"gpt-4o-mini-2024-07-18": true,
}

Functions

func EmbedTexts added in v0.6.5

func EmbedTexts(
	ctx context.Context,
	appState *models.AppState,
	model *models.EmbeddingModel,
	documentType string,
	text []string,
) ([][]float32, error)

func Float64ToFloat32Matrix added in v0.10.0

func Float64ToFloat32Matrix(in [][]float64) [][]float32

func GetEmbeddingModel added in v0.10.0

func GetEmbeddingModel(
	appState *models.AppState,
	documentType string,
) (*models.EmbeddingModel, error)

func GetLLMModelName

func GetLLMModelName(cfg *config.Config) (string, error)

func NewAnthropicLLM added in v0.10.0

func NewAnthropicLLM(ctx context.Context, cfg *config.Config) (models.ZepLLM, error)

func NewLLMClient added in v0.10.0

func NewLLMClient(ctx context.Context, cfg *config.Config) (models.ZepLLM, error)

func NewOpenAILLM added in v0.10.0

func NewOpenAILLM(ctx context.Context, cfg *config.Config) (models.ZepLLM, error)

func NewRetryableHTTPClient added in v0.10.0

func NewRetryableHTTPClient(retryMax int, timeout time.Duration) *http.Client

Types

type LLMError

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

func NewLLMError

func NewLLMError(message string, originalError error) *LLMError

func (*LLMError) Error

func (e *LLMError) Error() string

type ZepAnthropicLLM added in v0.10.0

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

func (*ZepAnthropicLLM) Call added in v0.10.0

func (zllm *ZepAnthropicLLM) Call(ctx context.Context,
	prompt string,
	options ...llms.CallOption,
) (string, error)

func (*ZepAnthropicLLM) EmbedTexts added in v0.10.0

func (zllm *ZepAnthropicLLM) EmbedTexts(_ context.Context, _ []string) ([][]float32, error)

func (*ZepAnthropicLLM) GetTokenCount added in v0.10.0

func (zllm *ZepAnthropicLLM) GetTokenCount(_ string) (int, error)

GetTokenCount returns the number of tokens in the text. Return 0 for now, since we don't have a token count function

func (*ZepAnthropicLLM) Init added in v0.10.0

func (zllm *ZepAnthropicLLM) Init(_ context.Context, cfg *config.Config) error

type ZepLLM added in v0.19.0

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

ZepLLM is a wrapper around the Zep LLM implementations that implements the ZepLLM interface and adds OpenTelemetry tracing

func (*ZepLLM) Call added in v0.19.0

func (zllm *ZepLLM) Call(ctx context.Context,
	prompt string,
	options ...llms.CallOption,
) (string, error)

func (*ZepLLM) EmbedTexts added in v0.19.0

func (zllm *ZepLLM) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ZepLLM) GetTokenCount added in v0.19.0

func (zllm *ZepLLM) GetTokenCount(text string) (int, error)

func (*ZepLLM) Init added in v0.19.0

func (zllm *ZepLLM) Init(ctx context.Context, cfg *config.Config) error

type ZepOpenAILLM added in v0.10.0

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

func (*ZepOpenAILLM) Call added in v0.10.0

func (zllm *ZepOpenAILLM) Call(ctx context.Context,
	prompt string,
	options ...llms.CallOption,
) (string, error)

func (*ZepOpenAILLM) EmbedTexts added in v0.10.0

func (zllm *ZepOpenAILLM) EmbedTexts(ctx context.Context, texts []string) ([][]float32, error)

func (*ZepOpenAILLM) GetTokenCount added in v0.10.0

func (zllm *ZepOpenAILLM) GetTokenCount(text string) (int, error)

GetTokenCount returns the number of tokens in the text

func (*ZepOpenAILLM) Init added in v0.10.0

func (zllm *ZepOpenAILLM) Init(_ context.Context, cfg *config.Config) error

Jump to

Keyboard shortcuts

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