🔮 Initial commit: sibilla — self-hosted Perplexity-like AI search engine

This commit is contained in:
Sibilla committed 2026-07-16 15:57:04 +00:00
commit ea09bb4f4f
11 files changed
+671

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
# Google AI API Key — ottenila da https://aistudio.google.com/apikey
GOOGLE_API_KEY=your-api-key-here
# Flask
SECRET_KEY=change-me-to-a-random-string
SIBILLA_HOST=127.0.0.1
SIBILLA_PORT=5000
SIBILLA_DEBUG=1
+34
View File
@@ -0,0 +1,34 @@
# Python
__pycache__/
*.py[cod]
*.egg-info/
dist/
build/
.eggs/
# Virtual environment
.venv/
venv/
env/
# Environment variables
.env
.env.local
# IDE
.vscode/
.idea/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
# Flask
instance/
# Testing
.pytest_cache/
htmlcov/
.coverage
+74
View File
@@ -0,0 +1,74 @@
# 🔮 Sibilla
> *L'oracolo AI che cerca nel web e risponde alle tue domande.*
> Self-hosted Perplexity-like search engine.
**Sibilla** è un motore di ricerca AI self-hosted che combina:
- 🧠 **Google Gemini API** — modelli linguistici avanzati con grounding su web search
- 🔧 **MCP (Model Context Protocol)** — tool use per estendere le capacità dell'AI
- 🔍 **Web search integrata** — ricerca e sintesi delle fonti in tempo reale
- 🖥️ **Flask web app** — interfaccia pulita e reattiva
```
Tu chiedi → Sibilla cerca nel web → Sintetizza le fonti → Ti risponde con citazioni
```
## Architettura (pianificata)
```
sibilla/
├── src/sibilla/
│ ├── app.py # Flask app factory
│ ├── cli.py # Entry point
│ ├── search.py # Web search + scraping
│ ├── ai.py # Google Gemini API client
│ ├── mcp.py # MCP tool integration
│ └── prompts.py # Prompt templates
├── templates/
│ └── index.html # Interfaccia di ricerca
├── static/
│ ├── style.css # Stili
│ └── app.js # Logica frontend
└── tests/
└── ...
```
## Setup
```bash
cd sibilla
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
```
Crea un file `.env` con la tua API key Google:
```
GOOGLE_API_KEY=your-api-key-here
```
## Uso
```bash
# Avvia il server
sibilla
# Oppure
python -m sibilla
```
Poi apri http://127.0.0.1:5000 nel browser.
## Sviluppo
```bash
pip install -e ".[dev]"
pytest
ruff check src tests
```
## Licenza
MIT
+54
View File
@@ -0,0 +1,54 @@
[project]
name = "sibilla"
version = "0.1.0"
description = "sibilla - Self-hosted Perplexity-like AI search engine with Google Gemini + MCP tool use, built with Flask"
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [{ name = "Author" }]
keywords = ["ai", "search", "gemini", "perplexity", "mcp", "llm", "rag", "flask"]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Operating System :: OS Independent",
"Environment :: Web Environment",
"Framework :: Flask",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
"flask>=3.0",
"google-genai>=1.0",
"requests>=2.31",
"python-dotenv>=1.0",
"beautifulsoup4>=4.12",
"markdown>=3.5",
]
[project.optional-dependencies]
dev = [
"pytest>=7",
"ruff>=0.5",
]
[project.scripts]
sibilla = "sibilla.cli:main"
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["src"]
include = ["sibilla*"]
[tool.setuptools.package-dir]
"" = "src"
[tool.pytest.ini_options]
addopts = "-q"
testpaths = ["tests"]
[tool.ruff]
line-length = 100
target-version = "py310"
+3
View File
@@ -0,0 +1,3 @@
"""sibilla — L'oracolo AI che risponde alle tue domande cercando nel web."""
__version__ = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
"""Allow running sibilla with `python -m sibilla`."""
from sibilla.cli import main
if __name__ == "__main__":
main()
+31
View File
@@ -0,0 +1,31 @@
"""sibilla web application — Flask app factory."""
import os
from flask import Flask, render_template
def create_app(testing: bool = False) -> Flask:
"""Create and configure the Flask application.
Args:
testing: If True, configure the app for testing (no .env loading).
"""
app = Flask(__name__)
app.config.update(
SECRET_KEY=os.environ.get("SECRET_KEY", "dev-secret-key-change-me"),
GOOGLE_API_KEY=os.environ.get("GOOGLE_API_KEY", ""),
)
# ── Routes ──────────────────────────────────────────────────────
@app.route("/")
def index():
"""Home page — the search interface."""
return render_template("index.html")
@app.route("/api/health")
def health():
"""Health check endpoint."""
return {"status": "ok", "version": __import__("sibilla").__version__}
return app
+21
View File
@@ -0,0 +1,21 @@
"""CLI entry point for sibilla."""
import os
from sibilla.app import create_app
def main() -> None:
"""Run the sibilla web server."""
host = os.environ.get("SIBILLA_HOST", "127.0.0.1")
port = int(os.environ.get("SIBILLA_PORT", "5000"))
debug = os.environ.get("SIBILLA_DEBUG", "1") == "1"
app = create_app()
print(f"🔮 Sibilla is awakening at http://{host}:{port}")
app.run(host=host, port=port, debug=debug)
if __name__ == "__main__":
main()
+108
View File
@@ -0,0 +1,108 @@
/**
* Sibilla — Frontend search interface
*/
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('search-form');
const queryInput = document.getElementById('query');
const submitBtn = document.getElementById('submit-btn');
const responseArea = document.getElementById('response-area');
const loading = document.getElementById('loading');
const answerDiv = document.getElementById('answer');
const sourcesDiv = document.getElementById('sources');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const query = queryInput.value.trim();
if (!query) return;
// Show response area + loading
responseArea.style.display = 'block';
loading.style.display = 'flex';
answerDiv.innerHTML = '';
sourcesDiv.innerHTML = '';
submitBtn.disabled = true;
try {
const res = await fetch('/api/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query }),
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error || 'Errore sconosciuto');
}
const data = await res.json();
// Render answer as Markdown
answerDiv.innerHTML = renderMarkdown(data.answer);
// Render sources
if (data.sources && data.sources.length > 0) {
sourcesDiv.innerHTML = '<h3>📚 Fonti</h3>' +
data.sources.map(s =>
`<a href="${escapeHtml(s.url)}" target="_blank" rel="noopener" class="source-item">
<span class="source-title">${escapeHtml(s.title)}</span>
<span class="source-url">${escapeHtml(s.url)}</span>
</a>`
).join('');
}
} catch (err) {
answerDiv.innerHTML = `<div class="error-box">⚠️ ${escapeHtml(err.message)}</div>`;
} finally {
loading.style.display = 'none';
submitBtn.disabled = false;
}
});
// Allow Ctrl+Enter to submit
queryInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
form.dispatchEvent(new Event('submit'));
}
});
});
// ── Tiny Markdown renderer ─────────────────────────────────────
function renderMarkdown(text) {
if (!text) return '';
let html = escapeHtml(text);
// Headers
html = html.replace(/^### (.+)$/gm, '<h3>$1</h3>');
html = html.replace(/^## (.+)$/gm, '<h2>$1</h2>');
html = html.replace(/^# (.+)$/gm, '<h1>$1</h1>');
// Bold + italic
html = html.replace(/\*\*\*(.+?)\*\*\*/g, '<strong><em>$1</em></strong>');
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
html = html.replace(/\*(.+?)\*/g, '<em>$1</em>');
// Inline code
html = html.replace(/`(.+?)`/g, '<code>$1</code>');
// Links
html = html.replace(/\[(.+?)\]\((.+?)\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
// Paragraphs (double newlines)
html = html.replace(/\n\n/g, '</p><p>');
html = '<p>' + html + '</p>';
html = html.replace(/<p>\s*<\/p>/g, '');
// Line breaks
html = html.replace(/\n/g, '<br>');
return html;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
+285
View File
@@ -0,0 +1,285 @@
/* ═══════════════════════════════════════════════════════════════
Sibilla — L'Oracolo AI
═══════════════════════════════════════════════════════════════ */
:root {
--bg: #0f0f14;
--surface: #1a1a24;
--surface-hover: #22222e;
--border: #2a2a3a;
--text: #e8e8ed;
--text-muted: #8888a0;
--accent: #a78bfa;
--accent-glow: #c4b5fd;
--success: #34d399;
--danger: #f87171;
--radius: 12px;
--transition: 0.2s ease;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
display: flex;
justify-content: center;
}
.container {
max-width: 800px;
width: 100%;
padding: 2rem 1.5rem;
display: flex;
flex-direction: column;
min-height: 100vh;
}
/* ── Header ──────────────────────────────────────────────────── */
header {
text-align: center;
margin-bottom: 3rem;
padding-top: 3rem;
}
header h1 {
font-size: 2.8rem;
font-weight: 700;
background: linear-gradient(135deg, var(--accent), var(--accent-glow));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 0.5rem;
letter-spacing: -0.02em;
}
.subtitle {
color: var(--text-muted);
font-size: 1.05rem;
}
/* ── Search Box ──────────────────────────────────────────────── */
.search-box {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin-bottom: 2rem;
}
.search-box textarea {
width: 100%;
padding: 1rem 1.25rem;
background: var(--surface);
border: 2px solid var(--border);
border-radius: var(--radius);
color: var(--text);
font-size: 1.05rem;
font-family: inherit;
resize: vertical;
min-height: 80px;
transition: border-color var(--transition), box-shadow var(--transition);
outline: none;
}
.search-box textarea:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
}
.search-box textarea::placeholder {
color: var(--text-muted);
}
#submit-btn {
align-self: flex-end;
padding: 0.75rem 1.75rem;
background: linear-gradient(135deg, var(--accent), #8b5cf6);
border: none;
border-radius: var(--radius);
color: #fff;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
}
#submit-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 20px rgba(167, 139, 250, 0.35);
}
#submit-btn:active {
transform: translateY(0);
}
#submit-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
/* ── Response Area ───────────────────────────────────────────── */
.response-area {
flex: 1;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
/* ── Loading ─────────────────────────────────────────────────── */
.loading {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
padding: 2rem;
color: var(--text-muted);
}
.spinner {
width: 36px;
height: 36px;
border: 3px solid var(--border);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* ── Answer ──────────────────────────────────────────────────── */
.answer {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1.5rem;
margin-bottom: 1.5rem;
line-height: 1.7;
font-size: 1.02rem;
}
.answer h1, .answer h2, .answer h3 {
margin-top: 1.25rem;
margin-bottom: 0.5rem;
color: var(--accent-glow);
}
.answer h1 { font-size: 1.5rem; }
.answer h2 { font-size: 1.25rem; }
.answer h3 { font-size: 1.1rem; }
.answer p {
margin-bottom: 0.75rem;
}
.answer ul, .answer ol {
padding-left: 1.5rem;
margin-bottom: 0.75rem;
}
.answer li {
margin-bottom: 0.35rem;
}
.answer code {
background: rgba(167, 139, 250, 0.1);
padding: 0.15rem 0.4rem;
border-radius: 4px;
font-size: 0.9em;
}
.answer pre {
background: rgba(0, 0, 0, 0.3);
padding: 1rem;
border-radius: 8px;
overflow-x: auto;
margin-bottom: 0.75rem;
}
.answer blockquote {
border-left: 3px solid var(--accent);
padding-left: 1rem;
color: var(--text-muted);
margin-bottom: 0.75rem;
}
/* ── Sources ─────────────────────────────────────────────────── */
.sources {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1.25rem;
}
.sources h3 {
color: var(--accent-glow);
font-size: 0.95rem;
margin-bottom: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.source-item {
display: block;
padding: 0.6rem 0.75rem;
border-radius: 8px;
color: var(--text);
text-decoration: none;
transition: background var(--transition);
margin-bottom: 0.25rem;
font-size: 0.9rem;
}
.source-item:hover {
background: var(--surface-hover);
}
.source-item .source-title {
font-weight: 500;
color: var(--accent-glow);
}
.source-item .source-url {
color: var(--text-muted);
font-size: 0.8rem;
display: block;
margin-top: 0.15rem;
word-break: break-all;
}
/* ── Error ───────────────────────────────────────────────────── */
.error-box {
background: rgba(248, 113, 113, 0.1);
border: 1px solid var(--danger);
border-radius: var(--radius);
padding: 1rem 1.25rem;
color: var(--danger);
}
/* ── Footer ──────────────────────────────────────────────────── */
footer {
text-align: center;
padding: 1.5rem 0;
color: var(--text-muted);
font-size: 0.8rem;
margin-top: auto;
}
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sibilla — L'Oracolo AI</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<div class="container">
<header>
<h1>🔮 Sibilla</h1>
<p class="subtitle">L'oracolo AI che cerca nel web e risponde alle tue domande</p>
</header>
<main>
<form id="search-form" class="search-box">
<textarea
id="query"
name="query"
placeholder="Chiedi qualsiasi cosa a Sibilla..."
rows="3"
autofocus
></textarea>
<button type="submit" id="submit-btn">
<span>Interroga l'Oracolo</span>
</button>
</form>
<div id="response-area" class="response-area" style="display: none;">
<div id="loading" class="loading" style="display: none;">
<span class="spinner"></span>
<p>Sibilla sta consultando le fonti...</p>
</div>
<div id="answer" class="answer"></div>
<div id="sources" class="sources"></div>
</div>
</main>
<footer>
<p>Sibilla v0.1.0 — Self-hosted AI Search</p>
</footer>
</div>
<script src="/static/app.js"></script>
</body>
</html>