Spaces:
Sleeping
Sleeping
Quincy Hsieh commited on
Commit Β·
c8361c5
1
Parent(s): 1974292
Fix error LLM API call failed: 404 Client Error: Not Found for url...
Browse filesFiles changed (3)
- README.md+15-9
- app.py+5-2
- prompts/rag_prompt.txt+5-6
58 unmodified lines5960616263646578 unmodified lines144145146147148149150151152153154155156157158159160161162163164165171 unmodified lines33733833934034134234336 unmodified lines38038138238338438558 unmodified linesβ ββββββββββββββββββββ βββββββββββββββββββ ββ β HF Inference β β Sentence β ββ β API (LLM) β β Transformers β ββ β Zephyr-7B β β (Embeddings) β ββ ββββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ```78 unmodified linesCombine retrieved context with the user's question and generate an answer.1. **Build prompt** β Load the template from [`prompts/rag_prompt.txt`](prompts/rag_prompt.txt), inject retrieved context and the user's question2. **Call LLM API** β Send the prompt to the Hugging Face Inference API (Zephyr-7B)3. **Return response** β The LLM generates an answer grounded in the provided contextThe prompt template (`prompts/rag_prompt.txt`):```<|system|>You are a helpful assistant. Answer the user's question based ONLY on the provided context.If the context does not contain enough information to answer, say "I don't have enough information to answer this question."Always be concise and factual.</s><|user|>Context:{context}Question: {question}</s><|assistant|>```The template is loaded once at startup and filled at query time:171 unmodified lines|---|---|---|| `HF_TOKEN` | (Space Secret) | Hugging Face API token for Inference API || `EMBEDDING_MODEL_NAME` | `sentence-transformers/all-MiniLM-L6-v2` | Model for text embeddings || `LLM_MODEL_NAME` | `HuggingFaceH4/zephyr-7b-beta` | LLM for answer generation || `CHROMA_PERSIST_DIR` | `./chroma_db` | ChromaDB storage path || `CHUNK_SIZE` | `512` | Text chunk size in characters || `CHUNK_OVERLAP` | `50` | Overlap between chunks |36 unmodified lines## Troubleshooting### SSL Certificate Verification ErrorIf you see an error like the one below when running `python app.py`, your machine is most likely behind a **corporate proxy that performs SSL inspection** and has its own root CA that Python does not trust by default.58 unmodified lines5960616263646578 unmodified lines144145146147148149150151152153154155156157158159160161162163171 unmodified lines33533633733833934034136 unmodified lines37837938038138238338438538638738838939039158 unmodified linesβ ββββββββββββββββββββ βββββββββββββββββββ ββ β HF Inference β β Sentence β ββ β API (LLM) β β Transformers β ββ β Mistral-7B β β (Embeddings) β ββ ββββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ```78 unmodified linesCombine retrieved context with the user's question and generate an answer.1. **Build prompt** β Load the template from [`prompts/rag_prompt.txt`](prompts/rag_prompt.txt), inject retrieved context and the user's question2. **Call LLM API** β Send the prompt to the Hugging Face Inference API (Mistral-7B-Instruct-v0.3)3. **Return response** β The LLM generates an answer grounded in the provided contextThe prompt template (`prompts/rag_prompt.txt`):```<s>[INST] You are a helpful assistant. Answer the user's question based ONLY on the provided context.If the context does not contain enough information to answer, say "I don't have enough information to answer this question."Always be concise and factual.Context:{context}Question: {question} [/INST]```The template is loaded once at startup and filled at query time:171 unmodified lines|---|---|---|| `HF_TOKEN` | (Space Secret) | Hugging Face API token for Inference API || `EMBEDDING_MODEL_NAME` | `sentence-transformers/all-MiniLM-L6-v2` | Model for text embeddings || `LLM_MODEL_NAME` | `mistralai/Mistral-7B-Instruct-v0.3` | LLM for answer generation || `CHROMA_PERSIST_DIR` | `./chroma_db` | ChromaDB storage path || `CHUNK_SIZE` | `512` | Text chunk size in characters || `CHUNK_OVERLAP` | `50` | Overlap between chunks |36 unmodified lines## Troubleshooting### ChromaDB Telemetry ErrorIf you see `capture() takes 1 positional argument but 3 were given` in the logs, it is a version incompatibility between ChromaDB and the `posthog` library. Telemetry is disabled at startup (`anonymized_telemetry=False`) so this error should no longer appear. If it persists after updating dependencies, pin `posthog<3.0` in `requirements.txt`.### LLM 404 β Model Not FoundIf the `/query` endpoint logs a `404 Not Found` for the Inference API URL, the configured model has been removed from the free serverless tier. Update `LLM_MODEL_NAME` in `app.py` to an available model and adjust `prompts/rag_prompt.txt` to match its instruction format. The current default (`mistralai/Mistral-7B-Instruct-v0.3`) uses the `<s>[INST] β¦ [/INST]` format.### SSL Certificate Verification ErrorIf you see an error like the one below when running `python app.py`, your machine is most likely behind a **corporate proxy that performs SSL inspection** and has its own root CA that Python does not trust by default.
38 unmodified lines3940414243444535 unmodified lines8182838485868738 unmodified lines# ---------------------------------------------------------------------------EMBEDDING_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2"LLM_MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"CHROMA_PERSIST_DIR = "./chroma_db"COLLECTION_NAME = "rag_documents"CHUNK_SIZE = 51235 unmodified lines# because it requires no external database service.logger.info(f"Initializing ChromaDB at: {CHROMA_PERSIST_DIR}")chroma_client = chromadb.PersistentClient(path=CHROMA_PERSIST_DIR)collection = chroma_client.get_or_create_collection(name=COLLECTION_NAME,metadata={"hnsw:space": "cosine"},38 unmodified lines3940414243444535 unmodified lines8182838485868788899038 unmodified lines# ---------------------------------------------------------------------------EMBEDDING_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2"LLM_MODEL_NAME = "mistralai/Mistral-7B-Instruct-v0.3"CHROMA_PERSIST_DIR = "./chroma_db"COLLECTION_NAME = "rag_documents"CHUNK_SIZE = 51235 unmodified lines# because it requires no external database service.logger.info(f"Initializing ChromaDB at: {CHROMA_PERSIST_DIR}")chroma_client = chromadb.PersistentClient(path=CHROMA_PERSIST_DIR,settings=Settings(anonymized_telemetry=False),)collection = chroma_client.get_or_create_collection(name=COLLECTION_NAME,metadata={"hnsw:space": "cosine"},
12345678910<|system|>You are a helpful assistant. Answer the user's question based ONLY on the provided context.If the context does not contain enough information to answer, say "I don't have enough information to answer this question."Always be concise and factual.</s><|user|>Context:{context}Question: {question}</s><|assistant|>123456789<s>[INST] You are a helpful assistant. Answer the user's question based ONLY on the provided context.If the context does not contain enough information to answer, say "I don't have enough information to answer this question."Always be concise and factual.Context:{context}Question: {question} [/INST]
README.md+15-9
app.py+5-2
prompts/rag_prompt.txt+5-6