- Issue created by @ayrmax
- 🇮🇳India Vivek Panicker Kolkata
To add to this, I find that this happens mainly for Anonymous users.
The issue happens here .
The form response is already set and after that the$http_response->setCallback`
is executed. - 🇬🇧United Kingdom MrDaleSmith
I wonder if we should instead have a method inside
$this->aiAssistantRunner
to retrieve the session: this could then be used by any code using the assistant API without it having to reroll its own solution?Something along the lines of:
public function getSession () { $thread_id = $this->getThreadsKey(); $session = $this->getTempStore()->get($thread_id); if (empty($session)) { $session['output_contexts'] = []; $this->aiAssistantRunner->getTempStore()->set($thread_id, $session); } return $session; }
- 🇮🇳India Vivek Panicker Kolkata
I think using the getTempstore() is what is causing the issue.
Instead we should try to use cookies, as that would reduce the load on the page, and also not cause any caching issues. - 🇮🇳India Vivek Panicker Kolkata
I tried the patch provided in #4.
But it doesn't work properly for me.
I get the following response from the chatbot:I am sorry, but I could not find any relevant information in the archives. Please try to ask the question in a different way or try to ask a different question.
Works fine for me in admin.
-
marcus_johansson →
committed ec90aec6 on 3488961-headers-have-already
Issue #3488961: Headers have already been sent
-
marcus_johansson →
committed ec90aec6 on 3488961-headers-have-already
-
marcus_johansson →
committed 4df27f31 on 3488961-headers-have-already
Issue #3488961: Headers have already been sent
-
marcus_johansson →
committed 4df27f31 on 3488961-headers-have-already
- 🇩🇪Germany marcus_johansson
Moving to cookies will need some thought, since there are both privacy and security concerns connected to it. Also architectural. Also writing/editing a cookie after headers are sent would cause the same issue. And they have a limit of 4k in certain browsers.
The biggest issue is that we are trying to solve it via AI Assistants API, meaning that the frontend can not get involved. Otherwise localstorage would be an option, though once again security and privacy concerns. We could add a mode called frontend/client/whatever handled, where the assistant only takes whatever messages it gets. But the complexity of handling every possible action based on it being handled by backend or frontend is too much.
For now I have just done the easiest solution, which is to start the session in the streamed output. There is a MR here: https://git.drupalcode.org/project/ai/-/merge_requests/377 - if you have the possibility to test it, please do.
Also note that the we are moving away from the old custom AI Chatbot to the Deepchat version - we are already showing warnings for it. Its basically just to switch the block type. But that helps us remove a lot of frontend concerns and make the chatbot look more professional. Most likely the old chatbot will be in a contrib module (if we find maintainers) or removed before we go to production.
-
marcus_johansson →
committed 8895c9b0 on 3488961-headers-have-already
Issue #3488961: Deepchat should not set historical messages on none
-
marcus_johansson →
committed 8895c9b0 on 3488961-headers-have-already
- 🇮🇳India Vivek Panicker Kolkata
@marcus_johansson I applied the patch https://git.drupalcode.org/project/ai/-/merge_requests/377.diff.
Now the chatbot doesn't give the error - "Headers have already been sent".
But when you ask some contextual question, it gives the response -
"I am sorry, but I could not find any relevant information in the archives. Please try to ask the question in a different way or try to ask a different question."
Seems like it's not getting the context for some reason.The situation is like:
Me: Tell me about xyz product. Chatbot: xzy is a good product.... Me: What can you tell me about it's availability? Chatbot: "I am sorry, but I could not find any relevant information in the archives. Please try to ask the question in a different way or try to ask a different question."
If I repeat the above steps again, the same things happen again.
Works fine for admin.
Note: I have provided access to the anonymous, admin and authenticated users in the advanced settings of the AI Assistant. - 🇩🇪Germany marcus_johansson
Thanks all for the issue and testing, its getting merged.
-
marcus_johansson →
committed 2835921e on 1.0.x
Issue #3488961: Headers have already been sent
-
marcus_johansson →
committed 2835921e on 1.0.x
- 🇺🇸United States shasha821110
tested the patch and seems works good so far. Thanks Marcus.
- Status changed to Fixed
about 1 hour ago 9:39am 22 January 2025 Automatically closed - issue fixed for 2 weeks with no activity.