diva.chat package

Submodules

diva.chat.interface_chatbot_scopes module

diva.chat.interface_classification module

diva.chat.interface_disclaimer module

diva.chat.interface_gen_text_answer module

diva.chat.interface_memory_rephrasing module

diva.chat.module_chat module

class diva.chat.module_chat.ModuleChat[source]

Bases: object

This module manages everything related to the chat between the user and chatbot, including Large Language Model (LLM) interactions.

add_disclaimer(types: list[str])[source]

Adds warning about frequency of data update and differences between climate predictions and weather forecast

property chat: Chat
property chatbot_scope_strategy: ChatbotScopes
clear_history()[source]

Clears the chat history

create_user_prompt(prompt: str)[source]

Creates the Prompt instance containing the user prompt. The text string of the user prompt should not be empty. The Prompt instance is stored in a Chat instance, itself stored in a ModuleChat instance.

Parameters

prompt: str

the text written by the user.

generate_text_answer()[source]

Generates a text answer in response to the user prompt.

The answer may vary depending on whether the prompt asks something within the chatbot scopes, depending on the given context, toxicity of the prompt, type of prompt (visualisation or discussion)…

is_memory_needed(last_prompt: Prompt | None = None, prompt: Prompt | None = None)[source]

Determines if memory (of the previous answer or of the previous prompt) is needed to answer the current prompt.

Parameters

last_prompt: Union[‘Prompt’, None], optional, default to None.

the Prompt instance containing the last user prompt. If None, it retrieves the Prompt instance directly from the chat history

prompt: Union[‘Prompt’, None], optional, default to None.

the Prompt instance, containing the current user prompt. If None, it retrieves the Prompt instance directly from the chat history.

is_prompt_in_scope()[source]

Verifies if the prompt corresponds to a task that is in the scope of the chatbot. If not in scope, the chatbot may not answer.

property memory_needed: bool
property prompt: Prompt
prompt_classification() str[source]

Classifies the prompt (intention) as either “discussion” or “visualisation”. If “discussion”, the chatbot response is only text. If “visualisation”, the chatbot response is text + graph. Returns a word, either “discussion” or “visualisation”

property prompt_history: list[Prompt]
prompt_rephrasing()[source]

Rephrases the user prompt to remove typos, and to make grammatically correct sentences. Can also be used to combine the current prompt with previous answer/prompt to mimic memory.

set_config_creation_strategy(strategy)[source]

Can be used to set a new classification strategy

set_demand_of_info(text: str)[source]

Setter. Demand of info is the demand made by the chatbot to the user when some information in the prompt are missing.

diva.chat.service_chatbot_scopes module

diva.chat.service_disclaimer module

diva.chat.service_gen_text_answer module

diva.chat.service_is_memory_needed module

diva.chat.service_prompt_classification module

diva.chat.service_prompt_rephrasing module

Module contents