Spaces:
Sleeping
Sleeping
macbookpro
commited on
Commit
·
fb90240
1
Parent(s):
89bf64d
try and except in inference.py
Browse files- server/app.py +2 -9
- server/data/load_data.py +1 -1
- 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 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|