Skip to content

Commit

Permalink
705 refactor handlechattogpt to remove mutation (#743)
Browse files Browse the repository at this point in the history
* refactor chatGptCallFunction

* pass history/email vars through openAI functions

* remove chatResponse from tool call functions

* start refactor on chatGptSendMessage

* begin to remove mutations from controller functions

* merge dev

* dont return defences from chatGptSendMessage

* update tests

* rebase frontend changes & tidy up

* fix alerted defences showing

* fix user message added to history when transformed

* set chatHistory to gptreply.chatHistory in getFinalReplyAfterAllToolCalls (to be safe)

* Address some PR comments

* remove blocked and defence report from handleChatError as it is not used

* save chat history to session on error

* address PR comments

* remove defenceReport from ChatResponse returned by openai

* removes defenceReport from LevelHandlerResponse interface

* 708 move logic for detecting output defence bot filtering (#740)

* Renamed method to be clear what defences are being checked

* Moved detection of output defences

* Using await rather than then

* Clearer use of the input defence report

* WIP: openai file doesn't know about the defence report

* WIP: Using new pushMessageToHistory method

* Fixed chat history

* Simpler combining of defence reports

* Consistent blocking rules

* Not mutating chatResponse in the performToolCalls method

* Better loop

* Not mutating chatResponse in the chatGptChatCompletion method

* Simplified return

* Method to add the user messages to chat history

* Better output defence report

* Moved combineChatDefenceReports to chat controller

* No longer exporting getFilterList and detectFilterList

* Fixed test build errors

* detectTriggeredOutputDefences unit tests

* Fixed chat controller tests

* Removed output filtering integration tests

This code is now covered by the unit tests

* Moved utils method to new file

* Fixed remaining tests

* pushMessageToHistory unit tests

* WIP: Now using the updated chat response

* WIP: Fixed chat utils tests

* WIP: Fixed remaining tests

* Fix for response not being set properly

* No longer adding transformed messae twice

* Nicer chat while loop

* Only sending back sent emails, not total emails

* Fixed tests

* Using flatMap

* const updatedChatHistory in low level chat

* Constructing chat response at the end of high level chat

Like what is done in low level chat

* Removed wrong comment

* Fixed tests

* Better function name

* Better promise name

* Not setting sent emails if the message was blocked

* refactor chathistory code to reduce mutation

* change test names and add comment

* adds history check to first test

* added second history check

* removed some comments

* correct some tests in integration/chatController.test

* adds unit test for chatController to make sure history is updated properly

* fixes defence trigger tests that were broken by mocks

* refactors reused mocking code

* added unit test to check history update in sandbox

* update first test to include existing history

* makes second test use existing history

* adds comment that points out some weirdness

* polishes off those tests

* fixes weirdness about combining the empty defence report

* fixes problem of not getting updated chat history

* respond to chris - makes chatHistoryWithNewUsermessages more concise

* respond to chris - adds back useful comment

* simplify transformed message ternary expression

* refactors transformMessage and only calls combineTransformedMessage once

---------

Co-authored-by: Peter Marsh <[email protected]>

* adds imports to test files to fix linting

* improve comment

* update name from high or low level chat to chat with or without defence detection

* removes stale comments

* moves sentEmails out of LevelHandlerResponse and uses the property in chatResponse instead

* changed an if to an else if

* unspread that spread

* return combined report without declaring const first

* makes chatResponse decleration more concise with buttery spreads

* updates comment

* remove linter rule about uninitialised let statements. changed the let statement in the chatController

---------

Co-authored-by: Peter Marsh <[email protected]>
Co-authored-by: George Sproston <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent cc2fdb9 commit b10a251
Show file tree
Hide file tree
Showing 16 changed files with 1,178 additions and 729 deletions.
1 change: 0 additions & 1 deletion backend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = {
],
'prefer-template': 'error',

'@typescript-eslint/init-declarations': 'error',
'@typescript-eslint/no-misused-promises': [
'error',
{
Expand Down
Loading

0 comments on commit b10a251

Please sign in to comment.