Documentation ¶
Index ¶
- func TokenCalucate(msgs []ChatCompletionMessage) int
- type ChatCompletionMessage
- type Conversation
- type Gpt3p5
- func (b *Gpt3p5) AddConversation(c *Conversation) error
- func (b *Gpt3p5) AddMessages(msgs []ChatCompletionMessage) error
- func (b *Gpt3p5) AddSystemRole(sr *SystemRole) error
- func (b *Gpt3p5) GetConversation(id uint) (Conversation, error)
- func (b *Gpt3p5) GetMessage(id uint) (ChatCompletionMessage, error)
- func (b *Gpt3p5) GetSystemRole(id uint) (SystemRole, error)
- func (b *Gpt3p5) ListConversations(query interface{}, args ...interface{}) ([]Conversation, error)
- func (b *Gpt3p5) ListSystemRoles(query interface{}, args ...interface{}) ([]SystemRole, error)
- func (b *Gpt3p5) Send(conversationID uint, msg string) (resp ChatCompletionMessage, err error)
- type GptBackend
- type SystemRole
- type SystemRoleDAO
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TokenCalucate ¶
func TokenCalucate(msgs []ChatCompletionMessage) int
Types ¶
type ChatCompletionMessage ¶
type ChatCompletionMessage struct { gorm.Model ConversationID uint `gorm:"index" json:"conversation_id"` Role string `json:"role"` Content string `json:"content"` PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` }
func (ChatCompletionMessage) TableName ¶
func (ChatCompletionMessage) TableName() string
type Conversation ¶
type Conversation struct { gorm.Model Name string `json:"name"` SystemRoleID uint `json:"system_role_id,omitempty"` Messages []ChatCompletionMessage `json:"messages,omitempty"` }
func (Conversation) TableName ¶
func (Conversation) TableName() string
conversation table name conversation
type Gpt3p5 ¶
type Gpt3p5 struct {
// contains filtered or unexported fields
}
Gpt3p5 implement the GptBackend
func (*Gpt3p5) AddConversation ¶
func (b *Gpt3p5) AddConversation(c *Conversation) error
AddConversation add a new conversation to db
func (*Gpt3p5) AddMessages ¶
func (b *Gpt3p5) AddMessages(msgs []ChatCompletionMessage) error
func (*Gpt3p5) AddSystemRole ¶
func (b *Gpt3p5) AddSystemRole(sr *SystemRole) error
AddSystemRole adds a system role
func (*Gpt3p5) GetConversation ¶
func (b *Gpt3p5) GetConversation(id uint) (Conversation, error)
GetConversation returns conversation by id and it's all messages
func (*Gpt3p5) GetMessage ¶
func (b *Gpt3p5) GetMessage(id uint) (ChatCompletionMessage, error)
GetMessage returns message by id
func (*Gpt3p5) GetSystemRole ¶
func (b *Gpt3p5) GetSystemRole(id uint) (SystemRole, error)
GetSystemRole returns system role by id
func (*Gpt3p5) ListConversations ¶
func (b *Gpt3p5) ListConversations(query interface{}, args ...interface{}) ([]Conversation, error)
ListConversations returns conversation filtered by where condition
func (*Gpt3p5) ListSystemRoles ¶
func (b *Gpt3p5) ListSystemRoles(query interface{}, args ...interface{}) ([]SystemRole, error)
ListSystemRoles returns system roles filtered by where condition
type GptBackend ¶
type GptBackend interface { SystemRoleDAO Send(conversationID uint, msg string) (ChatCompletionMessage, error) GetConversation(id uint) (Conversation, error) ListConversations(query interface{}, args ...interface{}) ([]Conversation, error) GetMessage(id uint) (ChatCompletionMessage, error) AddConversation(*Conversation) error AddMessages([]ChatCompletionMessage) error }
GptBackend is the interface for GPT backend
type SystemRole ¶
type SystemRole struct { gorm.Model Name string `gorm:"index" json:"name,omitempty"` Content string `json:"content,omitempty"` }
func (SystemRole) TableName ¶
func (SystemRole) TableName() string
type SystemRoleDAO ¶
type SystemRoleDAO interface { ListSystemRoles(query interface{}, args ...interface{}) ([]SystemRole, error) GetSystemRole(id uint) (SystemRole, error) AddSystemRole(*SystemRole) error }
Click to show internal directories.
Click to hide internal directories.