Skip to content

Commit

Permalink
tweak history saving
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Nov 29, 2023
1 parent 303124a commit 398a9e4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/placeos-rest-api/controllers/chat_gpt/chat_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module PlaceOS::Api
loop do
count += 1
if count > 20
yield({chat_id: chat_id, message: "sorry, I am unable to complete that task", type: :response})
yield({chat_id: chat_id, message: "sorry, I am unable to complete that task.\nTry breaking the request into smaller tasks.", type: :response})
request.messages.truncate(0..0) # leave only the prompt
break
end
Expand Down Expand Up @@ -158,11 +158,10 @@ module PlaceOS::Api
end
tracking_total = @total_tokens

# save relevant history
# track request history
msg = resp.choices.first.message
msg.tokens = resp.usage.completion_tokens
request.messages << msg
save_history(chat_id, msg) unless msg.tool_calls || (msg.role.function? && msg.name != "task_complete")

# perform function calls until we get a response for the user
if tool_calls = msg.tool_calls
Expand Down Expand Up @@ -190,6 +189,8 @@ module PlaceOS::Api
request.messages << res
end
next
else
save_history(chat_id, msg)
end

cleanup_messages(request, discardable_tokens)
Expand Down

0 comments on commit 398a9e4

Please sign in to comment.