ScottLogic / prompt-injection

Application which investigates defensive measures against prompt injection attacks on an LLM, with a focus on the exposure of external tools.
MIT License
15 stars 10 forks source link

707 refactor of chatgptchatcompletion #758

Closed pmarsh-scottlogic closed 7 months ago

pmarsh-scottlogic commented 8 months ago

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 from chatGptChatCompletion (openAI module), we call it from handleChatToGPT (chatController module). The idea of moving where it's invoked is to make methods responsible for fewer things.

Rewrites tests accordingly.

Notes

Concerns

Checklist

Have you done the following?

pmarsh-scottlogic commented 8 months ago

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 setSystemRoleInChatHistory in there. Thus, consider this PR BLOCKED by #740