ai_generator

package
v1.0.66 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleNewAiGenerator

func ExampleNewAiGenerator()

Types

type AiAttachment

type AiAttachment struct {
	MimeType string
	Data     []byte
}

type AiGenerator

type AiGenerator interface {
	Generate(prompt string, attachment *AiAttachment, histories []AiMessage) (*AiMessage, error)
	SetApiKey(apiKey string)
	SetSystemInstruction(instruction string)
	SetModel(model string)
	SetContentConfig(config *ContentConfig)
	SetHost(host string)
}

func NewAiGenerator

func NewAiGenerator(factory GeneratorFactory, config GeneratorConfig) (AiGenerator, error)

type AiGeneratorService added in v1.0.61

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

func NewAiGeneratorService added in v1.0.61

func NewAiGeneratorService(ctx *context.Context, db *gorm.DB, skipMigration bool) *AiGeneratorService

func (*AiGeneratorService) CreateAgent added in v1.0.61

func (s *AiGeneratorService) CreateAgent(agent *models.AiAgentModel) error

func (*AiGeneratorService) CreateHistory added in v1.0.61

func (s *AiGeneratorService) CreateHistory(history *models.AiAgentHistory) error

func (*AiGeneratorService) DeleteAgent added in v1.0.61

func (s *AiGeneratorService) DeleteAgent(id string) error

func (*AiGeneratorService) DeleteHistory added in v1.0.61

func (s *AiGeneratorService) DeleteHistory(id string) error

func (*AiGeneratorService) GetAgent added in v1.0.61

func (s *AiGeneratorService) GetAgent(id string) (*models.AiAgentModel, error)

func (*AiGeneratorService) GetAgents added in v1.0.61

func (s *AiGeneratorService) GetAgents(request *http.Request) (paginate.Page, error)

func (*AiGeneratorService) GetGeneratorFromID added in v1.0.61

func (s *AiGeneratorService) GetGeneratorFromID(id string) (AiGenerator, error)

func (*AiGeneratorService) GetHistories added in v1.0.61

func (s *AiGeneratorService) GetHistories(id, companyID *string, sessionCode *string, isModel *bool, limit *int) ([]models.AiAgentHistory, error)

func (*AiGeneratorService) SetConfig added in v1.0.61

func (s *AiGeneratorService) SetConfig(config GeneratorConfig)

func (*AiGeneratorService) SetFactory added in v1.0.61

func (s *AiGeneratorService) SetFactory(factory GeneratorFactory)

func (*AiGeneratorService) UpdateAgent added in v1.0.61

func (s *AiGeneratorService) UpdateAgent(agent *models.AiAgentModel) error

func (*AiGeneratorService) UpdateHistory added in v1.0.63

func (s *AiGeneratorService) UpdateHistory(history *models.AiAgentHistory) error

type AiMessage

type AiMessage struct {
	Role       string // Contoh: "user", "model", "system"
	Content    string
	Attachment *AiAttachment
}

type ContentConfig

type ContentConfig struct {
	Temperature      *float32 `json:"temperature,omitempty"`
	TopP             *float32 `json:"topP,omitempty"`
	TopK             *float32 `json:"topK,omitempty"`
	CandidateCount   int32    `json:"candidateCount,omitempty"`
	MaxOutputTokens  int32    `json:"maxOutputTokens,omitempty"`
	StopSequences    []string `json:"stopSequences,omitempty"`
	ResponseLogprobs bool     `json:"responseLogprobs,omitempty"`
	Logprobs         *int32   `json:"logprobs,omitempty"`
	PresencePenalty  *float32 `json:"presencePenalty,omitempty"`
	FrequencyPenalty *float32 `json:"frequencyPenalty,omitempty"`
	Seed             *int32   `json:"seed,omitempty"`
	ResponseMIMEType string   `json:"responseMimeType,omitempty"`
}

type DeepSeekService

type DeepSeekService struct {
	ApiKey string
	// contains filtered or unexported fields
}

func NewDeepSeekService

func NewDeepSeekService(ctx *context.Context, apiKey string) *DeepSeekService

func (*DeepSeekService) Generate

func (g *DeepSeekService) Generate(prompt string, attachment *AiAttachment, histories []AiMessage) (*AiMessage, error)

func (*DeepSeekService) SetApiKey

func (g *DeepSeekService) SetApiKey(apiKey string)

func (*DeepSeekService) SetContentConfig

func (g *DeepSeekService) SetContentConfig(config *ContentConfig)

func (*DeepSeekService) SetHost

func (g *DeepSeekService) SetHost(host string)

func (*DeepSeekService) SetModel

func (g *DeepSeekService) SetModel(model string)

func (*DeepSeekService) SetSystemInstruction

func (g *DeepSeekService) SetSystemInstruction(instruction string)

type GeminiV2SService

type GeminiV2SService struct {
	ApiKey string
	// contains filtered or unexported fields
}

func NewGeminiV2Service

func NewGeminiV2Service(ctx *context.Context, apiKey string) *GeminiV2SService

func (*GeminiV2SService) Generate

func (g *GeminiV2SService) Generate(prompt string, attachment *AiAttachment, histories []AiMessage) (*AiMessage, error)

func (*GeminiV2SService) SetApiKey

func (g *GeminiV2SService) SetApiKey(apiKey string)

func (*GeminiV2SService) SetContentConfig

func (g *GeminiV2SService) SetContentConfig(config *ContentConfig)

func (*GeminiV2SService) SetHost

func (g *GeminiV2SService) SetHost(host string)

func (*GeminiV2SService) SetModel

func (g *GeminiV2SService) SetModel(model string)

func (*GeminiV2SService) SetSystemInstruction

func (g *GeminiV2SService) SetSystemInstruction(instruction string)

type GeneratorConfig

type GeneratorConfig struct {
	Ctx               *context.Context
	APIKey            string
	SystemInstruction string
	Model             string
	Host              string
}

type GeneratorFactory

type GeneratorFactory func(config GeneratorConfig) (AiGenerator, error)

type Message

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

type OllamaService

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

func NewOllamaService

func NewOllamaService(ctx *context.Context, model string) *OllamaService

func (*OllamaService) Generate

func (g *OllamaService) Generate(prompt string, attachment *AiAttachment, histories []AiMessage) (*AiMessage, error)

func (*OllamaService) SetApiKey

func (g *OllamaService) SetApiKey(apiKey string)

func (*OllamaService) SetContentConfig

func (g *OllamaService) SetContentConfig(config *ContentConfig)

func (*OllamaService) SetHost

func (g *OllamaService) SetHost(host string)

func (*OllamaService) SetModel

func (g *OllamaService) SetModel(model string)

func (*OllamaService) SetSteam

func (g *OllamaService) SetSteam(stream bool)

func (*OllamaService) SetSystemInstruction

func (g *OllamaService) SetSystemInstruction(instruction string)

type OpenAiService added in v1.0.60

type OpenAiService struct {
	ApiKey string
	// contains filtered or unexported fields
}

func NewOpenAiService added in v1.0.60

func NewOpenAiService(ctx *context.Context, apiKey string) *OpenAiService

func (*OpenAiService) Generate added in v1.0.60

func (g *OpenAiService) Generate(prompt string, attachment *AiAttachment, histories []AiMessage) (*AiMessage, error)

func (*OpenAiService) SetApiKey added in v1.0.60

func (g *OpenAiService) SetApiKey(apiKey string)

func (*OpenAiService) SetContentConfig added in v1.0.60

func (g *OpenAiService) SetContentConfig(config *ContentConfig)

func (*OpenAiService) SetHost added in v1.0.60

func (g *OpenAiService) SetHost(host string)

func (*OpenAiService) SetModel added in v1.0.60

func (g *OpenAiService) SetModel(model string)

func (*OpenAiService) SetSystemInstruction added in v1.0.60

func (g *OpenAiService) SetSystemInstruction(instruction string)

type OtherService

type OtherService struct {
	ApiKey string
	// contains filtered or unexported fields
}

func NewOtherService

func NewOtherService(ctx *context.Context, apiKey string) *OtherService

func (*OtherService) Generate

func (g *OtherService) Generate(prompt string, attachment *AiAttachment, histories []AiMessage) (*AiMessage, error)

func (*OtherService) SetApiKey

func (g *OtherService) SetApiKey(apiKey string)

func (*OtherService) SetContentConfig

func (g *OtherService) SetContentConfig(config *ContentConfig)

func (*OtherService) SetHost

func (g *OtherService) SetHost(host string)

func (*OtherService) SetModel

func (g *OtherService) SetModel(model string)

func (*OtherService) SetSystemInstruction

func (g *OtherService) SetSystemInstruction(instruction string)

type Request

type Request struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	Stream   bool      `json:"stream"`
	Format   string    `json:"format"`
	Options  struct {
		NumCtx int `json:"num_ctx"`
	}
}

type Response

type Response struct {
	Model              string    `json:"model"`
	CreatedAt          time.Time `json:"created_at"`
	Message            Message   `json:"message"`
	Done               bool      `json:"done"`
	TotalDuration      int64     `json:"total_duration"`
	LoadDuration       int       `json:"load_duration"`
	PromptEvalCount    int       `json:"prompt_eval_count"`
	PromptEvalDuration int       `json:"prompt_eval_duration"`
	EvalCount          int       `json:"eval_count"`
	EvalDuration       int64     `json:"eval_duration"`
}

Jump to

Keyboard shortcuts

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