ArturG9 commited on
Commit
fe6ba28
1 Parent(s): 1fd4ac2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py CHANGED
@@ -15,7 +15,84 @@ def main():
15
  st.header("Info Assistant :" ":books:")
16
 
17
  st.markdown("###### Get support of "Info Assistant" , who has in memory a lot of Data Science related articles, if it can't answer based on it's knowledge base, information will be found on the internet:" ":books:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
 
 
19
 
20
 
21
 
 
15
  st.header("Info Assistant :" ":books:")
16
 
17
  st.markdown("###### Get support of "Info Assistant" , who has in memory a lot of Data Science related articles, if it can't answer based on it's knowledge base, information will be found on the internet:" ":books:")
18
+
19
+
20
+ if "messages" not in st.session_state:
21
+ st.session_state["messages"] = [
22
+ {"role": "assistant", "content": "Hi, I'm a chatbot who is based on respublic of Lithuania law documents. How can I help you?"}
23
+ ]
24
+
25
+
26
+ search_type = st.selectbox(
27
+ "Choose search type. Options are [Max marginal relevance search (similarity) , Similarity search (similarity). Default value (similarity)]",
28
+ options=["mmr", "similarity"],
29
+ index=1
30
+ )
31
+
32
+ k = st.select_slider(
33
+ "Select amount of documents to be retrieved. Default value (5): ",
34
+ options=list(range(2, 16)),
35
+ value=4
36
+ )
37
+ retriever = create_retriever_from_chroma(vectorstore_path="docs/chroma/", search_type=search_type, k=k, chunk_size=350, chunk_overlap=30)
38
+
39
+
40
+
41
+ # Graph
42
+ workflow = StateGraph(GraphState)
43
+
44
+ # Define the nodes
45
+ workflow.add_node("ask_question", ask_question)
46
+ workflow.add_node("retrieve", retrieve) # retrieve
47
+ workflow.add_node("grade_documents", grade_documents) # grade documents
48
+ workflow.add_node("generate", generate) # generatae
49
+ workflow.add_node("web_search", web_search) # web search
50
+ workflow.add_node("transform_query", transform_query)
51
+
52
+
53
+ # Build graph
54
+ workflow.set_entry_point("ask_question")
55
+ workflow.add_conditional_edges(
56
+ "ask_question",
57
+ grade_question_toxicity,
58
+
59
+ {
60
+ "good": "retrieve",
61
+ 'bad': END,
62
+
63
+ },
64
+ )
65
+
66
+ workflow.add_edge("retrieve", "grade_documents")
67
+ workflow.add_conditional_edges(
68
+ "grade_documents",
69
+ decide_to_generate,
70
+ {
71
+ "search": "web_search",
72
+ "generate": "generate",
73
+
74
+ },
75
+ )
76
+ workflow.add_edge("web_search", "generate")
77
+ workflow.add_conditional_edges(
78
+ "generate",
79
+ grade_generation_v_documents_and_question,
80
+ {
81
+ "not supported": "generate",
82
+ "useful": END,
83
+ "not useful": "transform_query",
84
+ },
85
+ )
86
+
87
+ workflow.add_edge("transform_query", "retrieve")
88
+
89
+ custom_graph = workflow.compile()
90
+
91
+
92
+
93
 
94
+ if user_question := st.text_input("Ask a question about your documents:"):
95
+ handle_userinput(user_question,retriever,rag_chain)
96
 
97
 
98