-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
707 refactor of chatgptchatcompletion #758
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! The only thing I'd prefer would be to move setSystemRoleInChatHistory
out of openai.ts.
I'd argue it can go in the chat controller, as that's the only place that uses it, although I appreciate that file is getting a little large.
Adding services for each controller would be nice, but a little overkill for this ticket. Could be worth making a new issue for it though? 👀
Alternatively, in #740 I added a chat utils file, could go there?
Re chat Service, I've just made #761 to introduce that. I don't think the other controllers are big enough to warrant a service however. I reckon I'll wait for #740 and put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few thoughts.
…pushMessageToHistory
backend/test/unit/utils/chat.test.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the tests for setSystemRoleInChatHistory
then decided I could split the file apart into pushMessageToHistory.test.ts
and setSystemRoleInChatHistory
@@ -297,6 +324,41 @@ describe('handleChatToGPT unit tests', () => { | |||
}) | |||
); | |||
}); | |||
|
|||
test('GIVEN output filtering defence enabled WHEN handleChatToGPT called THEN it should return 200 and blocked reason', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test ain't got anything to do with this ticket, but I noticed it was missing and it's pretty straightforward so I added it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great 👌
One suggestion for test mocking. Mocking classes is pretty complex.... One very good reason to avoid classes in our own code!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an import to correct and we're all good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡ Go!
No longer on project :(
Description
REFACTOR: moves the logic for setting the system role in chat history to its own method (
setSystemRoleInChatHistory
), and then instead of calling that method fromchatGptChatCompletion
(openAI
module), we call it fromhandleChatToGPT
(chatController
module). The idea of moving where it's invoked is to make methods responsible for fewer things.Rewrites tests accordingly.
Notes
setSystemRoleInChatHistory
on its own, then just checks that it gets called inhandleChatToGPT
Concerns
setSystemRoleInChatHistory
, so I left it inopenai
. In my ideal word, we'd have some module "chatService" which sits in between thechatController
and the lower level modules (openai
,langchain
) which would deal with this sort of thing.Checklist
Have you done the following?