llms

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

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,
	"claude-instant-1":   100_000,
	"claude-2":           100_000,
}
View Source
var ValidAnthropicLLMs = map[string]bool{
	"claude-instant-1": true,
	"claude-2":         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,
}

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