1
+ import streamlit as st
2
+ from utils .config_utils import get_config , MODEL_OPTIONS , SEARCH_TYPES
3
+ from utils .langchain import create_chain_conversation , ARQUIVOS
4
+ from utils .sidebar_utils import sidebar_config
5
+ from utils .utils import start_chatbot
6
+
7
+
8
+ def config_window () -> None :
9
+ """Configure the Streamlit window and chatbot parameters."""
10
+ st .set_page_config (
11
+ page_title = "Configurações do Chatbot" ,
12
+ page_icon = "⚙️" ,
13
+ layout = "centered" ,
14
+ initial_sidebar_state = "expanded" ,
15
+ menu_items = {"Get Help" : "https://www.streamlit.io/docs" }
16
+ )
17
+ st .header (
18
+ "⚙️ Configurações de Parâmetros do Chatbot" ,
19
+ help = "Configurações do ChatBot para leitura de documentos PDF" ,
20
+ divider = True
21
+ )
22
+
23
+ model_name = st .selectbox (
24
+ "Modelo de Linguagem" ,
25
+ MODEL_OPTIONS ,
26
+ index = MODEL_OPTIONS .index (get_config ("model_name" )),
27
+ key = "model_name_input" ,
28
+ help = "Modelo de linguagem a ser utilizado pelo ChatBot"
29
+ )
30
+
31
+ retrieval_search_type = st .selectbox (
32
+ "Tipo de Busca" ,
33
+ options = SEARCH_TYPES ,
34
+ index = SEARCH_TYPES .index (get_config ("retrieval_search_type" )),
35
+ key = "retrieval_search_type_selectbox" ,
36
+ help = "Tipo de busca a ser utilizado pelo ChatBot"
37
+ )
38
+ retrieval_kwargs : dict = {}
39
+
40
+ retrieval_kwargs ['k' ] = st .select_slider (
41
+ "Número de Documentos Retornados (k) - Recomendado: 5" ,
42
+ options = list (range (1 , 101 )),
43
+ value = get_config ("retrieval_kwargs" )['k' ],
44
+ key = "retrieval_kwargs_k_slider" ,
45
+ help = "Número de documentos mais relevantes a serem retornados" ,
46
+ on_change = lambda : st .session_state .update (
47
+ {"retrieval_kwargs" : retrieval_kwargs })
48
+ )
49
+
50
+ retrieval_kwargs ['fetch_k' ] = st .select_slider (
51
+ "Número de Documentos Buscados (fetch_k) - Recomendado: 20" ,
52
+ options = list (range (1 , 101 )),
53
+ value = get_config ("retrieval_kwargs" )['fetch_k' ],
54
+ key = "retrieval_kwargs_fetch_k_slider" ,
55
+ help = "Número total de documentos a serem buscados antes da filtragem" ,
56
+ on_change = lambda : st .session_state .update (
57
+ {"retrieval_kwargs" : retrieval_kwargs })
58
+ )
59
+
60
+ prompt = st .text_area (
61
+ label = "Prompt Template - Modelo de Prompt" ,
62
+ value = get_config ("prompt" ),
63
+ height = 400 ,
64
+ key = "prompt_slider" ,
65
+ help = "Template de prompt a ser utilizado pelo ChatBot"
66
+
67
+ )
68
+
69
+ if st .button (
70
+ "Salvar Configurações" ,
71
+ key = "salvar_config" ,
72
+ help = "Salva as configurações do ChatBot" ,
73
+ use_container_width = True
74
+ ):
75
+ st .session_state ["model_name" ] = model_name
76
+ st .session_state ["retrieval_search_type" ] = retrieval_search_type
77
+ st .session_state ["retrieval_kwargs" ] = retrieval_kwargs
78
+ st .session_state ["prompt" ] = prompt
79
+ st .toast ("Configurações Salvas com Sucesso!" , icon = "✔️" )
80
+ st .rerun ()
81
+
82
+ if st .button (
83
+ "Atualizar ChatBot" ,
84
+ key = "atualizar_chatbot" ,
85
+ help = "Atualiza o ChatBot com as novas configurações" ,
86
+ type = "primary" ,
87
+ use_container_width = True
88
+ ):
89
+ start_chatbot (st , ARQUIVOS , create_chain_conversation )
90
+
91
+ def app () -> None :
92
+ """Main Streamlit application."""
93
+ config_window ()
94
+ with st .sidebar :
95
+ sidebar_config (st )
96
+
97
+
98
+ app ()
0 commit comments