You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Completing this will greatly ease unit testing and documentation, which are two priorities for the end of the project.
Description
Lil' refactor to separate concerns and hopefully ease testing.
At the moment we have chatController.ts and openai.ts modules which contain the bulk of the logic for chatting with the chatbot. Both files are a bit bloated and seperation of concerns is wish-washy.
I propose that we introduce a new module chatService.ts, so that the concerns are separated into 3 layers (plus utils, introduced in #740 ):
chatController.ts deals with the API side of things. It validates the request parameters and constructs a sensible response based on how the chat goes (including unhappy paths).
chatService.ts contains the business logic for most of the interaction. Its job it to take an (already validated) message from the user, and get a response, including dealing with the tool calls faff.
openai.ts is only concerned with directly interfacing with the openAI API.
In concrete terms, I reckon we should:
Move handleLowLevelChat, handleHigherLevelChat and about half of the logic in handleChatToGPT to a fresh module chatService.ts.
Move performToolCalls, getFinalReplyAfterAllToolCalls, chatGptSendMessage also to chatService.ts.
Feature Request
Completing this will greatly ease unit testing and documentation, which are two priorities for the end of the project.
Description
Lil' refactor to separate concerns and hopefully ease testing.
At the moment we have
chatController.ts
andopenai.ts
modules which contain the bulk of the logic for chatting with the chatbot. Both files are a bit bloated and seperation of concerns is wish-washy.I propose that we introduce a new module
chatService.ts
, so that the concerns are separated into 3 layers (plus utils, introduced in #740 ):chatController.ts
deals with the API side of things. It validates the request parameters and constructs a sensible response based on how the chat goes (including unhappy paths).chatService.ts
contains the business logic for most of the interaction. Its job it to take an (already validated) message from the user, and get a response, including dealing with the tool calls faff.openai.ts
is only concerned with directly interfacing with the openAI API.In concrete terms, I reckon we should:
handleLowLevelChat
,handleHigherLevelChat
and about half of the logic inhandleChatToGPT
to a fresh modulechatService.ts
.performToolCalls
,getFinalReplyAfterAllToolCalls
,chatGptSendMessage
also tochatService.ts
.getChatCompletionsFromHistory
,pushCompletionToHistory
,getBlankChatResponse
toutils/chat.ts
(introduced in 708 move logic for detecting output defence bot filtering #740 )After all this it should be easier to unit test the exported methods from each layer.
NB: AFter a bunch of backend refactoring (#740, #743, #758) some of the above details will change, but the general gist is the same
Acceptance criteria
Refactor, so only regression testing.
Question: Do we want this, or does the benefit not outweigh the effort?
The text was updated successfully, but these errors were encountered: