Compare commits

...

44 Commits

Author SHA1 Message Date
tyler ad8f1397bc Fixed intent in the dev server 2026-05-19 15:20:06 -04:00
Tyler bda9e5a462 Fixing Intent in Dev.py 2026-05-19 14:30:42 -04:00
TySS-Dev f471140bd6 Upload files to "dev" 2026-05-19 06:01:19 -04:00
TySS-Dev 68ff90b655 Upload files to "/" 2026-05-19 06:01:01 -04:00
TySS-Dev 6daf947d00 Delete directory 'tests' 2026-05-19 03:09:34 -04:00
tyler af3e74c92a Moved dev.py to dev/ 2026-05-19 03:09:18 -04:00
tyler 7e06e07e4f moved an import line to the top 2026-05-19 03:08:57 -04:00
tyler 8b7c8f7df8 Adding base64 import back 2026-05-19 02:59:01 -04:00
tyler 93d263cdc3 Cleaning up code 2026-05-19 02:56:01 -04:00
tyler b914d13d4e Removing the boarder around model dropdown 2026-05-19 02:48:10 -04:00
tyler eee0fd8709 Revert ollama_answers.py to theme-aware state before border animation 2026-05-19 02:46:56 -04:00
tyler baec4522cf Fixing a animation around the input box 2026-05-19 02:43:27 -04:00
tyler 1702d9cd20 Fixing a animation around the input box 2026-05-19 02:40:42 -04:00
tyler 2a5a501a96 Fixing a animation around the input box 2026-05-19 02:39:00 -04:00
tyler 64aa62f5e0 Fixing a animation around the input box 2026-05-19 02:35:05 -04:00
tyler 378a485ba7 Adding a animation around the input box 2026-05-19 02:32:53 -04:00
tyler f66264b92a Attempting to make elements theme aware 2026-05-19 02:23:26 -04:00
tyler ff3b75d129 Attempting to make elements theme aware 2026-05-19 02:20:49 -04:00
tyler 08d4915d4a Attempting to make elements theme aware 2026-05-19 02:16:12 -04:00
tyler ce42f9a652 Attempting to make elements theme aware 2026-05-19 02:12:18 -04:00
tyler 9e784c8b8b Attempting to make elements theme aware 2026-05-19 02:07:25 -04:00
tyler 8e7752c2de Updated Issues in README 2026-05-19 02:07:01 -04:00
tyler 78941479db Reworking css 2026-05-19 01:49:18 -04:00
tyler 83494bb023 Reworking our injection 2026-05-19 00:05:50 -04:00
tyler e46c752aec Maybe working divider 2026-05-19 00:02:29 -04:00
tyler 541d98f7f1 Maybe working divider 2026-05-18 23:56:23 -04:00
tyler 4c749b825c Fixing conversation history and couldn't figure out how to remove SearXNG info box so just adding a smart divider 2026-05-18 23:53:04 -04:00
tyler 23ecac6afa Fixed mayber 2026-05-18 23:14:22 -04:00
Tyler 4b36a261c4 Attempting to fix conversation history 2026-05-18 15:11:18 -04:00
TySS-Dev eeac7fcd88 Added more known issues 2026-05-17 20:13:19 -04:00
TySS-Dev 1c3824b7a4 Fixed typo 2026-05-17 20:01:43 -04:00
TySS-Dev a7c031d27b Fixed check boxes 2026-05-17 20:00:56 -04:00
TySS-Dev 5e2b2a246f Added known issues and roadmap 2026-05-17 19:59:55 -04:00
TySS-Dev ffad0de8ae Fixed flow diagram 2026-05-17 19:51:19 -04:00
TySS-Dev 3dffeb384b Fixed a typo in README 2026-05-17 19:46:04 -04:00
TySS-Dev 85d1481bd9 Updated README 2026-05-17 19:45:37 -04:00
Tyler 904cf945a2 Updated README 2026-05-17 16:07:00 -04:00
Tyler b3dc603b94 Better markdown support 2026-05-17 16:02:31 -04:00
Tyler 4e2f9d97d7 Adding intent based prompting 2026-05-17 15:53:44 -04:00
Tyler 1f7d54590f Adding conversation memory 2026-05-17 15:44:53 -04:00
Tyler 2ed6a0aae9 Result filtering by relevance and RAG with chucnking logic 2026-05-17 15:27:21 -04:00
Tyler 9d6d4ec160 Fixing content not loading 2026-05-17 15:19:44 -04:00
Tyler e4880a7a51 Adding debug logic 2026-05-17 15:17:44 -04:00
Tyler 332834a126 Adding better AI response streaming logic 2026-05-17 15:11:01 -04:00
7 changed files with 2664 additions and 674 deletions
+1
View File
@@ -3,6 +3,7 @@ __pycache__/
*$py.class
venv/
.env
dev/.env
.idea/
.vscode/
.agent/
+169 -35
View File
@@ -10,51 +10,87 @@
A SearXNG plugin that generates local AI overviews powered by Ollama, using search results as RAG context.
Features:
- Token-by-token UI streaming
- Clickable inline citations
- Interactive mode: continue summary, ask follow-ups, copy, or regenerate
- Simple response mode with no extras
- Internally called low-latency RAG for follow-ups (bypasses HTTP loopback)
- Native network integration via `searx.network` (respects proxy/SSL settings)
- Stateless conversation persistence/shareability via URL hash
- Model selector in the AI overview widget
- Does not slow down result loading
- One file install
## Features:
## Installation
- Inline numbered citations
- Interactive mode - Continue summary, ask follow-ups, copy, or regenerate
- Overview of ranked results with prompts based on detected query intent:
- `How To` `Technical` `Factual` `Comparison` `Opinion` `Current` `Local` `Geneal`
- Internally called RAG for follow-ups
- Native network integration via `searx.network`
- Stateless conversation presistence/shareability via URL hash
- Ollama model selector
- Feeds fetched results to Ollama without slowing down SearXNG results
- Real-time streaming via Valkey (No waiting for a completed response)
- TF-IDF result ranking before being sent to Ollama
- Smart chunking - Pages are split into 512-token segments and highest-scoring chunk per page used for context
- Conversation memory - 30-minute cross-search conversation history via Valkey for follow-up questions
- Markdown support
- Intent emoji badge showing what intent prompt was used
Place `ollama_answers.py` into the `searx/plugins` directory of your SearXNG instance (or mount it in a container) and enable it in `settings.yml`:
## Install
```yaml
plugins:
1. Download the plugin:
### Main repo (Gitea)
```bash
curl -o ollama_answers.py https://git.tysstech.com/TySS-Dev/ollama-ai-answers-searxng/raw/branch/main/ollama_answers.py
```
### Mirror repo (Github):
```bash
curl -o ollama_answers.py https://raw.githubusercontent.com/TySP-Dev/ollama-ai-answers-searxng/main/ollama_answers.py
```
3. Copy to your SearXNG plugins directory:
```bash
cp ollama_answers.py path_to/searxng/plugins/ollama_answers.py
```
4. Add the volume mount to your `docker-compose.yml` under the searxng service:
```yaml
volumes:
- ./plugins/ollama_answers.py:/usr/local/searxng/searx/plugins/ollama_answers.py:Z
```
5. Add environment variables to `docker-compose.yml`:
```yaml
environment:
- LLM_URL=http://ollama:11434/v1/chat/completions
- LLM_MODEL=qwen3.5:9b
- VALKEY_HOST=searxng-valkey
```
6. Add to `settings.yml` plugins section:
```yaml
plugins:
searx.plugins.ollama_answers.SXNGPlugin:
active: true
```
```
7. Restart SearXNG:
```bash
docker compose up -d --force-recreate core
```
## Configuration
Configure via environment variables.
### Required
| Variable | Description | Default |
| Variable | Default | Description |
|---|---|---|
| `LLM_URL` | Ollama chat completions endpoint | `http://ollama:11434/v1/chat/completions` |
| `LLM_MODEL` | Model name as listed in Ollama | `qwen3.5:9b` |
### Optional
| Variable | Description | Default |
|---|---|---|
| `LLM_SYSTEM_PROMPT` | Overrides the default system prompt | `You are a direct, citation-accurate search synthesis engine.` |
| `LLM_MAX_TOKENS` | Max tokens in the AI response | `200` |
| `LLM_TEMPERATURE` | Sampling temperature | `0.2` |
| `LLM_CONTEXT_DEEP_COUNT` | Results used with full snippets | `5` |
| `LLM_CONTEXT_SHALLOW_COUNT` | Results with headlines only (breadth) | `15` |
| `LLM_TABS` | Comma-delimited tab whitelist | `general,science,it,news` |
| `LLM_INTERACTIVE` | Interactive UI mode (copy, regenerate, follow-up) | `true` |
| `LLM_QUESTION_MARK_REQUIRED` | Only trigger on queries containing `?` | `false` |
| `LLM_URL` | `http://ollama:11434/v1/chat/completions` | Ollama endpoint |
| `LLM_MODEL` | `qwen3.5:9b` | Default model |
| `LLM_MAX_TOKENS` | `200` | Max response tokens |
| `LLM_TEMPERATURE` | `0.2` | Response temperature |
| `LLM_TABS` | `general,science,it,news` | Tabs to show AI overview on |
| `LLM_QUESTION_MARK_REQUIRED` | `false` | Only trigger on queries with `?` |
| `LLM_INTERACTIVE` | `true` | Show copy/regen/follow-up UI |
| `LLM_SYSTEM_PROMPT` | *(built-in)* | Override the system prompt |
| `LLM_CONTEXT_DEEP_COUNT` | `5` | Full-content results to fetch |
| `LLM_CONTEXT_SHALLOW_COUNT` | `15` | Headline-only results |
| `VALKEY_HOST` | `searxng-valkey` | Valkey container hostname |
| `VALKEY_PORT` | `6379` | Valkey port |
## How It Works
@@ -66,6 +102,92 @@ Configure via environment variables.
6. Client-side script calls a signed endpoint (`/ai-stream`)
7. Ollama streams a response token-by-token in the UI
## Known Issues
- [ ] Update README with all updates
- [x] When asking a follow up question the previous output disappears
- [x] Parts of the UI are not theme aware resulting in a unpolished look when not using a dark theme
- [x] When SearXNG provides a info blob for a search it appears on top of the overview i.e. `Wikipedia` or `Linux`
For any issues not stated here please create an issue ticket on [Gitea](https://git.tysstech.com/TySS-Dev/ollama-ai-answers-searxng/issues) or [GitHub](https://github.com/TySP-Dev/ollama-ai-answers-searxng/issues) and add the `bug` tag.
## Roadmap
### Dev Server
- [x] Stream viewer — show tokens arriving in real time in the debug panel as they come out of Valkey, so you can see exactly what the LLM is generating chunk by chunk
- [x] TF-IDF score visualizer — show a table of which URLs were fetched, their scores, and which chunks were selected for context
- [ ] Intent detection display — show what intent was detected and which system prompt was used for each query
- [ ] Saved queries — save/load test queries so you can quickly re-run the same set of searches after making changes to the plugin
- [ ] A/B model comparison — run the same query against two different models simultaneously and show both responses side by side
- [ ] Response time breakdown — show how long each phase took: SearXNG fetch, page fetching, TF-IDF scoring, LLM stream start, stream complete
- [ ] Context inspector — show the full assembled context string that gets sent to the LLM, so you can see exactly what it's working with
- [ ] Prompt viewer — show the full system prompt + user prompt that gets sent to Ollama
- [ ] Export button — copy the full context + prompt + response as a JSON blob for bug reports
- [ ] Per-intent system prompt editor — edit the system prompts for each intent type live without restarting
- [ ] Token counter — show estimated token count of the context being sent
### Plugin
- [ ] Working on feature plans
## Architecture
```
┌─────────────────────────────────────────────────────┐
│ Browser │
│ POST /ai-stream → GET /ai-status/{id} (poll 150ms) │
└────────────────┬────────────────────────────────────┘
┌────────────────▼────────────────────────────────────┐
│ SearXNG + Plugin │
│ │
│ post_search() │
│ → _enrich_results() ← ThreadPoolExecutor │
│ → _fetch_page_text() × 5 parallel │
│ → _chunk_text() + _tfidf_score() │
│ → rerank by score │
│ → _assemble_context() │
│ → inject AI Overview HTML + JS │
│ │
│ /ai-stream │
│ → validate token │
│ → _detect_intent() → select system prompt │
│ → _load_conversation() from Valkey │
│ → launch stream_to_valkey() thread │
│ → return {job_id} immediately │
│ │
│ stream_to_valkey() [background thread] │
│ → Ollama stream=True │
│ → RPUSH tokens to Valkey │
│ → RPUSH __DONE__ when complete │
│ │
│ /ai-status/{job_id} │
│ → LRANGE chunks from offset │
│ → return {chunks, done} │
└────────────────┬────────────────────────────────────┘
┌────────────────▼────────────────────────────────────┐
│ Valkey │
│ ai:job:{id}:chunks (list, TTL 120s) │
│ ai:job:{id}:status (string, TTL 120s) │
│ ai:conv:{session} (JSON, TTL 1800s) │
└─────────────────────────────────────────────────────┘
```
## Docker Compose Example
```yaml
@@ -74,6 +196,7 @@ services:
environment:
- LLM_URL=http://ollama:11434/v1/chat/completions
- LLM_MODEL=qwen3.5:9b
- VALKEY_HOST=searxng-valkey
volumes:
- ./ollama_answers.py:/usr/local/searxng/searx/plugins/ollama_answers.py
@@ -96,6 +219,17 @@ environment:
- LLM_API_KEY=your-bearer-token
```
## Project Structure
```
ollama-ai-answers-searxng/
├── ollama_answers.py # single plugin file — all logic here
├── README.md
├── requirements.txt # flask, flask-babel (for local dev only)
└── tests/
└── dev.py # local dev server
```
## Development — Dev Server
A standalone Flask dev server is included in `tests/dev.py`. It mocks the SearXNG plugin environment so you can test the full UI without a running SearXNG instance.
@@ -124,7 +258,7 @@ Then open [http://127.0.0.1:5000/](http://127.0.0.1:5000/) in your browser.
### Environment Variables (dev)
The dev reads the same variables as the plugin:
The dev server reads the same variables as the plugin:
```bash
LLM_URL=http://localhost:11434/v1/chat/completions \
+39
View File
@@ -0,0 +1,39 @@
# AI Answers Plugin — Dev Server Config
# Copy this to .env and fill in your values
# .env is gitignored and never committed
# Ollama endpoint (required)
LLM_URL=http://localhost:11434/v1/chat/completions
# Default model
LLM_MODEL=qwen3.5:9b
# Max response tokens
LLM_MAX_TOKENS=200
# Response temperature (0.0 - 2.0)
LLM_TEMPERATURE=0.2
# Bearer token for authenticated LLM endpoints
# Leave empty if no Bearer token is needed for your server
LLM_API_KEY=
# Live SearXNG instance for real search results
# Leave empty to use mock results
SEARXNG_URL=
# Valkey for streaming (required)
# Start with: docker run -d --name dev-valkey -p 6379:6379 valkey/valkey:9-alpine
VALKEY_HOST=localhost
VALKEY_PORT=6379
# Dev server host and port
DEV_HOST=127.0.0.1
DEV_PORT=5000
# Plugin settings
LLM_INTERACTIVE=true
LLM_QUESTION_MARK_REQUIRED=false
LLM_TABS=general,science,it,news
LLM_CONTEXT_DEEP_COUNT=5
LLM_CONTEXT_SHALLOW_COUNT=15
+1482
View File
File diff suppressed because it is too large Load Diff
+888 -210
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -1,3 +1,5 @@
flask
flask-babel
certifi
python-dotenv
valkey
-346
View File
@@ -1,346 +0,0 @@
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import logging
from types import ModuleType
from flask import Flask, request, redirect
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
os.environ.setdefault('LLM_URL', 'http://localhost:11434/v1/chat/completions')
# SearXNG module mocks
searx = ModuleType("searx")
searx_plugins = ModuleType("searx.plugins")
searx_results = ModuleType("searx.result_types")
class MockPlugin:
def __init__(self, cfg):
self.active = getattr(cfg, 'active', True)
class MockPluginInfo:
def __init__(self, **kwargs):
self.meta = kwargs
class MockEngineResults:
def __init__(self):
self.types = ModuleType("types")
self.types.Answer = lambda *args, **kwargs: kwargs.get('answer', args[0] if args else "")
self._results = []
def add(self, res):
self._results.append(res)
searx_plugins.Plugin = MockPlugin
searx_plugins.PluginInfo = MockPluginInfo
searx_results.EngineResults = MockEngineResults
searx.settings = {'server': {'secret_key': 'demo-secret'}}
searx.network = ModuleType("searx.network")
sys.modules["searx"] = searx
sys.modules["searx.plugins"] = searx_plugins
sys.modules["searx.result_types"] = searx_results
# Network module mock
searx_network = ModuleType("searx.network")
def mock_network_call(method, url, **kwargs):
import http.client, ssl, json
from urllib.parse import urlparse
parsed = urlparse(url)
port = parsed.port or (443 if parsed.scheme=='https' else 80)
target = f"{parsed.hostname}:{port}"
if parsed.scheme == 'https':
conn = http.client.HTTPSConnection(target, timeout=30, context=ssl.create_default_context())
else:
conn = http.client.HTTPConnection(target, timeout=30)
headers = kwargs.get('headers', {})
body = None
if kwargs.get('json'):
body = json.dumps(kwargs['json'])
elif kwargs.get('data'):
body = kwargs['data']
path = parsed.path
if parsed.query:
path += f"?{parsed.query}"
if kwargs.get('params'):
from urllib.parse import urlencode
query_str = urlencode(kwargs['params'])
if '?' in path:
path += f"&{query_str}"
else:
path += f"?{query_str}"
conn.request(method, path, body=body, headers=headers)
return conn.getresponse()
def mock_stream(method, url, **kwargs):
res = mock_network_call(method, url, **kwargs)
class MockResponse:
def __init__(self, r):
self.status_code = r.status
self.text = "Mock Response" # Stub
self._r = r
def generator():
while True:
chunk = res.read(128)
if not chunk: break
yield chunk
return MockResponse(res), generator()
def mock_get(url, **kwargs):
import json
res = mock_network_call('GET', url, **kwargs)
class MockResponse:
def __init__(self, r):
self.status_code = r.status
self._content = r.read()
self.text = self._content.decode('utf-8')
def json(self):
return json.loads(self.text)
return MockResponse(res)
searx_network.stream = mock_stream
searx_network.get = mock_get
sys.modules["searx.network"] = searx_network
from ollama_answers import SXNGPlugin
from flask_babel import Babel
app = Flask(__name__)
babel = Babel(app)
class MockConfig:
active = True
plugin = SXNGPlugin(MockConfig())
plugin.init(app)
@app.route("/config", methods=["POST"])
def update_config():
url = request.form.get("url", "").strip()
bearer = request.form.get("bearer", "").strip()
model = request.form.get("model", "").strip()
query = request.form.get("q", "")
if url:
plugin.endpoint_url = url
plugin.api_key = bearer if bearer else "ollama"
if model:
plugin.model = model
redirect_q = f"?q={query}" if query else ""
return redirect(f"/{redirect_q}")
@app.route("/search")
def mock_search():
query = request.args.get("q", "")
format_type = request.args.get("format", "html")
if format_type != "json":
return "Demo only supports JSON format", 400
results = [
{"title": f"Result 1 for: {query}", "content": f"This is simulated content about {query}. It contains relevant information.", "url": f"https://example.com/1/{query.replace(' ', '-')}", "publishedDate": "2026-01-18"},
{"title": f"Result 2 for: {query}", "content": f"Additional information regarding {query}. More context and details.", "url": f"https://example.com/2/{query.replace(' ', '-')}", "publishedDate": "2026-01-17"},
{"title": f"Result 3 for: {query}", "content": f"Further reading on {query}. Expert analysis.", "url": f"https://example.com/3/{query.replace(' ', '-')}", "publishedDate": "2026-01-16"},
]
return {
"results": results,
"infoboxes": [],
"answers": [],
"suggestions": [f"{query} explained", f"{query} tutorial"]
}
@app.route("/")
def index():
query = request.args.get("q", "why is the sky blue")
class MockSearchQuery:
pageno = 1
lang = 'en'
categories = ['general']
MockSearchQuery.query = query
class MockSearch:
search_query = MockSearchQuery()
class MockResultContainer:
def __init__(self):
self.answers = set()
def get_ordered_results(self):
base_results = [
{"title": "Wikipedia", "content": "The sky appears blue due to Rayleigh scattering of sunlight. When sunlight enters the atmosphere, it collides with gas molecules and scatters in all directions. Blue light scatters more than other colors because it travels in shorter waves.", "url": "https://en.wikipedia.org/wiki/Rayleigh_scattering", "publishedDate": "2026-01-15"},
{"title": "NASA Science", "content": "Shorter blue wavelengths scatter more than longer red wavelengths. This phenomenon, discovered by Lord Rayleigh in the 1870s, explains why we see a blue sky during the day.", "url": "https://science.nasa.gov/blue-sky", "publishedDate": "2026-01-10"},
{"title": "Physics Today", "content": "The atmosphere acts as a filter, scattering blue light in all directions while letting other colors pass through more directly.", "url": "https://physicstoday.org/atmosphere", "publishedDate": "2026-01-01"},
{"title": "Scientific American", "content": "At sunset, light travels through more atmosphere, scattering away the blue and leaving reds and oranges.", "url": "https://scientificamerican.com/sunset", "publishedDate": "2025-12-20"},
{"title": "National Geographic", "content": "Ocean color also results from light scattering and absorption by water molecules.", "url": "https://nationalgeographic.com/ocean-blue", "publishedDate": "2025-12-15"},
]
broad_results = [
{"title": "MIT OpenCourseWare: Atmospheric Physics", "content": "Course materials.", "url": "https://ocw.mit.edu/physics"},
{"title": "NOAA: Understanding the Atmosphere", "content": "Educational resource.", "url": "https://noaa.gov/atmosphere"},
{"title": "BBC Science: Why is the sky blue?", "content": "Explainer article.", "url": "https://bbc.com/science/sky"},
{"title": "Khan Academy: Light and Color", "content": "Video lesson.", "url": "https://khanacademy.org/light"},
{"title": "HowStuffWorks: Rayleigh Scattering", "content": "Detailed explanation.", "url": "https://howstuffworks.com/rayleigh"},
{"title": "Physics Stack Exchange: Sky color discussion", "content": "Q&A thread.", "url": "https://physics.stackexchange.com/sky"},
{"title": "Quora: Atmospheric optics explained", "content": "Community answers.", "url": "https://quora.com/atmosphere"},
]
if 'quantum' in query.lower():
return [
{"title": "IBM Quantum", "content": "Quantum computers rely on qubits, which can represent 0, 1, or both via superposition. They solve complex problems faster.", "url": "https://www.ibm.com/quantum", "publishedDate": "2026-01-15"},
{"title": "Nature Physics", "content": "Entanglement allows qubits to be correlated instantly across distances. This is key for quantum cryptography and teleportation.", "url": "https://nature.com/articles/quantum", "publishedDate": "2026-01-10"},
{"title": "Wikipedia", "content": "Quantum computing uses quantum mechanics. Major applications include drug discovery and materials science.", "url": "https://en.wikipedia.org/wiki/Quantum_computing", "publishedDate": "2025-12-01"}
] + broad_results
return base_results + broad_results
result_container = MockResultContainer()
search = MockSearch()
plugin.post_search(None, search)
injection_html = ""
if search.result_container.answers:
injection_html = list(search.result_container.answers)[0]
bearer_display = plugin.api_key if plugin.api_key != "ollama" else ""
return f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Answers Demo</title>
<style>
body {{
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
padding: 2rem;
max-width: 800px;
margin: 0 auto;
background: #2e3440;
color: #eceff4;
}}
:root {{
--color-result-border: #3b4252;
--color-result-description: #d8dee9;
--color-base-font: #88c0d0;
--color-result-link: #81a1c1;
}}
.meta {{ color: #81a1c1; font-size: 0.9rem; }}
hr {{ border-color: #4c566a; }}
a {{ color: #88c0d0; }}
.config-panel {{
background: #3b4252;
border-radius: 6px;
padding: 1rem 1.25rem;
margin-bottom: 1.25rem;
}}
.config-panel summary {{
cursor: pointer;
font-size: 0.85rem;
color: #81a1c1;
user-select: none;
}}
.config-panel summary:hover {{ color: #88c0d0; }}
.config-row {{
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-top: 0.75rem;
}}
.config-row label {{
font-size: 0.8rem;
color: #81a1c1;
}}
.config-row input {{
background: #2e3440;
border: 1px solid #4c566a;
border-radius: 4px;
color: #eceff4;
font-size: 0.85rem;
padding: 0.4rem 0.6rem;
width: 100%;
box-sizing: border-box;
}}
.config-row input:focus {{ outline: none; border-color: #81a1c1; }}
.config-btn {{
margin-top: 0.75rem;
background: #4c566a;
border: none;
border-radius: 4px;
color: #eceff4;
cursor: pointer;
font-size: 0.85rem;
padding: 0.4rem 1rem;
}}
.config-btn:hover {{ background: #5e81ac; }}
.search-row {{
display: flex;
gap: 0.5rem;
margin-bottom: 1.25rem;
}}
.search-row input {{
flex: 1;
background: #3b4252;
border: 1px solid #4c566a;
border-radius: 4px;
color: #eceff4;
font-size: 0.95rem;
padding: 0.45rem 0.75rem;
}}
.search-row input:focus {{ outline: none; border-color: #81a1c1; }}
.search-row button {{
background: #5e81ac;
border: none;
border-radius: 4px;
color: #eceff4;
cursor: pointer;
font-size: 0.9rem;
padding: 0.45rem 1rem;
}}
.search-row button:hover {{ background: #81a1c1; }}
</style>
</head>
<body>
<details class="config-panel" {'open' if not bearer_display and 'localhost' in plugin.endpoint_url else ''}>
<summary>&#9881; Ollama Configuration</summary>
<form method="POST" action="/config">
<input type="hidden" name="q" value="{query}">
<div class="config-row">
<label>Endpoint URL</label>
<input type="text" name="url" value="{plugin.endpoint_url}" placeholder="http://localhost:11434/v1/chat/completions">
</div>
<div class="config-row">
<label>Bearer Token <span style="opacity:0.5;">(optional)</span></label>
<input type="text" name="bearer" value="{bearer_display}" placeholder="Leave empty if not required">
</div>
<button type="submit" class="config-btn">Apply</button>
</form>
</details>
<form class="search-row" method="GET" action="/">
<input type="text" name="q" value="{query}" placeholder="Ask something...">
<button type="submit">Search</button>
</form>
<p class="meta">Model: <strong>{plugin.model}</strong></p>
<hr>
{injection_html if injection_html else '<p style="color:#f66;">No response — check your Ollama endpoint and token above.</p>'}
</body>
</html>
"""
if __name__ == "__main__":
print("AI Answers - Demo\n")
print(f" Endpoint: {plugin.endpoint_url}")
print(f" Model: {plugin.model or 'N/A'}")
print(f" Mode: {'interactive' if plugin.interactive else 'simple'}")
print(f"\n http://localhost:5000/?q=why+is+the+sky+blue\n")
app.run(debug=False, port=5000)