ai

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MPL-2.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ProviderAzure   = "azure"
	ProviderOpenAI  = "openai"
	ProviderBedrock = "bedrock"
)
View Source
const (
	ChatMessageRoleUser      = "user"
	ChatMessageRoleAssistant = "assistant"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BedRockClaudeChatMessage added in v0.0.5

type BedRockClaudeChatMessage struct {
	Role    string                        `json:"role"`
	Content []BedRockClaudeMessageContent `json:"content"`
}

type BedRockClaudeMessageContent added in v0.0.5

type BedRockClaudeMessageContent struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

type BedrockClaudeResponse added in v0.0.5

type BedrockClaudeResponse struct {
	ID           string                        `json:"id"`
	Type         string                        `json:"type"`
	Role         string                        `json:"role"`
	Model        string                        `json:"model"`
	Content      []BedRockClaudeMessageContent `json:"content"`
	StopReason   string                        `json:"stop_reason"`
	StopSequence interface{}                   `json:"stop_sequence"`
	Usage        map[string]int                `json:"usage"`
}

type ChainParams

type ChainParams struct {
	Format string
	Steps  []ChainParamsStep
}

type ChainParamsStep

type ChainParamsStep struct {
	Input       string
	Instruction string
	Options     any
}

type ChainResult

type ChainResult struct {
	Text string
	Json map[string]any
}

type Config

type Config struct {
	// openai
	OpenAIApiKey         string
	OpenAIGptModel       string
	OpenAIEmbeddingModel string

	// azure openai
	AzureOpenAIApiKey                string
	AzureOpenAIEndpoint              string
	AzureOpenAIGptDeploymentID       string
	AzureOpenAIEmbeddingDeploymentID string

	// aws bedrock
	AwsKey                      string
	AwsSecret                   string
	AwsBedrockModelArn          string
	AwsBedrockEmbeddingModelArn string

	Provider string

	Debug bool
}

type GeneralChatCompletionMessage

type GeneralChatCompletionMessage struct {
	Role    string
	Content string
}

func (GeneralChatCompletionMessage) Pretty

type Instant

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

func New

func New(cfg Config) *Instant

func (*Instant) CallInChain

func (s *Instant) CallInChain(ctx context.Context, params ChainParams) (*ChainResult, error)

func (*Instant) CreateEmbeddingAzureOpenAI

func (s *Instant) CreateEmbeddingAzureOpenAI(ctx context.Context, input []string) ([]float32, error)

func (*Instant) CreateEmbeddingBedrock added in v0.0.7

func (s *Instant) CreateEmbeddingBedrock(ctx context.Context, input []string) ([]float32, error)

func (*Instant) CreateEmbeddingOpenAI added in v0.0.7

func (s *Instant) CreateEmbeddingOpenAI(ctx context.Context, input []string) ([]float32, error)

func (*Instant) GetEmbeddings

func (s *Instant) GetEmbeddings(ctx context.Context, input []string) ([]float32, error)

func (*Instant) GrabJsonOutput

func (s *Instant) GrabJsonOutput(ctx context.Context, input string, outputKeys ...string) (map[string]any, error)

func (*Instant) GrabJsonOutputFromMd added in v0.0.6

func (s *Instant) GrabJsonOutputFromMd(ctx context.Context, input string, ptrOutput interface{}) error

func (*Instant) MultipleSteps

func (s *Instant) MultipleSteps(ctx context.Context, params ChainParams) (*ChainResult, error)

func (*Instant) OneTimeRequest

func (s *Instant) OneTimeRequest(ctx context.Context, content string) (string, error)

func (*Instant) OneTimeRequestJson

func (s *Instant) OneTimeRequestJson(ctx context.Context, content string) (map[string]any, error)

func (*Instant) RawRequest

func (s *Instant) RawRequest(ctx context.Context, messages []GeneralChatCompletionMessage) (string, error)

func (*Instant) RawRequestAWSBedrockClaude added in v0.0.5

func (s *Instant) RawRequestAWSBedrockClaude(ctx context.Context, messages []BedRockClaudeChatMessage) (string, error)

func (*Instant) RawRequestAzureOpenAI

func (s *Instant) RawRequestAzureOpenAI(ctx context.Context, messages []azopenai.ChatRequestMessageClassification) (string, error)

func (*Instant) RawRequestOpenAI

func (s *Instant) RawRequestOpenAI(ctx context.Context, messages []openai.ChatCompletionMessage) (string, error)

func (*Instant) TwoSteps

func (s *Instant) TwoSteps(ctx context.Context, outputFormat string, input, inst string) (*ChainResult, error)

Jump to

Keyboard shortcuts

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