Skip to content

Commit

Permalink
fix: streamlit fetch data
Browse files Browse the repository at this point in the history
  • Loading branch information
leoguillaumegouv committed Sep 16, 2024
1 parent 510cbdc commit 0b8e735
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/helpers/_vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_collection_metadata(self, collection_names: List[str] = [], type: str =

# sort by updated_at and remove duplicates collections with same names (keep the latest version), concerns only public collections
sorted_data = sorted(metadata, key=lambda x: x.payload.get("updated_at", 0), reverse=False)
metadata = list({item.payload["name"]: item for item in sorted_data}.values())
metadata = list({item.payload["name"]: item for item in sorted_data if "name" in item.payload}.values())

for i in range(len(metadata)):
metadata[i] = CollectionMetadata(
Expand Down
4 changes: 2 additions & 2 deletions app/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._baserag import BaseRAG
from ._sppfewshots import SPPFewShots
from ._fewshots import FewShots

__all__ = ["BaseRAG", "SPPFewShots"]
__all__ = ["BaseRAG", "FewShots"]
7 changes: 4 additions & 3 deletions app/tools/_sppfewshots.py → app/tools/_fewshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from app.schemas.tools import ToolOutput


class SPPFewShots:
class FewShots:
"""
Service Public Plus Fewshots RAG.
Fewshots RAG.
Args:
embeddings_model (str): OpenAI embeddings model
collection (str): Collection name. The collection must have question/answer pairs in metadata.
k (int, optional): Top K per collection. Defaults to 4.
"""

Expand Down Expand Up @@ -56,7 +57,7 @@ async def get_prompt(
results = vectorstore.search(collection_names=[collection.name], prompt=prompt, k=k, model=embeddings_model)

context = "\n\n\n".join([
f"Question: {result.payload.get('description', 'N/A')}\n" f"Réponse: {result.payload.get('reponse', 'N/A')}" for result in results
f"Question: {result.payload.get('question', 'N/A')}\n" f"Réponse: {result.payload.get('answer', 'N/A')}" for result in results
])

prompt = self.DEFAULT_PROMPT_TEMPLATE.format(context=context, prompt=prompt)
Expand Down
20 changes: 9 additions & 11 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ services:
volumes:
- .:/home/albert/conf # a config.yml file should be in this folder

streamlit:
image: ghcr.io/etalab-ia/albert-api/ui:latest
command: ["streamlit", "run", "chat.py", "--server.port=8501", "--browser.gatherUsageStats", "false", "--theme.base", "light"]
restart: always
environment:
- BASE_URL=http://fastapi:8000/v1
ports:
- 8501:8501

qdrant:
image: qdrant/qdrant:v1.9.7-unprivileged
restart: always
Expand Down Expand Up @@ -54,17 +63,6 @@ services:
timeout: 10s
retries: 5

streamlit:
image: ghcr.io/etalab-ia/albert-api/ui:latest
command: ["streamlit", "run", "app.py", "--server.port=8501", "--browser.gatherUsageStats", "false", "--theme.base", "light"]
restart: always
environment:
- BASE_URL=http://fastapi:8000/v1
ports:
- 8501:8501
depends_on:
- fastapi

volumes:
qdrant:
minio:
Expand Down
2 changes: 1 addition & 1 deletion docs/deploiement.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ Voici les types de base de données supportées, à configurer dans le fichier d
2. Exécutez l'application Streamlit

```bash
streamlit run ui/app.py
streamlit run ui/chat.py --server.port 8501 --browser.gatherUsageStats false --theme.base light
```

0 comments on commit 0b8e735

Please sign in to comment.