Hello again folks. I am using celery channel with django to build a chatbot. The chatbot part use langchain and openai API. Since the chatbot has memory of the conversation I need to initialize it in the WebsocketConsumer, and pass it to the task.
Because it is not a standard python type (It’s a RetrievalQA object), I need to use the pickle serializer to make it work (And it work fine). Looking at the documentation, using pickle is really dangerous with untrustfull connexion. By dangerous I mean possible code injection.
And because my app is a chatbot, I cannot really trust the user/client, it can be anyone.
The celery documentation said that it is possible to accept only certain content-type, but it looks like it is to select which serializer to accept or not.
Celery documentation about pickle security concern : Security — Celery 5.3.1 documentation
Any idea to avoid using pickle or/and to secure it ?
Thank you for your help and advices !
For context here is my task:
channel_layer = get_channel_layer()
@shared_task
def get_response(channel_name, input_data, disc_id, qa):
with get_openai_callback() as cb: #cb contain tokens usages of the call
bot_response = qa.run(input_data["text"]) #run the llm chain on the user query
save_db(disc_id,cb) #save cost to db
total_cost = cb.total_cost
#send chatbot response
async_to_sync(channel_layer.send)(
channel_name,
{
"type": "chat_message",
"text": {"msg": bot_response, "source": "bot"},
"cost": total_cost,
},
)