ai

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MPL-2.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ProviderAzure    = "azure"
	ProviderOpenAI   = "openai"
	ProviderBedrock  = "bedrock"
	ProviderSusanoo  = "susanoo"
	ProviderDeepseek = "deepseek"
	ProviderXAI      = "xai"
)
View Source
const (
	ChatMessageRoleUser      = "user"
	ChatMessageRoleAssistant = "assistant"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AzureRawRequestOptions added in v1.0.1

type AzureRawRequestOptions struct {
	UseJSON bool
}

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
	RawRequestParams map[string]any
}

type ChainParamsStep

type ChainParamsStep struct {
	Input       string
	Instruction string
	Options     any
}

type Config

type Config struct {
	// openai
	OpenAIAPIBase        string
	OpenAIAPIKey         string
	OpenAIModel          string
	OpenAIEmbeddingModel string

	// azure openai
	AzureOpenAIAPIKey         string
	AzureOpenAIEndpoint       string
	AzureOpenAIModel          string
	AzureOpenAIEmbeddingModel string

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

	// susanoo
	SusanooAPIBase string
	SusanooAPIKey  string

	Provider string

	Debug bool
}

type GeneralChatCompletionMessage

type GeneralChatCompletionMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

func (GeneralChatCompletionMessage) Pretty

type Instant

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

func New

func New(cfg Config) *Instant

func (*Instant) AzureOpenAIRawRequest added in v0.0.9

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

func (*Instant) BedrockClaudeRawRequestAWS added in v0.0.9

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

func (*Instant) CallInChain

func (s *Instant) CallInChain(ctx context.Context, params ChainParams) (*Result, 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) (*Result, error)

func (*Instant) OneTimeRequestWithParams added in v1.0.0

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

func (*Instant) OpenAIRawRequest added in v0.0.9

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

func (*Instant) RawRequest

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

func (*Instant) RawRequestWithParams added in v0.0.9

func (s *Instant) RawRequestWithParams(ctx context.Context, messages []GeneralChatCompletionMessage, params map[string]any) (*Result, error)

func (*Instant) SusanooCreateTask added in v0.0.9

func (s *Instant) SusanooCreateTask(ctx context.Context, task *SusanooTaskRequest) (string, error)

func (*Instant) SusanooFetchTaskResult added in v0.0.9

func (s *Instant) SusanooFetchTaskResult(ctx context.Context, traceID string) (*SusanooTaskResultResponse, error)

func (*Instant) SusanooRawRequest added in v0.0.9

func (s *Instant) SusanooRawRequest(ctx context.Context, messages []GeneralChatCompletionMessage, params map[string]any) (*SusanooTaskResultResponse, error)

type OpenAIRawRequestOptions added in v1.0.1

type OpenAIRawRequestOptions struct {
	UseJSON bool
}

type Result added in v1.0.0

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

type SusanoParams added in v1.0.0

type SusanoParams struct {
	Format     string                 `json:"format"`
	Search     SusanoParamsSearch     `json:"search"`
	Conditions SusanoParamsConditions `json:"conditions"`
}

func (*SusanoParams) ToMap added in v1.0.0

func (p *SusanoParams) ToMap() map[string]any

type SusanoParamsConditions added in v1.0.0

type SusanoParamsConditions struct {
	PreferredProvider string `json:"preferred_provider"`
	PreferredModel    string `json:"preferred_model"`
}

type SusanoParamsSearch added in v1.0.2

type SusanoParamsSearch struct {
	Enabled bool `json:"enabled"`
	Limit   int  `json:"limit"`
}

type SusanooTaskRequest added in v0.0.9

type SusanooTaskRequest struct {
	Messages []GeneralChatCompletionMessage `json:"messages"`
	Params   map[string]any                 `json:"params"`
}

type SusanooTaskResponse added in v0.0.9

type SusanooTaskResponse struct {
	Data struct {
		Code    int    `json:"code"`
		TraceID string `json:"trace_id"`
	} `json:"data"`
	Ts int `json:"ts"`
}

type SusanooTaskResultResponse added in v0.0.9

type SusanooTaskResultResponse struct {
	Data struct {
		ID           int            `json:"id"`
		ProxyID      int            `json:"proxy_id"`
		Result       map[string]any `json:"result"`
		Status       int            `json:"status"`
		TraceID      string         `json:"trace_id"`
		ScheduledAt  string         `json:"scheduled_at"`
		CreatedAt    string         `json:"created_at"`
		UpdatedAt    string         `json:"updated_at"`
		PendingCount int            `json:"pending_count"`
	} `json:"data"`
	Ts int `json:"ts"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳