Update backend/main.py
Browse files- backend/main.py +4 -4
backend/main.py
CHANGED
|
@@ -39,7 +39,8 @@ app.add_middleware(
|
|
| 39 |
HF_EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 40 |
|
| 41 |
# Inicializa o modelo Groq
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
# Inicializa o HuggingFaceEmbeddings na CPU
|
| 45 |
embeddings = HuggingFaceEmbeddings(
|
|
@@ -109,8 +110,8 @@ async def upload_document(file: UploadFile = File(...)):
|
|
| 109 |
vectorstore = FAISS.from_documents(documents=splits, embedding=embeddings)
|
| 110 |
retriever = vectorstore.as_retriever(search_kwargs={"k": 4})
|
| 111 |
|
| 112 |
-
# 5. Criar a nova Chain RAG
|
| 113 |
-
#
|
| 114 |
rag_chain = (
|
| 115 |
RunnablePassthrough.assign(
|
| 116 |
context=(lambda x: x["input"]) | retriever | format_docs
|
|
@@ -150,7 +151,6 @@ async def chat(request: ChatRequest):
|
|
| 150 |
async def stream_generator():
|
| 151 |
try:
|
| 152 |
# 'astream' é o método de streaming assíncrono do LangChain
|
| 153 |
-
# Passamos {"input": ...} que será interceptado pelo lambda definido acima
|
| 154 |
async for chunk in current_chain.astream({"input": request.content}):
|
| 155 |
if chunk:
|
| 156 |
yield chunk
|
|
|
|
| 39 |
HF_EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 40 |
|
| 41 |
# Inicializa o modelo Groq
|
| 42 |
+
# CORREÇÃO AQUI: Atualizado para 'llama-3.3-70b-versatile' pois o mixtral foi descontinuado
|
| 43 |
+
model = ChatGroq(model=os.getenv("GROQ_MODEL", "llama-3.3-70b-versatile"))
|
| 44 |
|
| 45 |
# Inicializa o HuggingFaceEmbeddings na CPU
|
| 46 |
embeddings = HuggingFaceEmbeddings(
|
|
|
|
| 110 |
vectorstore = FAISS.from_documents(documents=splits, embedding=embeddings)
|
| 111 |
retriever = vectorstore.as_retriever(search_kwargs={"k": 4})
|
| 112 |
|
| 113 |
+
# 5. Criar a nova Chain RAG
|
| 114 |
+
# Correção mantida: lambda para extrair 'input' do dicionário
|
| 115 |
rag_chain = (
|
| 116 |
RunnablePassthrough.assign(
|
| 117 |
context=(lambda x: x["input"]) | retriever | format_docs
|
|
|
|
| 151 |
async def stream_generator():
|
| 152 |
try:
|
| 153 |
# 'astream' é o método de streaming assíncrono do LangChain
|
|
|
|
| 154 |
async for chunk in current_chain.astream({"input": request.content}):
|
| 155 |
if chunk:
|
| 156 |
yield chunk
|