Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -186,11 +186,25 @@ async def gen_title(request: Request):
|
|
| 186 |
return {"title": "New Chat"}
|
| 187 |
|
| 188 |
|
| 189 |
-
def build_prompt(user_input: str, history: List[Dict[str, str]]) -> str:
|
| 190 |
-
# Qwen 2.5 chat format
|
| 191 |
system = (
|
| 192 |
-
"You are Hannah 1.0, an intelligent, fast, and helpful
|
| 193 |
-
"Answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
)
|
| 195 |
|
| 196 |
parts: List[str] = ["<|im_start|>system\n" + system + "<|im_end|>\n"]
|
|
@@ -213,14 +227,18 @@ async def chat(request: Request):
|
|
| 213 |
user_input = (data.get("message") or "").strip()
|
| 214 |
model_file = data.get("model")
|
| 215 |
history = data.get("history") or []
|
|
|
|
| 216 |
|
| 217 |
if not user_input:
|
| 218 |
raise HTTPException(status_code=400, detail="Empty message")
|
| 219 |
|
| 220 |
llm = get_model(model_file)
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
def iter_response():
|
| 223 |
-
prompt = build_prompt(user_input, history)
|
| 224 |
|
| 225 |
stream = llm(
|
| 226 |
prompt,
|
|
|
|
| 186 |
return {"title": "New Chat"}
|
| 187 |
|
| 188 |
|
| 189 |
+
def build_prompt(user_input: str, history: List[Dict[str, str]], has_web_context: bool = False) -> str:
|
| 190 |
+
# Qwen 2.5 chat format with optional web context awareness
|
| 191 |
system = (
|
| 192 |
+
"You are Hannah 1.0, an intelligent, fast, and helpful AI assistant. "
|
| 193 |
+
"Answer clearly and accurately. "
|
| 194 |
+
)
|
| 195 |
+
|
| 196 |
+
# If web context is available, instruct the model to use it
|
| 197 |
+
if has_web_context:
|
| 198 |
+
system += (
|
| 199 |
+
"You have been provided with fresh web search context in the user's message. "
|
| 200 |
+
"Use this context to provide current, accurate information about recent events and dates. "
|
| 201 |
+
"Reference the sources when relevant. "
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
system += (
|
| 205 |
+
"Keep responses concise but helpful. "
|
| 206 |
+
"If asked about your model or training details, simply say: 'I'm Hannah - a helpful AI assistant.' "
|
| 207 |
+
"Do not discuss GGUF files or internal implementation details."
|
| 208 |
)
|
| 209 |
|
| 210 |
parts: List[str] = ["<|im_start|>system\n" + system + "<|im_end|>\n"]
|
|
|
|
| 227 |
user_input = (data.get("message") or "").strip()
|
| 228 |
model_file = data.get("model")
|
| 229 |
history = data.get("history") or []
|
| 230 |
+
has_web = data.get("internet", False) # Check if web search was enabled
|
| 231 |
|
| 232 |
if not user_input:
|
| 233 |
raise HTTPException(status_code=400, detail="Empty message")
|
| 234 |
|
| 235 |
llm = get_model(model_file)
|
| 236 |
+
|
| 237 |
+
# Detect if the message includes web context
|
| 238 |
+
has_web_context = has_web and "[Web context retrieved on" in user_input
|
| 239 |
|
| 240 |
def iter_response():
|
| 241 |
+
prompt = build_prompt(user_input, history, has_web_context=has_web_context)
|
| 242 |
|
| 243 |
stream = llm(
|
| 244 |
prompt,
|