llm

package
v0.0.110 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package llm provides functionalities for working with Large Language Models (LLMs).

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpenAIOptions = OpenAIOptions{
	CallbackOptions: &schema.CallbackOptions{
		Verbose: golc.Verbose,
	},
	ModelName:        openai.GPT3Dot5TurboInstruct,
	Temperature:      0.7,
	MaxTokens:        256,
	TopP:             1,
	PresencePenalty:  0,
	FrequencyPenalty: 0,
	N:                1,
	BestOf:           1,
	Stream:           false,
	MaxRetries:       3,
}
View Source
var DefaultPenalty = ai21.Penalty{
	Scale:               0,
	ApplyToWhitespaces:  true,
	ApplyToPunctuations: true,
	ApplyToNumbers:      true,
	ApplyToStopwords:    true,
	ApplyToEmojis:       true,
}

DefaultPenalty represents the default penalty options for AI21 text completion.

Functions

func EnforceStopTokens added in v0.0.71

func EnforceStopTokens(text string, stop []string) string

EnforceStopTokens cuts off the text as soon as any stop words occur.

Types

type AI21 added in v0.0.70

type AI21 struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

AI21 is an AI21 LLM model that generates text based on a provided response function.

func NewAI21 added in v0.0.70

func NewAI21(apiKey string, optFns ...func(o *AI21Options)) (*AI21, error)

NewAI21 creates a new AI21 LLM instance with the provided API key and optional configuration options.

func NewAI21FromClient added in v0.0.70

func NewAI21FromClient(client AI21Client, optFns ...func(o *AI21Options)) (*AI21, error)

NewAI21FromClient creates a new AI21 LLM instance using the provided AI21 client and optional configuration options.

func (*AI21) Callbacks added in v0.0.70

func (l *AI21) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*AI21) Generate added in v0.0.70

func (l *AI21) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*AI21) InvocationParams added in v0.0.70

func (l *AI21) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*AI21) Type added in v0.0.70

func (l *AI21) Type() string

Type returns the type of the model.

func (*AI21) Verbose added in v0.0.70

func (l *AI21) Verbose() bool

Verbose returns the verbosity setting of the model.

type AI21Client added in v0.0.70

type AI21Client interface {
	CreateCompletion(ctx context.Context, model string, req *ai21.CompleteRequest) (*ai21.CompleteResponse, error)
}

AI21Client is an interface for interacting with the AI21 API.

type AI21Options added in v0.0.70

type AI21Options struct {
	// CallbackOptions specify options for handling callbacks during text generation.
	*schema.CallbackOptions `map:"-"`
	// Tokenizer represents the tokenizer to be used with the LLM model.
	schema.Tokenizer `map:"-"`

	// Model is the name of the AI21 model to use for text completion.
	Model string `map:"model,omitempty"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float64 `map:"temperature"`

	// MaxTokens sets the maximum number of tokens in the generated text.
	MaxTokens int `map:"maxTokens"`

	// MinTokens sets the minimum number of tokens in the generated text.
	MinTokens int `map:"minTokens"`

	// TopP sets the nucleus sampling probability. Higher values result in more diverse text.
	TopP float64 `map:"topP"`

	// PresencePenalty specifies the penalty for repeating words in generated text.
	PresencePenalty ai21.Penalty `map:"presencePenalty"`

	// CountPenalty specifies the penalty for repeating tokens in generated text.
	CountPenalty ai21.Penalty `map:"countPenalty"`

	// FrequencyPenalty specifies the penalty for generating frequent words.
	FrequencyPenalty ai21.Penalty `map:"frequencyPenalty"`

	// NumResults sets the number of completion results to return.
	NumResults int `map:"numResults"`
}

AI21Options contains options for configuring the AI21 LLM model.

type AzureOpenAI added in v0.0.38

type AzureOpenAI struct {
	*OpenAI
	// contains filtered or unexported fields
}

func NewAzureOpenAI added in v0.0.38

func NewAzureOpenAI(apiKey, baseURL string, optFns ...func(o *AzureOpenAIOptions)) (*AzureOpenAI, error)

func (*AzureOpenAI) InvocationParams added in v0.0.55

func (l *AzureOpenAI) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*AzureOpenAI) Type added in v0.0.38

func (l *AzureOpenAI) Type() string

Type returns the type of the model.

type AzureOpenAIOptions added in v0.0.38

type AzureOpenAIOptions struct {
	OpenAIOptions
	Deployment string `map:"deployment,omitempty"`
}

type Bedrock added in v0.0.71

type Bedrock struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

Bedrock is a Bedrock LLM model that generates text based on a provided response function.

func NewBedrock added in v0.0.71

func NewBedrock(client BedrockRuntimeClient, modelID string, optFns ...func(o *BedrockOptions)) (*Bedrock, error)

NewBedrock creates a new instance of the Bedrock LLM model with the provided response function and options.

func NewBedrockAI21 added in v0.0.78

func NewBedrockAI21(client BedrockRuntimeClient, optFns ...func(o *BedrockAI21Options)) (*Bedrock, error)

func NewBedrockAmazon added in v0.0.79

func NewBedrockAmazon(client BedrockRuntimeClient, optFns ...func(o *BedrockAmazonOptions)) (*Bedrock, error)

func NewBedrockAnthropic added in v0.0.110

func NewBedrockAnthropic(client BedrockRuntimeClient, optFns ...func(o *BedrockAnthropicOptions)) (*Bedrock, error)

func NewBedrockCohere added in v0.0.79

func NewBedrockCohere(client BedrockRuntimeClient, optFns ...func(o *BedrockCohereOptions)) (*Bedrock, error)

func NewBedrockMeta added in v0.0.87

func NewBedrockMeta(client BedrockRuntimeClient, optFns ...func(o *BedrockMetaOptions)) (*Bedrock, error)

NewBedrockMeta creates a new instance of Bedrock for the "meta" provider.

func NewBedrockMistral added in v0.0.109

func NewBedrockMistral(client BedrockRuntimeClient, optFns ...func(o *BedrockMistralOptions)) (*Bedrock, error)

func (*Bedrock) Callbacks added in v0.0.71

func (l *Bedrock) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*Bedrock) Generate added in v0.0.71

func (l *Bedrock) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*Bedrock) InvocationParams added in v0.0.71

func (l *Bedrock) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*Bedrock) Type added in v0.0.71

func (l *Bedrock) Type() string

Type returns the type of the model.

func (*Bedrock) Verbose added in v0.0.71

func (l *Bedrock) Verbose() bool

Verbose returns the verbosity setting of the model.

type BedrockAI21Options added in v0.0.78

type BedrockAI21Options struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float64 `map:"temperature"`

	// TopP sets the nucleus sampling probability. Higher values result in more diverse text.
	TopP float64 `map:"topP"`

	// MaxTokens sets the maximum number of tokens in the generated text.
	MaxTokens int `map:"maxTokens"`

	// PresencePenalty specifies the penalty for repeating words in generated text.
	PresencePenalty ai21.Penalty `map:"presencePenalty"`

	// CountPenalty specifies the penalty for repeating tokens in generated text.
	CountPenalty ai21.Penalty `map:"countPenalty"`

	// FrequencyPenalty specifies the penalty for generating frequent words.
	FrequencyPenalty ai21.Penalty `map:"frequencyPenalty"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

type BedrockAmazonOptions added in v0.0.79

type BedrockAmazonOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float64 `json:"temperature"`

	// TopP is the total probability mass of tokens to consider at each step.
	TopP float64 `json:"topP"`

	// MaxTokenCount sets the maximum number of tokens in the generated text.
	MaxTokenCount int `json:"maxTokenCount"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

type BedrockAnthropicOptions added in v0.0.77

type BedrockAnthropicOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// MaxTokensToSmaple sets the maximum number of tokens in the generated text.
	MaxTokensToSample int `map:"max_tokens_to_sample"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float32 `map:"temperature"`

	// TopP is the total probability mass of tokens to consider at each step.
	TopP float32 `map:"top_p,omitempty"`

	// TopK determines how the model selects tokens for output.
	TopK int `map:"top_k"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

type BedrockCohereOptions added in v0.0.79

type BedrockCohereOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float64 `json:"temperature,omitempty"`

	// P is the total probability mass of tokens to consider at each step.
	P float64 `json:"p,omitempty"`

	// K determines how the model selects tokens for output.
	K float64 `json:"k,omitempty"`

	// MaxTokens sets the maximum number of tokens in the generated text.
	MaxTokens int `json:"max_tokens,omitempty"`

	// ReturnLikelihoods specifies how and if the token likelihoods are returned with the response.
	ReturnLikelihoods ReturnLikelihood `json:"return_likelihoods,omitempty"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

type BedrockInputOutputAdapter added in v0.0.71

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

BedrockInputOutputAdapter is a helper struct for preparing input and handling output for Bedrock model.

func NewBedrockInputOutputAdapter added in v0.0.71

func NewBedrockInputOutputAdapter(provider string) *BedrockInputOutputAdapter

NewBedrockInputOutputAdpter creates a new instance of BedrockInputOutputAdpter.

func (*BedrockInputOutputAdapter) PrepareInput added in v0.0.71

func (bioa *BedrockInputOutputAdapter) PrepareInput(prompt string, modelParams map[string]any) ([]byte, error)

PrepareInput prepares the input for the Bedrock model based on the specified provider.

func (*BedrockInputOutputAdapter) PrepareOutput added in v0.0.71

func (bioa *BedrockInputOutputAdapter) PrepareOutput(response []byte) (string, error)

PrepareOutput prepares the output for the Bedrock model based on the specified provider.

func (*BedrockInputOutputAdapter) PrepareStreamOutput added in v0.0.96

func (bioa *BedrockInputOutputAdapter) PrepareStreamOutput(response []byte) (string, error)

PrepareStreamOutput prepares the output for the Bedrock model based on the specified provider.

type BedrockMetaOptions added in v0.0.87

type BedrockMetaOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float32 `map:"temperature"`

	// TopP is the total probability mass of tokens to consider at each step.
	TopP float32 `map:"top_p,omitempty"`

	// MaxGenLen specify the maximum number of tokens to use in the generated response.
	MaxGenLen int `map:"max_gen_len"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

BedrockMetaOptions contains options for configuring the Bedrock model with the "meta" provider.

type BedrockMistralOptions added in v0.0.109

type BedrockMistralOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model id to use.
	ModelID string `map:"model_id,omitempty"`

	// Temperature controls the randomness of text generation. Higher values make it more random.
	Temperature float32 `map:"temperature"`

	// TopP is the total probability mass of tokens to consider at each step.
	TopP float32 `map:"top_p,omitempty"`

	// TopK determines how the model selects tokens for output.
	TopK int `map:"top_k"`

	// MaxTokens sets the maximum number of tokens in the generated text.
	MaxTokens int `json:"max_tokens,omitempty"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

type BedrockOptions added in v0.0.71

type BedrockOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model params to use.
	ModelParams map[string]any `map:"model_params,omitempty"`

	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

BedrockOptions contains options for configuring the Bedrock LLM model.

type BedrockRuntimeClient added in v0.0.71

type BedrockRuntimeClient interface {
	InvokeModel(ctx context.Context, params *bedrockruntime.InvokeModelInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.InvokeModelOutput, error)
	InvokeModelWithResponseStream(ctx context.Context, params *bedrockruntime.InvokeModelWithResponseStreamInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.InvokeModelWithResponseStreamOutput, error)
}

BedrockRuntimeClient is an interface for the Bedrock model runtime client.

type Cohere

type Cohere struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

Cohere represents the Cohere language model.

func NewCohere

func NewCohere(apiKey string, optFns ...func(o *CohereOptions)) (*Cohere, error)

NewCohere creates a new Cohere instance using the provided API key and optional configuration options. It internally creates a Cohere client using the provided API key and initializes the Cohere struct.

func NewCohereFromClient added in v0.0.31

func NewCohereFromClient(client CohereClient, optFns ...func(o *CohereOptions)) (*Cohere, error)

NewCohereFromClient creates a new Cohere instance using the provided Cohere client and optional configuration options.

func (*Cohere) Callbacks

func (l *Cohere) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*Cohere) Generate

func (l *Cohere) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*Cohere) InvocationParams added in v0.0.27

func (l *Cohere) InvocationParams() map[string]any

InvocationParams returns the parameters used in the llm model invocation.

func (*Cohere) Type

func (l *Cohere) Type() string

Type returns the type of the model.

func (*Cohere) Verbose

func (l *Cohere) Verbose() bool

Verbose returns the verbosity setting of the model.

type CohereClient added in v0.0.31

type CohereClient interface {
	Generate(ctx context.Context, request *cohere.GenerateRequest, opts ...core.RequestOption) (*cohere.Generation, error)
}

CohereClient is an interface for the Cohere client.

type CohereOptions

type CohereOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Model represents the name or identifier of the Cohere language model to use.
	Model string `map:"model,omitempty"`

	// NumGenerations denotes the maximum number of generations that will be returned.                   string
	NumGenerations int `map:"num_generations"`

	// MaxTokens denotes the number of tokens to predict per generation.
	MaxTokens int `map:"max_tokens"`

	// Temperature is a non-negative float that tunes the degree of randomness in generation.
	Temperature float64 `map:"temperature"`

	// K specifies the number of top most likely tokens to consider for generation at each step.
	K int `map:"k"`

	// P is a probability value between 0.0 and 1.0. It ensures that only the most likely tokens,
	// with a total probability mass of P, are considered for generation at each step.
	P float64 `map:"p"`

	// FrequencyPenalty is used to reduce repetitiveness of generated tokens. A higher value applies
	// a stronger penalty to previously present tokens, proportional to how many times they have
	// already appeared in the prompt or prior generation.
	FrequencyPenalty float64 `map:"frequency_penalty"`

	// PresencePenalty is used to reduce repetitiveness of generated tokens. It applies a penalty
	// equally to all tokens that have already appeared, regardless of their exact frequencies.
	PresencePenalty float64 `map:"presence_penalty"`

	// ReturnLikelihoods specifies whether and how the token likelihoods are returned with the response.
	// It can be set to "GENERATION", "ALL", or "NONE". If "GENERATION" is selected, the token likelihoods
	// will only be provided for generated text. If "ALL" is selected, the token likelihoods will be
	// provided for both the prompt and the generated text.
	ReturnLikelihoods string `map:"return_likelihoods,omitempty"`

	// MaxRetries represents the maximum number of retries to make when generating.
	MaxRetries uint `map:"max_retries,omitempty"`
}

CohereOptions contains options for configuring the Cohere LLM model.

type ContentHandler added in v0.0.41

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

ContentHandler handles content transformation for the LLM model.

func NewContentHandler added in v0.0.41

func NewContentHandler(contentType, accept string, transformer Transformer) *ContentHandler

NewContentHandler creates a new ContentHandler instance.

func (*ContentHandler) Accept added in v0.0.41

func (ch *ContentHandler) Accept() string

Accept returns the accept type of the ContentHandler.

func (*ContentHandler) ContentType added in v0.0.41

func (ch *ContentHandler) ContentType() string

ContentType returns the content type of the ContentHandler.

func (*ContentHandler) TransformInput added in v0.0.41

func (ch *ContentHandler) TransformInput(prompt string) ([]byte, error)

TransformInput transforms the input prompt using the ContentHandler's transformer.

func (*ContentHandler) TransformOutput added in v0.0.41

func (ch *ContentHandler) TransformOutput(output []byte) (string, error)

TransformOutput transforms the output from the LLM model using the ContentHandler's transformer.

type Fake added in v0.0.14

type Fake struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

Fake is a fake LLM model that generates text based on a provided response function.

func NewFake added in v0.0.14

func NewFake(fakeResultFunc FakeResultFunc, optFns ...func(o *FakeOptions)) *Fake

NewFake creates a new instance of the Fake LLM model with the provided response function and options.

func NewSimpleFake added in v0.0.58

func NewSimpleFake(resultText string, optFns ...func(o *FakeOptions)) *Fake

NewSimpleFake creates a simple instance of the Fake LLM model with a fixed response for all inputs.

func (*Fake) Callbacks added in v0.0.14

func (l *Fake) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*Fake) Generate added in v0.0.14

func (l *Fake) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*Fake) InvocationParams added in v0.0.27

func (l *Fake) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*Fake) Type added in v0.0.14

func (l *Fake) Type() string

Type returns the type of the model.

func (*Fake) Verbose added in v0.0.14

func (l *Fake) Verbose() bool

Verbose returns the verbosity setting of the model.

type FakeOptions added in v0.0.31

type FakeOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`
	LLMType                 string `map:"-"`
}

FakeOptions contains options for configuring the Fake LLM model.

type FakeResultFunc added in v0.0.58

type FakeResultFunc func(ctx context.Context, prompt string) (*schema.ModelResult, error)

FakeResultFunc is a function type for generating fake responses based on a prompt.

type GoogleGenAI added in v0.0.92

type GoogleGenAI struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

GoogleGenAI represents the GoogleGenAI Language Model.

func NewGoogleGenAI added in v0.0.92

func NewGoogleGenAI(client GoogleGenAIClient, optFns ...func(o *GoogleGenAIOptions)) (*GoogleGenAI, error)

NewGoogleGenAI creates a new instance of the GoogleGenAI Language Model.

func (*GoogleGenAI) Callbacks added in v0.0.92

func (l *GoogleGenAI) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*GoogleGenAI) Generate added in v0.0.92

func (l *GoogleGenAI) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*GoogleGenAI) InvocationParams added in v0.0.92

func (l *GoogleGenAI) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*GoogleGenAI) Type added in v0.0.92

func (l *GoogleGenAI) Type() string

Type returns the type of the model.

func (*GoogleGenAI) Verbose added in v0.0.92

func (l *GoogleGenAI) Verbose() bool

Verbose returns the verbosity setting of the model.

type GoogleGenAIClient added in v0.0.92

GoogleGenAIClient is an interface for the GoogleGenAI model client.

type GoogleGenAIOptions added in v0.0.92

type GoogleGenAIOptions struct {
	// CallbackOptions specify options for handling callbacks during text generation.
	*schema.CallbackOptions `map:"-"`
	// Tokenizer represents the tokenizer to be used with the LLM model.
	schema.Tokenizer `map:"-"`
	// ModelName is the name of the GoogleGenAI model to use.
	ModelName string `map:"model_name,omitempty"`
	// CandidateCount is the number of candidate generations to consider.
	CandidateCount int32 `map:"candidate_count,omitempty"`
	// MaxOutputTokens is the maximum number of tokens to generate in the output.
	MaxOutputTokens int32 `map:"max_output_tokens,omitempty"`
	// Temperature controls the randomness of the generation. Higher values make the output more random.
	Temperature float32 `map:"temperature,omitempty"`
	// TopP is the nucleus sampling parameter. It controls the cumulative probability of the most likely tokens to sample from.
	TopP float32 `map:"top_p,omitempty"`
	// TopK is the number of top tokens to consider for sampling.
	TopK int32 `map:"top_k,omitempty"`
	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

GoogleGenAIOptions contains options for the GoogleGenAI Language Model.

type HuggingFaceHub added in v0.0.14

type HuggingFaceHub struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

HuggingFaceHub represents the Hugging Face Hub LLM model.

func NewHuggingFaceHub added in v0.0.14

func NewHuggingFaceHub(apiToken string, optFns ...func(o *HuggingFaceHubOptions)) (*HuggingFaceHub, error)

NewHuggingFaceHub creates a new instance of the HuggingFaceHub model using the provided API token and options.

func NewHuggingFaceHubFromClient added in v0.0.31

func NewHuggingFaceHubFromClient(client HuggingFaceHubClient, optFns ...func(o *HuggingFaceHubOptions)) (*HuggingFaceHub, error)

NewHuggingFaceHubFromClient creates a new instance of the HuggingFaceHub model using the provided client and options.

func (*HuggingFaceHub) Callbacks added in v0.0.14

func (l *HuggingFaceHub) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*HuggingFaceHub) Generate added in v0.0.14

func (l *HuggingFaceHub) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*HuggingFaceHub) InvocationParams added in v0.0.27

func (l *HuggingFaceHub) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*HuggingFaceHub) Type added in v0.0.14

func (l *HuggingFaceHub) Type() string

Type returns the type of the model.

func (*HuggingFaceHub) Verbose added in v0.0.14

func (l *HuggingFaceHub) Verbose() bool

Verbose returns the verbosity setting of the model.

type HuggingFaceHubClient added in v0.0.31

type HuggingFaceHubClient interface {
	// TextGeneration performs text generation based on the provided request and returns the response.
	TextGeneration(ctx context.Context, req *huggingface.TextGenerationRequest) (huggingface.TextGenerationResponse, error)

	// Text2TextGeneration performs text-to-text generation based on the provided request and returns the response.
	Text2TextGeneration(ctx context.Context, req *huggingface.Text2TextGenerationRequest) (huggingface.Text2TextGenerationResponse, error)

	// Summarization performs text summarization based on the provided request and returns the response.
	Summarization(ctx context.Context, req *huggingface.SummarizationRequest) (huggingface.SummarizationResponse, error)

	// SetModel sets the model to be used for inference.
	SetModel(model string)
}

HuggingFaceHubClient represents the client for interacting with the Hugging Face Hub service.

type HuggingFaceHubOptions added in v0.0.14

type HuggingFaceHubOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`
	Model                   string `map:"model,omitempty"`
	Task                    string `map:"task,omitempty"`
	Options                 huggingface.Options
}

HuggingFaceHubOptions contains options for configuring the Hugging Face Hub LLM model.

type Ollama added in v0.0.90

type Ollama struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

Ollama is a struct representing the Ollama generative model.

func NewOllama added in v0.0.90

func NewOllama(client OllamaClient, optFns ...func(o *OllamaOptions)) (*Ollama, error)

NewOllama creates a new instance of the Ollama model with the provided client and options.

func (*Ollama) Callbacks added in v0.0.90

func (l *Ollama) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*Ollama) Generate added in v0.0.90

func (l *Ollama) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*Ollama) InvocationParams added in v0.0.90

func (l *Ollama) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*Ollama) Type added in v0.0.90

func (l *Ollama) Type() string

Type returns the type of the model.

func (*Ollama) Verbose added in v0.0.90

func (l *Ollama) Verbose() bool

Verbose returns the verbosity setting of the model.

type OllamaClient added in v0.0.90

type OllamaClient interface {
	// CreateGeneration produces a single request and response for the Ollama generative model.
	CreateGeneration(ctx context.Context, req *ollama.GenerationRequest) (*ollama.GenerationResponse, error)
	// CreateGenerationStream initiates a streaming request and returns a stream for the Ollama generative model.
	CreateGenerationStream(ctx context.Context, req *ollama.GenerationRequest) (*ollama.GenerationStream, error)
}

OllamaClient is an interface for the Ollama generative model client.

type OllamaOptions added in v0.0.90

type OllamaOptions struct {
	// CallbackOptions specify options for handling callbacks during text generation.
	*schema.CallbackOptions `map:"-"`
	// Tokenizer represents the tokenizer to be used with the LLM model.
	schema.Tokenizer `map:"-"`
	// ModelName is the name of the Gemini model to use.
	ModelName string `map:"model_name,omitempty"`
	// Temperature controls the randomness of the generation. Higher values make the output more random.
	Temperature float32 `map:"temperature,omitempty"`
	// MaxTokens is the maximum number of tokens to generate in the completion.
	MaxTokens int `map:"max_tokens,omitempty"`
	// TopP is the nucleus sampling parameter. It controls the cumulative probability of the most likely tokens to sample from.
	TopP float32 `map:"top_p,omitempty"`
	// TopK is the number of top tokens to consider for sampling.
	TopK int `map:"top_k,omitempty"`
	// PresencePenalty penalizes repeated tokens.
	PresencePenalty float32 `map:"presence_penalty,omitempty"`
	// FrequencyPenalty penalizes repeated tokens according to frequency.
	FrequencyPenalty float32 `map:"frequency_penalty,omitempty"`
	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
}

OllamaOptions contains options for the Ollama model.

type OpenAI

type OpenAI struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

OpenAI is an implementation of the LLM interface for the OpenAI language model.

func NewOpenAI

func NewOpenAI(apiKey string, optFns ...func(o *OpenAIOptions)) (*OpenAI, error)

NewOpenAI creates a new OpenAI instance with the provided API key and options.

func NewOpenAIFromClient added in v0.0.31

func NewOpenAIFromClient(client OpenAIClient, optFns ...func(o *OpenAIOptions)) (*OpenAI, error)

NewOpenAIFromClient creates a new OpenAI instance with the provided client and options.

func (*OpenAI) Callbacks

func (l *OpenAI) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*OpenAI) Generate

func (l *OpenAI) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*OpenAI) InvocationParams added in v0.0.27

func (l *OpenAI) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*OpenAI) Type

func (l *OpenAI) Type() string

Type returns the type of the model.

func (*OpenAI) Verbose

func (l *OpenAI) Verbose() bool

Verbose returns the verbosity setting of the model.

type OpenAIClient added in v0.0.31

type OpenAIClient interface {
	// CreateCompletionStream creates a streaming completion request with the provided completion request.
	// It returns a completion stream for receiving streamed completion responses from the OpenAI API.
	// The `CompletionStream` should be closed after use.
	CreateCompletionStream(ctx context.Context, request openai.CompletionRequest) (stream *openai.CompletionStream, err error)

	// CreateCompletion sends a completion request to the OpenAI API and returns the completion response.
	// It blocks until the response is received from the API.
	CreateCompletion(ctx context.Context, request openai.CompletionRequest) (response openai.CompletionResponse, err error)
}

OpenAIClient represents the interface for interacting with the OpenAI API.

type OpenAIOptions

type OpenAIOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`
	// ModelName is the name of the OpenAI language model to use.
	ModelName string `map:"model_name,omitempty"`
	// Temperature is the sampling temperature to use during text generation.
	Temperature float32 `map:"temperature,omitempty"`
	// MaxTokens is the maximum number of tokens to generate in the completion.
	MaxTokens int `map:"max_tokens,omitempty"`
	// TopP is the total probability mass of tokens to consider at each step.
	TopP float32 `map:"top_p,omitempty"`
	// PresencePenalty penalizes repeated tokens.
	PresencePenalty float32 `map:"presence_penalty,omitempty"`
	// FrequencyPenalty penalizes repeated tokens according to frequency.
	FrequencyPenalty float32 `map:"frequency_penalty,omitempty"`
	// N is the number of completions to generate for each prompt.
	N int `map:"n,omitempty"`
	// BestOf selects the best completion from multiple completions.
	BestOf int `map:"best_of,omitempty"`
	// LogitBias adjusts the probability of specific tokens being generated.
	LogitBias map[string]int `map:"logit_bias,omitempty"`
	// Stream indicates whether to stream the results or not.
	Stream bool `map:"stream,omitempty"`
	// MaxRetries represents the maximum number of retries to make when generating.
	MaxRetries uint `map:"max_retries,omitempty"`
	// BaseURL is the base URL of the OpenAI service.
	BaseURL string `map:"base_url,omitempty"`
	// OrgID is the organization ID for accessing the OpenAI service.
	OrgID string `map:"org_id,omitempty"`
}

OpenAIOptions contains options for configuring the OpenAI LLM model.

type ReturnLikelihood added in v0.0.79

type ReturnLikelihood string
const (
	ReturnLikelihoodGeneration ReturnLikelihood = "GENERATION"
	ReturnLikelihoodAll        ReturnLikelihood = "ALL"
	ReturnLikelihoodNone       ReturnLikelihood = "NONE"
)

type SagemakerEndpoint

type SagemakerEndpoint struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

SagemakerEndpoint represents an LLM model deployed on AWS SageMaker.

func NewSagemakerEndpoint

func NewSagemakerEndpoint(client SagemakerRuntimeClient, endpointName string, contenHandler *ContentHandler, optFns ...func(o *SagemakerEndpointOptions)) (*SagemakerEndpoint, error)

NewSagemakerEndpoint creates a new SagemakerEndpoint instance.

func (*SagemakerEndpoint) Callbacks

func (l *SagemakerEndpoint) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*SagemakerEndpoint) Generate

func (l *SagemakerEndpoint) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*SagemakerEndpoint) InvocationParams added in v0.0.27

func (l *SagemakerEndpoint) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*SagemakerEndpoint) Type

func (l *SagemakerEndpoint) Type() string

Type returns the type of the model.

func (*SagemakerEndpoint) Verbose

func (l *SagemakerEndpoint) Verbose() bool

Verbose returns the verbosity setting of the model.

type SagemakerEndpointOptions

type SagemakerEndpointOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`
}

SagemakerEndpointOptions contains options for configuring the SagemakerEndpoint.

type SagemakerRuntimeClient added in v0.0.34

type SagemakerRuntimeClient interface {
	// InvokeEndpoint invokes an endpoint in the SageMaker Runtime service with the specified input parameters.
	// It returns the output of the endpoint invocation or an error if the invocation fails.
	InvokeEndpoint(ctx context.Context, params *sagemakerruntime.InvokeEndpointInput, optFns ...func(*sagemakerruntime.Options)) (*sagemakerruntime.InvokeEndpointOutput, error)
}

SagemakerRuntimeClient is an interface that represents the client for interacting with the SageMaker Runtime service.

type Transformer

type Transformer interface {
	// Transforms the input to a format that model can accept
	// as the request Body. Should return bytes or seekable file
	// like object in the format specified in the content_type
	// request header.
	TransformInput(prompt string) ([]byte, error)

	// Transforms the output from the model to string that
	// the LLM class expects.
	TransformOutput(output []byte) (string, error)
}

Transformer defines the interface for transforming input and output data for the LLM model.

type VertexAI added in v0.0.31

type VertexAI struct {
	schema.Tokenizer
	// contains filtered or unexported fields
}

VertexAI represents the VertexAI language model.

func NewVertexAI added in v0.0.31

func NewVertexAI(client VertexAIClient, endpoint string, optFns ...func(o *VertexAIOptions)) (*VertexAI, error)

NewVertexAI creates a new VertexAI instance with the provided client and endpoint.

func (*VertexAI) Callbacks added in v0.0.31

func (l *VertexAI) Callbacks() []schema.Callback

Callbacks returns the registered callbacks of the model.

func (*VertexAI) Generate added in v0.0.31

func (l *VertexAI) Generate(ctx context.Context, prompt string, optFns ...func(o *schema.GenerateOptions)) (*schema.ModelResult, error)

Generate generates text based on the provided prompt and options.

func (*VertexAI) InvocationParams added in v0.0.31

func (l *VertexAI) InvocationParams() map[string]any

InvocationParams returns the parameters used in the model invocation.

func (*VertexAI) Type added in v0.0.31

func (l *VertexAI) Type() string

Type returns the type of the model.

func (*VertexAI) Verbose added in v0.0.31

func (l *VertexAI) Verbose() bool

Verbose returns the verbosity setting of the model.

type VertexAIClient added in v0.0.31

type VertexAIClient interface {
	// Predict sends a prediction request to the Vertex AI service.
	// It takes a context, predict request, and optional call options.
	// It returns the predict response or an error if the prediction fails.
	Predict(ctx context.Context, req *aiplatformpb.PredictRequest, opts ...gax.CallOption) (*aiplatformpb.PredictResponse, error)
}

VertexAIClient represents the interface for interacting with Vertex AI.

type VertexAIOptions added in v0.0.31

type VertexAIOptions struct {
	*schema.CallbackOptions `map:"-"`
	schema.Tokenizer        `map:"-"`

	// Temperature is the sampling temperature to use during text generation.
	Temperature float32 `map:"temperature"`

	// MaxOutputTokens determines the maximum amount of text output from one prompt.
	MaxOutputTokens int `map:"max_output_tokens"`

	// TopP is the total probability mass of tokens to consider at each step.
	TopP float32 `map:"top_p"`

	// TopK determines how the model selects tokens for output.
	TopK int `map:"top_k"`
}

VertexAIOptions contains options for configuring the VertexAI language model.

Jump to

Keyboard shortcuts

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