ai

package
v0.0.0-...-0d8279c Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StructuredResponseCodeTypeJSON is the code type for JSON responses.
	StructuredResponseCodeTypeJSON = "json"
	// StructuredResponseCodeTypeYAML is the code type for YAML responses.
	StructuredResponseCodeTypeYAML = "yaml"
)
View Source
const GoogleVertexAIClientName = "googlevertexai"
View Source
const GroqAIClientName = "groq"
View Source
const OpenAIClientName = "openai"

Variables

View Source
var (
	Clients = map[string]IAI{
		OpenAIClientName:         &OpenAIClient{},
		GroqAIClientName:         &GroqAIClient{},
		GoogleVertexAIClientName: &GoogleVertexAIClient{},
	}

	Backends = []string{
		OpenAIClientName,
		GroqAIClientName,
		GoogleVertexAIClientName,
	}
)

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Providers       []Provider `mapstructure:"providers" yaml:"providers" goconf:"providers"`
	DefaultProvider string     `mapstructure:"default_provider" yaml:"default_provider" goconf:"default_provider"`
}

type GoogleVertexAIClient

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

func (*GoogleVertexAIClient) Configure

func (g *GoogleVertexAIClient) Configure(config IAIConfig) error

func (*GoogleVertexAIClient) GetCompletion

func (g *GoogleVertexAIClient) GetCompletion(ctx context.Context, messages []llms.MessageContent, callOptions ...llms.CallOption) (*llms.ContentResponse, error)

func (*GoogleVertexAIClient) GetCompletionFromSinglePrompt

func (g *GoogleVertexAIClient) GetCompletionFromSinglePrompt(ctx context.Context, prompt string) (string, error)

func (*GoogleVertexAIClient) GetName

func (g *GoogleVertexAIClient) GetName() string

type GroqAIClient

type GroqAIClient struct {
	OpenAIClient
}

func (*GroqAIClient) GetName

func (a *GroqAIClient) GetName() string

type IAI

type IAI interface {
	// Configure sets up client for given configuration
	Configure(config IAIConfig) error

	// GetCompletionFromSinglePrompt generates text based on prompt.
	GetCompletionFromSinglePrompt(ctx context.Context, prompt string) (string, error)

	// GetCompletion generates text based on complex prompt.
	GetCompletion(ctx context.Context, messages []llms.MessageContent, callOptions ...llms.CallOption) (*llms.ContentResponse, error)

	// GetName returns name of the backend/client.
	GetName() string
}

IAI is an interface all clients (representing backends) share.

func NewClient

func NewClient(provider string) IAI

type IAIConfig

type IAIConfig interface {
	GetPassword() string
	GetModel() string
	GetEmbeddingModel() string
	GetBaseURL() string
	GetProxyEndpoint() string
	GetEndpointName() string
	GetEngine() string
	GetTemperature() float32
	GetProviderRegion() string
	GetTopP() float32
	GetTopK() int32
	GetMaxTokens() int
	GetProviderId() string
	GetCompartmentId() string
	GetOrganizationId() string
}

type OpenAIClient

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

func (*OpenAIClient) Configure

func (c *OpenAIClient) Configure(config IAIConfig) error

func (*OpenAIClient) GetCompletion

func (c *OpenAIClient) GetCompletion(ctx context.Context, messages []llms.MessageContent, callOptions ...llms.CallOption) (*llms.ContentResponse, error)

func (*OpenAIClient) GetCompletionFromSinglePrompt

func (c *OpenAIClient) GetCompletionFromSinglePrompt(ctx context.Context, prompt string) (string, error)

func (*OpenAIClient) GetName

func (c *OpenAIClient) GetName() string

type ParseError

type ParseError struct {
	Text   string
	Reason string
}

ParseError is the error type returned by output parsers.

func (ParseError) Error

func (e ParseError) Error() string

type Prompt

type Prompt struct {
	System string
	User   string
}

type PromptBuilder

type PromptBuilder struct {
	PromptName string
	// contains filtered or unexported fields
}

func NewPromptBuilder

func NewPromptBuilder(promptName string, vars any) *PromptBuilder

func (*PromptBuilder) BuildPrompt

func (p *PromptBuilder) BuildPrompt() ([]llms.MessageContent, error)

func (*PromptBuilder) GetPromptContent

func (p *PromptBuilder) GetPromptContent() (string, error)

func (*PromptBuilder) RenderPromptContent

func (p *PromptBuilder) RenderPromptContent() (string, error)

type Provider

type Provider struct {
	Name           string  `mapstructure:"name" yaml:"name,omitempty" goconf:"name"`
	Model          string  `mapstructure:"model" yaml:"model,omitempty" goconf:"model"`
	EmbeddingModel string  `mapstructure:"embedding_model" yaml:"embedding_model,omitempty" goconf:"embedding_model"`
	Password       string  `mapstructure:"password" yaml:"password,omitempty" goconf:"password"`
	BaseURL        string  `mapstructure:"base_url" yaml:"base_url,omitempty" goconf:"base_url"`
	ProxyEndpoint  string  `mapstructure:"proxy_endpoint" yaml:"proxy_endpoint,omitempty" goconf:"proxy_endpoint"`
	ProxyPort      string  `mapstructure:"proxy_port" yaml:"proxy_port,omitempty" goconf:"proxy_port"`
	EndpointName   string  `mapstructure:"endpoint_name" yaml:"endpoint_name,omitempty" goconf:"endpoint_name"`
	Engine         string  `mapstructure:"engine" yaml:"engine,omitempty" goconf:"engine"`
	Temperature    float32 `mapstructure:"temperature" yaml:"temperature,omitempty" goconf:"temperature"`
	ProviderRegion string  `mapstructure:"provider_region" yaml:"provider_region,omitempty" goconf:"provider_region"`
	ProviderId     string  `mapstructure:"provider_id" yaml:"provider_id,omitempty" goconf:"provider_id"`
	CompartmentId  string  `mapstructure:"compartment_id" yaml:"compartment_id,omitempty" goconf:"compartment_id"`
	TopP           float32 `mapstructure:"topp" yaml:"topp,omitempty" goconf:"topp"`
	TopK           int32   `mapstructure:"topk" yaml:"topk,omitempty" goconf:"topk"`
	MaxTokens      int     `mapstructure:"max_tokens" yaml:"max_tokens,omitempty" goconf:"max_tokens"`
	OrganizationId string  `mapstructure:"organization_id" yaml:"organization_id,omitempty" goconf:"organization_id"`
}

func (*Provider) GetBaseURL

func (p *Provider) GetBaseURL() string

func (*Provider) GetCompartmentId

func (p *Provider) GetCompartmentId() string

func (*Provider) GetEmbeddingModel

func (p *Provider) GetEmbeddingModel() string

func (*Provider) GetEndpointName

func (p *Provider) GetEndpointName() string

func (*Provider) GetEngine

func (p *Provider) GetEngine() string

func (*Provider) GetMaxTokens

func (p *Provider) GetMaxTokens() int

func (*Provider) GetModel

func (p *Provider) GetModel() string

func (*Provider) GetOrganizationId

func (p *Provider) GetOrganizationId() string

func (*Provider) GetPassword

func (p *Provider) GetPassword() string

func (*Provider) GetProviderId

func (p *Provider) GetProviderId() string

func (*Provider) GetProviderRegion

func (p *Provider) GetProviderRegion() string

func (*Provider) GetProxyEndpoint

func (p *Provider) GetProxyEndpoint() string

func (*Provider) GetTemperature

func (p *Provider) GetTemperature() float32

func (*Provider) GetTopK

func (p *Provider) GetTopK() int32

func (*Provider) GetTopP

func (p *Provider) GetTopP() float32

type StructuredResponse

type StructuredResponse struct {
	Text            string
	CodeType        string
	ResponseSchemas any
}

func NewStructuredResponse

func NewStructuredResponse(text string, codeType string, responseSchemas any) StructuredResponse

func (*StructuredResponse) Parse

func (s *StructuredResponse) Parse() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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