openai

package
v0.0.0-...-a15e8ba Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 NewGpt3p5

func NewGpt3p5(db *gorm.DB, key string) *Gpt3p5

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

func (*Gpt3p5) Send

func (b *Gpt3p5) Send(conversationID uint, msg string) (resp ChatCompletionMessage, err error)

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
}

Jump to

Keyboard shortcuts

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