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
16 stars 11 forks source link

705 refactor handlechattogpt to remove mutation #743

Closed heatherlogan-scottlogic closed 9 months ago

heatherlogan-scottlogic commented 10 months ago

Description

Refactor of functions inside chatController.ts and openAI.ts to reduce mutation. ChatResponse, chatHistroy, sentEmails, should not be mutated across different functions - instead changes should be returned by the using functions either as

Notes

openai.ts

chatController.ts

Concerns

Checklist

Have you done the following?

chriswilty commented 9 months ago

One thing that goes hand-in-hand with immutability is avoiding let declarations wherever possible. Sometimes it doesn't seem possible, if we have conditional statements that might or might not overwrite that value, but such cases are often a sign that the function needs to be split. In any case, this is a strong start, and the rest we can tackle as we go.

pmarsh-scottlogic commented 9 months ago

Really appreciate the thorough PR description ⭐

pmarsh-scottlogic commented 9 months ago

Nothing else from me. Aside from Peter's open questions (and the merge conflict) this looks good to go.

@pmarsh-scottlogic Would you like to take this one, and I'll handle George's PR?

@chriswilty I was about to suggest exactly the same thing :)

pmarsh-scottlogic commented 9 months ago

Review notes for myself

What happened before when user sends a message on a low level, say level 1?

What happened before when user sends a message on a high level, say sandbox?

What happens now when user sends a message on a low level, say level 1?

What happens now when user sends a message on a high level, say sandbox?

chriswilty commented 9 months ago

@pmarsh-scottlogic I'm very happy with this now, good work. The linter rule is small beans, remove it if you wish - doesn't stop me approving.