Spaces:
Running
Running
open web search settgins to user
Browse files
app.py
CHANGED
|
@@ -102,6 +102,7 @@ MODELS = {
|
|
| 102 |
},
|
| 103 |
}
|
| 104 |
|
|
|
|
| 105 |
# ----- Sidebar settings -----
|
| 106 |
with st.sidebar:
|
| 107 |
st.header("⚙️ Settings")
|
|
@@ -114,6 +115,10 @@ with st.sidebar:
|
|
| 114 |
repeat_penalty = st.slider("Repetition Penalty", 1.0, 2.0, 1.1)
|
| 115 |
enable_search = st.checkbox("Enable Web Search", value=False)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# ---- Define selected model and manage its download/load ----
|
| 118 |
selected_model = MODELS[selected_model_name]
|
| 119 |
model_path = os.path.join("models", selected_model["filename"])
|
|
@@ -123,7 +128,7 @@ def try_load_model(path):
|
|
| 123 |
try:
|
| 124 |
return Llama(
|
| 125 |
model_path=path,
|
| 126 |
-
n_ctx=
|
| 127 |
n_threads=2,
|
| 128 |
n_threads_batch=1,
|
| 129 |
n_batch=256,
|
|
@@ -194,12 +199,15 @@ if user_input:
|
|
| 194 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 195 |
st.session_state.pending_response = True
|
| 196 |
|
| 197 |
-
#
|
| 198 |
-
retrieved_context =
|
|
|
|
|
|
|
|
|
|
| 199 |
st.sidebar.markdown("### Retrieved Context" if enable_search else "Web Search Disabled")
|
| 200 |
st.sidebar.text(retrieved_context or "No context found.")
|
| 201 |
|
| 202 |
-
# Build augmented query
|
| 203 |
if enable_search and retrieved_context:
|
| 204 |
augmented_user_input = (
|
| 205 |
f"{system_prompt_base.strip()}\n\n"
|
|
|
|
| 102 |
},
|
| 103 |
}
|
| 104 |
|
| 105 |
+
# ----- Sidebar settings -----
|
| 106 |
# ----- Sidebar settings -----
|
| 107 |
with st.sidebar:
|
| 108 |
st.header("⚙️ Settings")
|
|
|
|
| 115 |
repeat_penalty = st.slider("Repetition Penalty", 1.0, 2.0, 1.1)
|
| 116 |
enable_search = st.checkbox("Enable Web Search", value=False)
|
| 117 |
|
| 118 |
+
# NEW SETTINGS: Expose search configuration
|
| 119 |
+
max_results = st.number_input("Max Results for Context", min_value=1, max_value=20, value=6, step=1)
|
| 120 |
+
max_chars_per_result = st.number_input("Max Chars Per Result", min_value=100, max_value=2000, value=600, step=50)
|
| 121 |
+
|
| 122 |
# ---- Define selected model and manage its download/load ----
|
| 123 |
selected_model = MODELS[selected_model_name]
|
| 124 |
model_path = os.path.join("models", selected_model["filename"])
|
|
|
|
| 128 |
try:
|
| 129 |
return Llama(
|
| 130 |
model_path=path,
|
| 131 |
+
n_ctx=4096, # Reduced context window
|
| 132 |
n_threads=2,
|
| 133 |
n_threads_batch=1,
|
| 134 |
n_batch=256,
|
|
|
|
| 199 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 200 |
st.session_state.pending_response = True
|
| 201 |
|
| 202 |
+
# Use the new settings when retrieving web search context
|
| 203 |
+
retrieved_context = (
|
| 204 |
+
retrieve_context(user_input, max_results=max_results, max_chars_per_result=max_chars_per_result)
|
| 205 |
+
if enable_search else ""
|
| 206 |
+
)
|
| 207 |
st.sidebar.markdown("### Retrieved Context" if enable_search else "Web Search Disabled")
|
| 208 |
st.sidebar.text(retrieved_context or "No context found.")
|
| 209 |
|
| 210 |
+
# Build augmented query as before...
|
| 211 |
if enable_search and retrieved_context:
|
| 212 |
augmented_user_input = (
|
| 213 |
f"{system_prompt_base.strip()}\n\n"
|