session#
- class besser.bot.core.session.Session(session_id, bot, platform)[source]#
Bases:
objectA user session in a bot execution.
When a user starts interacting with a bot, a session is assigned to him/her to store user related information, such as the current state of the bot, the conversation history, the detected intent with its parameters or any user’s private data. A session can be accessed from the body of the states to read/write user information.
- Parameters:
- _file#
File or None: The last file sent to the bot.
- flags#
A dictionary of boolean flags. A predicted_intent flag is set to true when an intent is received. When the evaluation of the current state’s transitions is done, the flag is set to false. It may happen that a transition different from the one associated with this intent is triggered (e.g. one evaluating some condition). In the following state, if there is a transition associated with the same intent, it should not be triggered as the time for this intent passed (unless the same intent is detected, in such case the flag will be set to true again). Another flag file_flag is used for the same purpose but for files sent by the user
- delete(key)[source]#
Delete an entry of the session private data storage.
- Parameters:
key (str) – the entry key
- get(key)[source]#
Get an entry of the session private data storage.
- Parameters:
key (str) – the entry key
- Returns:
the entry value, or None if the key does not exist
- Return type:
Any
- move(transition)[source]#
Move to another bot state.
- Parameters:
transition (Transition) – the transition that points to the bot state to move
- reply(message)[source]#
A bot message (usually a reply to a user message) is sent to the session platform to show it to the user.
- Parameters:
message (str) – the bot reply
- run_rag(message=None, llm_prompt=None, llm_name=None, k=None, num_previous_messages=None)[source]#
Run the RAG engine.
- Parameters:
message (str) – the input query for the RAG engine. If none is provided, the last user message will be used by default
llm_prompt (str) – the prompt containing the instructions for the LLM to generate an answer from the retrieved content. If none is provided, the RAG’s default value will be used
llm_name (str) – the name of the LLM to use. If none is provided, the RAG’s default value will be used
k (int) – number of chunks to retrieve from the vector store. If none is provided, the RAG’s default value will be used
num_previous_messages (int) – number of previous messages of the conversation to add to the prompt context. If none is provided, the RAG’s default value will be used. Necessary a connection to
MonitoringDB
- Returns:
the answer generated by the RAG engine
- Return type: