basic llm request stream
This commit is contained in:
1 parent
f74e4d1043
commit
a92cc76a9a
66 files changed
+1496
-158
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package turso
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type TursoChatRepository struct {
|
||||
db *sql.DB
|
||||
chatTable orm.Table[domain.Chat]
|
||||
messageTable orm.Table[domain.Message]
|
||||
}
|
||||
|
||||
func NewTursoChatRepository(db *sql.DB) *TursoChatRepository {
|
||||
dialect := orm.NewSqliteDialect()
|
||||
chatTable, err := orm.NewTable[domain.Chat](db, dialect, "chats")
|
||||
messageTable, err := orm.NewTable[domain.Message](db, dialect, "chat_messages")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche agent table")
|
||||
}
|
||||
|
||||
return &TursoChatRepository{
|
||||
db: db,
|
||||
chatTable: chatTable,
|
||||
messageTable: messageTable,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) ListChats(userID string, teamID string, page int) ([]*domain.Chat, error) {
|
||||
return r.chatTable.Select(
|
||||
orm.WithWhere(
|
||||
"team_id=$1 and team_id in (select team_id from user_teams where user_id=$2)",
|
||||
teamID,
|
||||
userID,
|
||||
),
|
||||
orm.WithPagination(page, 50),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) GetChat(userID string, teamID string, id string) (*domain.Chat, error) {
|
||||
return r.chatTable.SelectOne(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
teamID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) CreateChat(userID string, chat *domain.Chat) (*domain.Chat, error) {
|
||||
return r.chatTable.Insert(chat)
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) UpdateChat(userID string, chat *domain.Chat) (*domain.Chat, error) {
|
||||
return r.chatTable.Update(chat)
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) DeleteChat(userID string, teamID string, id string) error {
|
||||
return r.chatTable.DeleteWhere(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
teamID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) GetChatMessages(userID string, teamID string, chatID string) ([]*domain.Message, error) {
|
||||
return r.messageTable.Select(
|
||||
orm.WithWhere(
|
||||
"chat_id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
chatID,
|
||||
teamID,
|
||||
userID,
|
||||
),
|
||||
orm.WithOrder("_date_created asc"),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoChatRepository) CreateChatMessage(userID string, message *domain.Message) (*domain.Message, error) {
|
||||
return r.messageTable.Insert(message)
|
||||
}
|
||||
Reference in new issue
Block a user