refactor: final code purge

This commit is contained in:
cra88y
2026-01-10 21:23:08 -06:00
parent 290126a99b
commit 28f946736d
2 changed files with 12 additions and 14 deletions
+11 -13
View File
@@ -36,13 +36,11 @@ class SXNGPlugin(Plugin):
return Response("Error: Missing Key or Query", status=400)
prompt = (
f"SYSTEM: Answer USER QUERY by integrating SEARCH RESULTS with expert knowledge.\n"
f"HIERARCHY: Use RESULTS for facts/data. Use KNOWLEDGE for context/synthesis.\n"
f"CONSTRAINTS: <4 sentences | Dense information | Complete thoughts.\n"
f"FALLBACK: If results are empty, answer from knowledge but note the lack of sources.\n\n"
f"SEARCH RESULTS:\n{context_text}\n\n"
f"USER QUERY: {q}\n\n"
f"ANSWER:"
f"Answer concisely (<4 sentences) using the provided search results.\n"
f"Prioritize results for facts. If results are empty, use general knowledge.\n\n"
f"Results:\n{context_text}\n\n"
f"Query: {q}\n\n"
f"Answer:"
)
def generate_gemini():
@@ -100,7 +98,7 @@ class SXNGPlugin(Plugin):
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
"HTTP-Referer": "https://github.com/cra88y/searxng-stream-gemini",
"X-Title": "SearXNG Gemini Stream"
"X-Title": "SearXNG Stream"
}
conn.request("POST", "/api/v1/chat/completions", body=json.dumps(payload), headers=headers)
res = conn.getresponse()
@@ -142,15 +140,15 @@ class SXNGPlugin(Plugin):
js_q = json.dumps(search.search_query.query)
html_payload = f'''
<article id="ai-shell" class="answer" style="display:none; margin-bottom: 1rem;">
<p id="ai-out" style="white-space: pre-wrap;"></p>
<article id="sxng-stream-box" class="answer" style="display:none; margin-bottom: 1rem;">
<p id="sxng-stream-data" style="white-space: pre-wrap;"></p>
</article>
<script>
(async () => {{
const q = {js_q};
const b64 = "{b64_context}";
const shell = document.getElementById('ai-shell');
const out = document.getElementById('ai-out');
const shell = document.getElementById('sxng-stream-box');
const data = document.getElementById('sxng-stream-data');
try {{
const ctx = new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0)));
@@ -172,7 +170,7 @@ class SXNGPlugin(Plugin):
const chunk = decoder.decode(value);
if (chunk) {{
if (shell.style.display === 'none') shell.style.display = 'block';
out.innerText += chunk;
data.innerText += chunk;
}}
}}
}} catch (e) {{ console.error(e); }}
+1 -1
View File
@@ -110,7 +110,7 @@ class PluginTestCase(unittest.TestCase):
def test_html_injection(self):
response = self.app.get('/')
content = response.data.decode('utf-8')
self.assertIn('<article id="ai-shell"', content)
self.assertIn('<article id="sxng-stream-box"', content)
self.assertIn('/gemini-stream', content)
def test_stream_endpoint(self):