Skip to content
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

run defence detection and chat completion concurrently #375

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

heatherlogan-scottlogic
Copy link
Contributor

@heatherlogan-scottlogic heatherlogan-scottlogic commented Oct 9, 2023

this ticket

  • in the chat endpoint (in router.ts), split logic for level 1 and 2 (where no defences are applied), and level 2 and 3 (where we detect defences and can block message if turned on)

  • for level 2 and 3, call detectTriggeredDefences and chatGptSendMessage in parallel

  • when both are resolved, check if message was blocked in detectTriggeredDefences

  • if it is blocked, restore the chat history object from before the chat was sent (essentially undoing the chat message as we now find out it was blocked)

  • set the openAi reply to stop the message being returned to the user


testing


comments

  • this looks like it's quite effective in reducing wait times during the conversation, although now have the added issue of wasting the cost of a call to the openAi api, if the message is blocked, and we throw it away

@heatherlogan-scottlogic heatherlogan-scottlogic linked an issue Oct 9, 2023 that may be closed by this pull request
Copy link
Member

@chriswilty chriswilty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, and one concern to point out, but the logic seems sound.

I am of course concerned that changes such as these are not covered by tests!

wonLevel: false,
};
const message = req.body.message;
const currentLevel = req.body.currentLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructuring is neater:

const { message, currentLevel } = req.body;

...openAiReply.defenceInfo.triggeredDefences,
];
// combine blocked
chatResponse.defenceInfo.isBlocked = openAiReply.defenceInfo.isBlocked;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I'm a little concerned about this mutable chatResponse object being passed around, and modified as a side-effect, as it feels like a difficult-to-detect bug waiting to emerge, particularly in functions with high complexity such as these. I am having difficulty seeing all the places it can be modified, and in what order.

I'll add a future issue to tackle this complexity, and introduce immutability.

Copy link
Contributor

@gsproston-scottlogic gsproston-scottlogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change, this has sped things up a massive amount 🏃‍♀️

@heatherlogan-scottlogic heatherlogan-scottlogic merged commit 46def3d into dev Oct 17, 2023
2 checks passed
@gsproston-scottlogic gsproston-scottlogic deleted the 333-dont-wait-llm-evaluation branch October 18, 2023 14:13
chriswilty pushed a commit that referenced this pull request Apr 8, 2024
* run defence detection and chat completion concurrently

* split up chat request

* refactor error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't wait for LLM evaluation
3 participants