Spaces:
Sleeping
Sleeping
Arif commited on
Commit ·
10e948d
1
Parent(s): 4722db8
added streaming response and conversation memory. Also added reranker, ragas. Added 1 test
Browse files- app/core/llm.py +15 -0
- pyproject.toml +2 -0
- tests/test_rag.py +10 -0
- uv.lock +0 -0
app/core/llm.py
CHANGED
|
@@ -41,3 +41,18 @@ Answer:""",
|
|
| 41 |
"question": question,
|
| 42 |
"context": context
|
| 43 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
"question": question,
|
| 42 |
"context": context
|
| 43 |
})
|
| 44 |
+
|
| 45 |
+
async def generate_stream(self, question: str, context: str):
|
| 46 |
+
"""Stream LLM responses"""
|
| 47 |
+
async for chunk in self.chain.astream({
|
| 48 |
+
"question": question,
|
| 49 |
+
"context": context
|
| 50 |
+
}):
|
| 51 |
+
yield chunk
|
| 52 |
+
|
| 53 |
+
from langchain.memory import ConversationBufferMemory
|
| 54 |
+
|
| 55 |
+
class ConversationalRAG:
|
| 56 |
+
def __init__(self, rag_chain):
|
| 57 |
+
self.rag_chain = rag_chain
|
| 58 |
+
self.memory = ConversationBufferMemory()
|
pyproject.toml
CHANGED
|
@@ -14,6 +14,8 @@ dependencies = [
|
|
| 14 |
"python-docx>=1.2.0",
|
| 15 |
"python-multipart>=0.0.20",
|
| 16 |
"qdrant-client>=1.15.1",
|
|
|
|
|
|
|
| 17 |
"sentence-transformers>=5.1.2",
|
| 18 |
"unstructured>=0.18.15",
|
| 19 |
"uvicorn>=0.38.0",
|
|
|
|
| 14 |
"python-docx>=1.2.0",
|
| 15 |
"python-multipart>=0.0.20",
|
| 16 |
"qdrant-client>=1.15.1",
|
| 17 |
+
"ragas>=0.3.7",
|
| 18 |
+
"rank-bm25>=0.2.2",
|
| 19 |
"sentence-transformers>=5.1.2",
|
| 20 |
"unstructured>=0.18.15",
|
| 21 |
"uvicorn>=0.38.0",
|
tests/test_rag.py
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from app.core.embeddings import EmbeddingGenerator
|
| 3 |
+
|
| 4 |
+
def test_embedding_generation():
|
| 5 |
+
embedder = EmbeddingGenerator("sentence-transformers/all-MiniLM-L6-v2")
|
| 6 |
+
embeddings = embedder.generate(["test text"])
|
| 7 |
+
assert len(embeddings) == 1
|
| 8 |
+
assert len(embeddings[0]) == 384
|
| 9 |
+
|
| 10 |
+
# Run tests with: uv run pytest
|
uv.lock
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|