Feat: load char/agent; agent-chat flow

This commit is contained in:
Grail Finder
2024-12-09 19:26:26 +03:00
parent bdd40ea8df
commit 67f36d417f
5 changed files with 119 additions and 40 deletions

View File

@@ -17,6 +17,7 @@ type ChatHistory interface {
ListChats() ([]models.Chat, error)
GetChatByID(id uint32) (*models.Chat, error)
GetLastChat() (*models.Chat, error)
GetLastChatByAgent(agent string) (*models.Chat, error)
UpsertChat(chat *models.Chat) (*models.Chat, error)
RemoveChat(id uint32) error
ChatGetMaxID() (uint32, error)
@@ -45,6 +46,13 @@ func (p ProviderSQL) GetLastChat() (*models.Chat, error) {
return &resp, err
}
func (p ProviderSQL) GetLastChatByAgent(agent string) (*models.Chat, error) {
resp := models.Chat{}
query := "SELECT * FROM chats WHERE agent=$1 ORDER BY updated_at DESC LIMIT 1"
err := p.db.Get(&resp, query, agent)
return &resp, err
}
func (p ProviderSQL) UpsertChat(chat *models.Chat) (*models.Chat, error) {
// Prepare the SQL statement
query := `