Spaces:
Sleeping
Sleeping
Merge branch 'tests' of https://github.com/luanpoppe/vella-backend into feat-adicionar-google-gemini-2
Browse files
README.md
CHANGED
|
@@ -8,3 +8,8 @@ pinned: false
|
|
| 8 |
---
|
| 9 |
|
| 10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 11 |
+
|
| 12 |
+
Dica de deploy no ambiente correto:
|
| 13 |
+
git push <nome_do_remote> <branch_local>:<branch_do_remote>
|
| 14 |
+
git push prd tests:main
|
| 15 |
+
git push tests tests:main
|
_utils/gerar_relatorio_modelo_usuario/GerarDocumento.py
CHANGED
|
@@ -36,7 +36,7 @@ class GerarDocumento:
|
|
| 36 |
chunk_overlap,
|
| 37 |
num_k_rerank,
|
| 38 |
model_cohere_rerank,
|
| 39 |
-
prompt_auxiliar,
|
| 40 |
gpt_model,
|
| 41 |
gpt_temperature,
|
| 42 |
# id_modelo_do_usuario,
|
|
@@ -45,7 +45,7 @@ class GerarDocumento:
|
|
| 45 |
):
|
| 46 |
self.config = config
|
| 47 |
self.logger = logging.getLogger(__name__)
|
| 48 |
-
self.prompt_auxiliar = prompt_auxiliar
|
| 49 |
self.gpt_model = gpt_model
|
| 50 |
self.gpt_temperature = gpt_temperature
|
| 51 |
self.prompt_gerar_documento = prompt_gerar_documento
|
|
@@ -177,16 +177,50 @@ class GerarDocumento:
|
|
| 177 |
vector_store, bm25, chunk_ids, query
|
| 178 |
)
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
)
|
| 184 |
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
self.resumo_gerado = cast(str, resumo_auxiliar_do_documento.content)
|
| 190 |
|
| 191 |
prompt_gerar_documento = PromptTemplate(
|
| 192 |
template=self.prompt_gerar_documento,
|
|
@@ -197,8 +231,8 @@ class GerarDocumento:
|
|
| 197 |
str,
|
| 198 |
llm.invoke(
|
| 199 |
prompt_gerar_documento.format(
|
| 200 |
-
documento_gerado=self.resumo_gerado,
|
| 201 |
context="\n\n".join(contexts),
|
|
|
|
| 202 |
)
|
| 203 |
).content,
|
| 204 |
)
|
|
|
|
| 36 |
chunk_overlap,
|
| 37 |
num_k_rerank,
|
| 38 |
model_cohere_rerank,
|
| 39 |
+
# prompt_auxiliar,
|
| 40 |
gpt_model,
|
| 41 |
gpt_temperature,
|
| 42 |
# id_modelo_do_usuario,
|
|
|
|
| 45 |
):
|
| 46 |
self.config = config
|
| 47 |
self.logger = logging.getLogger(__name__)
|
| 48 |
+
# self.prompt_auxiliar = prompt_auxiliar
|
| 49 |
self.gpt_model = gpt_model
|
| 50 |
self.gpt_temperature = gpt_temperature
|
| 51 |
self.prompt_gerar_documento = prompt_gerar_documento
|
|
|
|
| 177 |
vector_store, bm25, chunk_ids, query
|
| 178 |
)
|
| 179 |
|
| 180 |
+
# Prepare context and track sources
|
| 181 |
+
contexts = []
|
| 182 |
+
sources = []
|
|
|
|
| 183 |
|
| 184 |
+
# Get full documents for top results
|
| 185 |
+
for chunk_id, score in ranked_results[: self.config.num_chunks]:
|
| 186 |
+
results = vector_store.get(
|
| 187 |
+
where={"chunk_id": chunk_id}, include=["documents", "metadatas"]
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
if results["documents"]:
|
| 191 |
+
context = results["documents"][0]
|
| 192 |
+
metadata = results["metadatas"][0]
|
| 193 |
+
|
| 194 |
+
contexts.append(context)
|
| 195 |
+
sources.append(
|
| 196 |
+
{
|
| 197 |
+
"content": context,
|
| 198 |
+
"page": metadata["page"],
|
| 199 |
+
"chunk_id": chunk_id,
|
| 200 |
+
"relevance_score": score,
|
| 201 |
+
"context": metadata.get("context", ""),
|
| 202 |
+
}
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
if llm_ultimas_requests == "gpt-4o-mini":
|
| 206 |
+
llm = ChatOpenAI(
|
| 207 |
+
temperature=self.gpt_temperature,
|
| 208 |
+
model=self.gpt_model,
|
| 209 |
+
api_key=SecretStr(self.openai_api_key),
|
| 210 |
+
)
|
| 211 |
+
elif llm_ultimas_requests == "deepseek-chat":
|
| 212 |
+
llm_instance = LLM()
|
| 213 |
+
llm = llm_instance.deepseek()
|
| 214 |
+
|
| 215 |
+
# prompt_auxiliar = PromptTemplate(
|
| 216 |
+
# template=self.prompt_auxiliar, input_variables=["context"]
|
| 217 |
+
# )
|
| 218 |
+
|
| 219 |
+
# resumo_auxiliar_do_documento = llm.invoke(
|
| 220 |
+
# prompt_auxiliar.format(context="\n\n".join(contexts))
|
| 221 |
+
# )
|
| 222 |
|
| 223 |
+
# self.resumo_gerado = cast(str, resumo_auxiliar_do_documento.content)
|
| 224 |
|
| 225 |
prompt_gerar_documento = PromptTemplate(
|
| 226 |
template=self.prompt_gerar_documento,
|
|
|
|
| 231 |
str,
|
| 232 |
llm.invoke(
|
| 233 |
prompt_gerar_documento.format(
|
|
|
|
| 234 |
context="\n\n".join(contexts),
|
| 235 |
+
# modelo_usuario=serializer.data["modelo"],
|
| 236 |
)
|
| 237 |
).content,
|
| 238 |
)
|
_utils/gerar_relatorio_modelo_usuario/utils.py
CHANGED
|
@@ -28,7 +28,7 @@ def gerar_resposta_compilada(serializer):
|
|
| 28 |
"hf_embedding": serializer["hf_embedding"],
|
| 29 |
"chunk_size": serializer["chunk_size"],
|
| 30 |
"chunk_overlap": serializer["chunk_overlap"],
|
| 31 |
-
"prompt_auxiliar": serializer["prompt_auxiliar"],
|
| 32 |
"prompt_gerar_documento": serializer["prompt_gerar_documento"],
|
| 33 |
}
|
| 34 |
|
|
|
|
| 28 |
"hf_embedding": serializer["hf_embedding"],
|
| 29 |
"chunk_size": serializer["chunk_size"],
|
| 30 |
"chunk_overlap": serializer["chunk_overlap"],
|
| 31 |
+
# "prompt_auxiliar": serializer["prompt_auxiliar"],
|
| 32 |
"prompt_gerar_documento": serializer["prompt_gerar_documento"],
|
| 33 |
}
|
| 34 |
|
_utils/resumo_completo_cursor.py
CHANGED
|
@@ -66,7 +66,7 @@ async def get_llm_summary_answer_by_cursor_complete(
|
|
| 66 |
chunk_size=serializer["chunk_size"],
|
| 67 |
num_k_rerank=serializer["num_k_rerank"],
|
| 68 |
model_cohere_rerank=serializer["model_cohere_rerank"],
|
| 69 |
-
prompt_auxiliar=serializer["prompt_auxiliar"],
|
| 70 |
gpt_model=serializer["model"],
|
| 71 |
gpt_temperature=serializer["gpt_temperature"],
|
| 72 |
prompt_gerar_documento=serializer["prompt_gerar_documento"],
|
|
|
|
| 66 |
chunk_size=serializer["chunk_size"],
|
| 67 |
num_k_rerank=serializer["num_k_rerank"],
|
| 68 |
model_cohere_rerank=serializer["model_cohere_rerank"],
|
| 69 |
+
# prompt_auxiliar=serializer["prompt_auxiliar"],
|
| 70 |
gpt_model=serializer["model"],
|
| 71 |
gpt_temperature=serializer["gpt_temperature"],
|
| 72 |
prompt_gerar_documento=serializer["prompt_gerar_documento"],
|
gerar_documento/serializer.py
CHANGED
|
@@ -22,9 +22,9 @@ class GerarDocumentoSerializer(ResumoCursorSerializer):
|
|
| 22 |
required=False, default="version-test"
|
| 23 |
) # Será o valor utilizado dentro da URL da requisição pro Bubble
|
| 24 |
|
| 25 |
-
prompt_auxiliar = serializers.CharField(
|
| 26 |
-
|
| 27 |
-
)
|
| 28 |
prompt_gerar_documento = serializers.CharField(
|
| 29 |
required=False, default=prompt_gerar_documento
|
| 30 |
)
|
|
@@ -53,9 +53,9 @@ class GerarDocumentoSerializer(ResumoCursorSerializer):
|
|
| 53 |
|
| 54 |
class GerarDocumentoComPDFProprioSerializer(ResumoCursorSerializer):
|
| 55 |
system_prompt = None
|
| 56 |
-
prompt_auxiliar = serializers.CharField(
|
| 57 |
-
|
| 58 |
-
)
|
| 59 |
prompt_gerar_documento = serializers.CharField(
|
| 60 |
required=False, default=prompt_gerar_documento
|
| 61 |
)
|
|
|
|
| 22 |
required=False, default="version-test"
|
| 23 |
) # Será o valor utilizado dentro da URL da requisição pro Bubble
|
| 24 |
|
| 25 |
+
# prompt_auxiliar = serializers.CharField(
|
| 26 |
+
# required=False, default=prompt_auxiliar_padrao
|
| 27 |
+
# )
|
| 28 |
prompt_gerar_documento = serializers.CharField(
|
| 29 |
required=False, default=prompt_gerar_documento
|
| 30 |
)
|
|
|
|
| 53 |
|
| 54 |
class GerarDocumentoComPDFProprioSerializer(ResumoCursorSerializer):
|
| 55 |
system_prompt = None
|
| 56 |
+
# prompt_auxiliar = serializers.CharField(
|
| 57 |
+
# required=False, default=prompt_auxiliar_padrao
|
| 58 |
+
# )
|
| 59 |
prompt_gerar_documento = serializers.CharField(
|
| 60 |
required=False, default=prompt_gerar_documento
|
| 61 |
)
|
gerar_documento/views.py
CHANGED
|
@@ -33,9 +33,9 @@ class GerarDocumentoView(AsyncAPIView):
|
|
| 33 |
data = cast(Dict[str, Any], serializer.validated_data)
|
| 34 |
print("\n\ndata: ", data)
|
| 35 |
|
| 36 |
-
data["prompt_auxiliar"] = (
|
| 37 |
-
|
| 38 |
-
)
|
| 39 |
|
| 40 |
# listaPDFs = handle_pdf_files_from_serializer(data["files"])
|
| 41 |
listaPDFs = [l["link_arquivo"] for l in data["files"]]
|
|
|
|
| 33 |
data = cast(Dict[str, Any], serializer.validated_data)
|
| 34 |
print("\n\ndata: ", data)
|
| 35 |
|
| 36 |
+
# data["prompt_auxiliar"] = (
|
| 37 |
+
# prompt_auxiliar_inicio + "\n" + data["prompt_auxiliar"]
|
| 38 |
+
# )
|
| 39 |
|
| 40 |
# listaPDFs = handle_pdf_files_from_serializer(data["files"])
|
| 41 |
listaPDFs = [l["link_arquivo"] for l in data["files"]]
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|