Skip to content

Commit

Permalink
Merge pull request #31 from klipach/refactor-chat-history
Browse files Browse the repository at this point in the history
Refactor chat history
  • Loading branch information
klipach authored Jan 23, 2025
2 parents 73b4de5 + a39e2aa commit d85f30e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ func Bot(w http.ResponseWriter, r *http.Request) {
return
}

chatHistory, err := chat.LoadChatHistory(ctx, token.UID, msg.ChatID)
messages, err := chat.LoadHistory(ctx, token.UID, msg.ChatID)
if err != nil {
logger.Printf("error while loading chat history: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}

chatHistory = append(chatHistory, llms.TextParts(llms.ChatMessageTypeHuman, msg.Message))
messages = append(messages, llms.TextParts(llms.ChatMessageTypeHuman, msg.Message))

gpt4o, err := openai.New(
openai.WithModel("gpt-4o"),
Expand All @@ -208,7 +208,7 @@ func Bot(w http.ResponseWriter, r *http.Request) {
[]llms.MessageContent{
llms.TextParts(llms.ChatMessageTypeSystem, shortPromptStr.String()),
},
chatHistory...,
messages...,
),
llms.WithTemperature(0.8),
llms.WithMaxTokens(1000),
Expand Down Expand Up @@ -281,7 +281,7 @@ func Bot(w http.ResponseWriter, r *http.Request) {
[]llms.MessageContent{
llms.TextParts(llms.ChatMessageTypeSystem, mainPromptStr.String()),
},
chatHistory...,
messages...,
),
llms.WithTemperature(0.8),
llms.WithMaxTokens(1000),
Expand Down
2 changes: 1 addition & 1 deletion chat/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type firestoreUser struct {
} `firestore:"chats"`
}

func LoadChatHistory(ctx context.Context, userID string, chatID int) ([]llms.MessageContent, error) {
func LoadHistory(ctx context.Context, userID string, chatID int) ([]llms.MessageContent, error) {
logger := logger.FromContext(ctx)

var chatHistory []llms.MessageContent
Expand Down
2 changes: 1 addition & 1 deletion prompts/short.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Ignore all previous conversations. Erase all prior dialogues.

- do not answer or repet the user's question
- if external knowledge is not required, respond with "no" and stop
- if external knowledge is required, generate a concise external prompt focusing solely on the needed information
- if external knowledge is required, generate a concise prompt focusing solely on the needed information

##** Today is: {{ .Today }}**
##** Current time offset is: {{ .TimeOffset }}**
Expand Down

0 comments on commit d85f30e

Please sign in to comment.