From d1df3296586b7ab02790c6bbd27d6cdb2b0cb248 Mon Sep 17 00:00:00 2001 From: Nick Savage Date: Thu, 28 Nov 2024 06:16:09 -0500 Subject: [PATCH] backend: working on search with chat --- go-backend/handlers/chat.go | 7 +++++-- go-backend/handlers/chat_test.go | 4 ++-- go-backend/schema/0031-chat-add-cards.sql | 1 + zettelkasten-front/src/models/Chat.ts | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 go-backend/schema/0031-chat-add-cards.sql diff --git a/go-backend/handlers/chat.go b/go-backend/handlers/chat.go index 6b0c4d3..7fe8baf 100644 --- a/go-backend/handlers/chat.go +++ b/go-backend/handlers/chat.go @@ -10,6 +10,7 @@ import ( "github.com/google/uuid" "github.com/gorilla/mux" + "github.com/lib/pq" ) const MODEL = "gpt-4" @@ -264,8 +265,8 @@ func (s *Handler) GetChatCompletion(userID int, conversationID string) (models.C query := ` INSERT INTO chat_completions ( user_id, conversation_id, sequence_number, role, - content, model, tokens - ) VALUES ($1, $2, $3, $4, $5, $6, $7) + content, model, tokens, card_chunks + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, created_at ` err = s.DB.QueryRow( @@ -277,6 +278,8 @@ func (s *Handler) GetChatCompletion(userID int, conversationID string) (models.C completion.Content, completion.Model, completion.Tokens, + pq.Array(completion.ReferencedCards), // Convert Go slice to PostgreSQL array + ).Scan(&completion.ID, &completion.CreatedAt) if err != nil { diff --git a/go-backend/handlers/chat_test.go b/go-backend/handlers/chat_test.go index bd028eb..dfbb3bb 100644 --- a/go-backend/handlers/chat_test.go +++ b/go-backend/handlers/chat_test.go @@ -1,8 +1,8 @@ package handlers import ( - "bytes" - "encoding/json" + // "bytes" + // "encoding/json" "go-backend/models" "go-backend/tests" "log" diff --git a/go-backend/schema/0031-chat-add-cards.sql b/go-backend/schema/0031-chat-add-cards.sql new file mode 100644 index 0000000..55431aa --- /dev/null +++ b/go-backend/schema/0031-chat-add-cards.sql @@ -0,0 +1 @@ +ALTER TABLE chat_completions ADD COLUMN card_chunks integer[]; diff --git a/zettelkasten-front/src/models/Chat.ts b/zettelkasten-front/src/models/Chat.ts index 43bc62f..fe175df 100644 --- a/zettelkasten-front/src/models/Chat.ts +++ b/zettelkasten-front/src/models/Chat.ts @@ -12,7 +12,7 @@ export interface ChatCompletion { } export interface ConversationSummary { - conversation_id: string; + id: string; message_count: number; created_at: Date; model: string;