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