horus

package module
v0.0.0-...-b40d7d9 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: GPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	PERMISSIONS_NONE       = 0b00000000 // Null value - nothing is enabled
	PERMISSIONS_GPT        = 0b00000001 // GPT functionality is enabled
	PERMISSIONS_PRVMODULES = 0b00000010 // Only "private" custom modules are enabled
	PERMISSIONS_PUBMODULES = 0b00000100 // Only "public" custom modules are enabled

	PERMISSIONS_ALLMODULES = 0b00000110 // All custom modules are enabled
	PERMISSIONS_ALL        = 0b11111111 // All custom modules and GPT functionality is enabled
)
View Source
const (
	OPENAI_MODEL     = openai.GPT3Dot5Turbo // What OpenAI model is being used
	OPENAI_ROLE      = openai.ChatMessageRoleSystem
	OPENAI_MAXTOKENS = 500                                                 // What is the maximum amount of tokens that can be sent to the model? (Tokens = Words / 0.75)
	OPENAI_SYSPROMPT = `You are a helpful personal assistant named Horus.` // System Prompt for the OpenAI model
)

Variables

This section is empty.

Functions

func InitSQL

func InitSQL(dsn string) error

InitSQL initializes the SQL database the structs are connected to

Types

type Bot

type Bot struct {
	gorm.Model

	Name          string         // The name of the bot
	Permissions   byte           // A byte representation of allowed permissions
	Memory        Memory         // Static memory associated with a bot
	Conversations []Conversation // A list of conversations with the user
	// contains filtered or unexported fields
}

Bot represents an implementation of Horus. It contains multiple conversations with a given user as well as defining characteristics

func GetAllBots

func GetAllBots() ([]Bot, error)

GetAllBots gets a list of all bots in the SQL database

func GetBotByName

func GetBotByName(name string) (*Bot, error)

GetBotByName gets a singular bot by name from the SQL database

func NewBot

func NewBot(name string, permissions byte) (*Bot, error)

NewBot creates a new Bot object

func (*Bot) AddConversation

func (b *Bot) AddConversation(key string) error

AddConversation adds a new conversation to the bot

func (*Bot) AddDefinitions

func (b *Bot) AddDefinitions(name string, definitions *map[string]openai.FunctionDefinition)

Adds definitions to the bot's function definitions

func (*Bot) AddHandlers

func (b *Bot) AddHandlers(handlers ...func(function string, input *types.Input) any)

Adds handlers to the bot's handlers

func (*Bot) AddMessage

func (b *Bot) AddMessage(key string, role string, name string, content string) error

Add a message to a conversation

func (*Bot) AddQueuedFunctions

func (b *Bot) AddQueuedFunctions(funcs ...func(bot *Bot, input *types.Input) *types.Output)

Add a list of functions to the function queue

func (*Bot) DeleteConversation

func (b *Bot) DeleteConversation(key string) error

DeleteConversation delets a conversation from the bot

func (*Bot) EditVariable

func (b *Bot) EditVariable(key string, value any)

Writes a value to the variables map

func (*Bot) GetVariable

func (b *Bot) GetVariable(key string) any

Returns a value from the variables map

func (*Bot) IsConversation

func (b *Bot) IsConversation(key string) bool

IsConversation returns true if the conversation exists

func (*Bot) SendMessage

func (b *Bot) SendMessage(key string, input *types.Input) (*types.Output, error)

SendMessage sends a message to the bot in a given conversation

func (*Bot) Setup

func (b *Bot) Setup(client *openai.Client)

Setup sets up the bot with an openai Client

type Conversation

type Conversation struct {
	gorm.Model

	BotID    uint      // The foreign key to relate the conversation to a bot
	Name     string    // A unique identifying key for the converesation
	Messages []Message // A list of messages in the conversation
	// contains filtered or unexported fields
}

Conversation represents a conversation between Horus and the user

func (*Conversation) AddFunctionCall

func (c *Conversation) AddFunctionCall(message *openai.ChatCompletionMessage) error

Add function call to the conversation

func (*Conversation) AddMessage

func (c *Conversation) AddMessage(role string, name string, content string) error

Add a message to the conversation without sending it

func (*Conversation) Delete

func (c *Conversation) Delete() error

Delete a conversation and all associated messages

func (*Conversation) SendFunctionCalls

func (c *Conversation) SendFunctionCalls() (*openai.ChatCompletionResponse, error)

SendFunctionCalls gets a new response with added function calls

func (*Conversation) SendMessage

func (c *Conversation) SendMessage(role string, name string, content string) (*openai.ChatCompletionResponse, error)

SendMessage sends a message to OpenAI

type Memory

type Memory struct {
	gorm.Model

	BotID           uint // The foreign key to relate the Memory struct to the Bot
	Timezone        string
	City            string
	TemperatureUnit string
}

Memory represents a static memory bank used by a Bot. Values in this struct get stored to SQL and are saved past reboot

type Message

type Message struct {
	gorm.Model

	ConversationID uint   // The conversation this message is related to
	Idx            uint   // The index of the message in the conversation
	Role           string // The role of the entity speaking the message
	Name           string // The message's type
	Content        string // The content of the message

	// Tools related to the message call
	ToolCallID string
	ToolCalls  []ToolCall

	// The openAI message this message is representing
	ChatCompletionMessage *openai.ChatCompletionMessage `gorm:"-"`
}

Message represents a sent message in a conversation

func (*Message) Delete

func (m *Message) Delete() error

Delete deletes the message from the SQL database

type ToolCall

type ToolCall struct {
	gorm.Model

	ID            string
	Type          string
	CallName      string
	CallArguments string
	MessageID     uint
}

TooCall is a helper struct to encode tool call information into messages

Directories

Path Synopsis
definitions.go contains all OpenAI function declarations
definitions.go contains all OpenAI function declarations

Jump to

Keyboard shortcuts

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