daniel-simeone commited on
Commit ·
43951a2
1
Parent(s): 49fdc18
update model
Browse files
app.py
CHANGED
|
@@ -86,9 +86,12 @@ class MinimalistTheme(Base):
|
|
| 86 |
class RAGChatbot:
|
| 87 |
"""Chatbot with RAG capabilities."""
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
def __init__(
|
| 90 |
self,
|
| 91 |
-
model_name: str =
|
| 92 |
embedding_model: str = "all-mpnet-base-v2",
|
| 93 |
vector_store_path: str = "data/vector_store"
|
| 94 |
):
|
|
@@ -100,8 +103,8 @@ class RAGChatbot:
|
|
| 100 |
embedding_model: Model for document embeddings
|
| 101 |
vector_store_path: Path to saved vector store
|
| 102 |
"""
|
| 103 |
-
self.model_name = model_name
|
| 104 |
-
|
| 105 |
# Initialize Inference API client
|
| 106 |
hf_token = os.environ.get("HF_TOKEN")
|
| 107 |
# Debug: report HF_TOKEN status (masked)
|
|
@@ -114,10 +117,10 @@ class RAGChatbot:
|
|
| 114 |
print(f"[DEBUG] HF_TOKEN: set (length={len(hf_token)}, masked={masked})")
|
| 115 |
print("HF_TOKEN found. Inference API ready.")
|
| 116 |
|
| 117 |
-
print(f"[DEBUG] Initializing Inference API client for model: {model_name}")
|
| 118 |
try:
|
| 119 |
self.inference_client = InferenceClient(
|
| 120 |
-
model=model_name,
|
| 121 |
token=hf_token
|
| 122 |
)
|
| 123 |
print("[DEBUG] Inference API client initialized successfully (using chat_completion for this model)")
|
|
@@ -211,6 +214,13 @@ Answer:"""
|
|
| 211 |
raise ValueError("Empty response from model")
|
| 212 |
except Exception as api_error:
|
| 213 |
print(f"[DEBUG] RAG generation failed: {type(api_error).__name__}: {api_error}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
# Fallback: return formatted chunks with note
|
| 215 |
response_parts = []
|
| 216 |
response_parts.append("I retrieved relevant information, but couldn't generate a synthesized answer. Here are the relevant chunks:\n\n")
|
|
|
|
| 86 |
class RAGChatbot:
|
| 87 |
"""Chatbot with RAG capabilities."""
|
| 88 |
|
| 89 |
+
# Default model: use one supported by HF Inference API (Mistral often requires enabled providers)
|
| 90 |
+
DEFAULT_CHAT_MODEL = "HuggingFaceH4/zephyr-7b-beta"
|
| 91 |
+
|
| 92 |
def __init__(
|
| 93 |
self,
|
| 94 |
+
model_name: str = None,
|
| 95 |
embedding_model: str = "all-mpnet-base-v2",
|
| 96 |
vector_store_path: str = "data/vector_store"
|
| 97 |
):
|
|
|
|
| 103 |
embedding_model: Model for document embeddings
|
| 104 |
vector_store_path: Path to saved vector store
|
| 105 |
"""
|
| 106 |
+
self.model_name = model_name if model_name else self.DEFAULT_CHAT_MODEL
|
| 107 |
+
|
| 108 |
# Initialize Inference API client
|
| 109 |
hf_token = os.environ.get("HF_TOKEN")
|
| 110 |
# Debug: report HF_TOKEN status (masked)
|
|
|
|
| 117 |
print(f"[DEBUG] HF_TOKEN: set (length={len(hf_token)}, masked={masked})")
|
| 118 |
print("HF_TOKEN found. Inference API ready.")
|
| 119 |
|
| 120 |
+
print(f"[DEBUG] Initializing Inference API client for model: {self.model_name}")
|
| 121 |
try:
|
| 122 |
self.inference_client = InferenceClient(
|
| 123 |
+
model=self.model_name,
|
| 124 |
token=hf_token
|
| 125 |
)
|
| 126 |
print("[DEBUG] Inference API client initialized successfully (using chat_completion for this model)")
|
|
|
|
| 214 |
raise ValueError("Empty response from model")
|
| 215 |
except Exception as api_error:
|
| 216 |
print(f"[DEBUG] RAG generation failed: {type(api_error).__name__}: {api_error}")
|
| 217 |
+
err_str = str(api_error).lower()
|
| 218 |
+
if "model_not_supported" in err_str or "not supported by any provider" in err_str:
|
| 219 |
+
return (
|
| 220 |
+
"The current chat model isn't available with your Inference API providers. "
|
| 221 |
+
"Try using the default model (Zephyr) or enable a provider for your chosen model at "
|
| 222 |
+
"https://huggingface.co/settings/inference-api."
|
| 223 |
+
)
|
| 224 |
# Fallback: return formatted chunks with note
|
| 225 |
response_parts = []
|
| 226 |
response_parts.append("I retrieved relevant information, but couldn't generate a synthesized answer. Here are the relevant chunks:\n\n")
|