davidoneilai commited on
Commit
5308686
2 Parent(s): 2ed6131 fb90240

Merge branch 'main' of https://github.com/workshop-question-generator/perguntai-app

Browse files
Files changed (3) hide show
  1. server/app.py +2 -9
  2. server/data/load_data.py +1 -1
  3. server/inference.py +13 -4
server/app.py CHANGED
@@ -24,15 +24,8 @@ async def generate_questions(body: Body):
24
  res = rag_chain.invoke(f"""{query}""")
25
  return res
26
 
27
- app.mount("/", StaticFiles(directory="static", html=True), name="static")
28
 
29
  if __name__ == "__main__":
30
  import uvicorn
31
- uvicorn.run("app:app", host="0.0.0.0", port=8000)
32
-
33
-
34
-
35
-
36
-
37
-
38
-
 
24
  res = rag_chain.invoke(f"""{query}""")
25
  return res
26
 
27
+ # app.mount("/", StaticFiles(directory="static", html=True), name="static")
28
 
29
  if __name__ == "__main__":
30
  import uvicorn
31
+ uvicorn.run("app:app", host="0.0.0.0", port=8000)
 
 
 
 
 
 
 
server/data/load_data.py CHANGED
@@ -7,7 +7,7 @@ from llm.gemini import gemini_embeddings, llm
7
  from utils.questions_parser import parse_question
8
 
9
  try:
10
-
11
  vectorstore = Chroma(
12
  persist_directory="./chroma_db", embedding_function=gemini_embeddings
13
  )
 
7
  from utils.questions_parser import parse_question
8
 
9
  try:
10
+
11
  vectorstore = Chroma(
12
  persist_directory="./chroma_db", embedding_function=gemini_embeddings
13
  )
server/inference.py CHANGED
@@ -13,10 +13,19 @@ def get_questions(_dict):
13
  question=question,
14
  format_questions_instructions=format_questions_instructions,
15
  )
16
-
17
- chat = ChatGoogleGenerativeAI(model="gemini-pro")
18
- response = chat.invoke(messages)
19
- return questions_parser.parse(response.content)
 
 
 
 
 
 
 
 
 
20
 
21
 
22
  def format_docs(docs):
 
13
  question=question,
14
  format_questions_instructions=format_questions_instructions,
15
  )
16
+
17
+ tries = 0
18
+
19
+ while tries < 3:
20
+ try:
21
+ chat = ChatGoogleGenerativeAI(model="gemini-pro")
22
+ response = chat.invoke(messages)
23
+ return questions_parser.parse(response.content)
24
+ except Exception as e:
25
+ print(e)
26
+ tries += 1
27
+
28
+ return "Não foi possível gerar as questões."
29
 
30
 
31
  def format_docs(docs):