Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.venv/
venv/
__pycache__/
*.pyc
.env
.DS_Store
19 changes: 19 additions & 0 deletions PROMPTS_BOT_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Prompts Bot (Flask)

This small scaffold provides a minimal Flask HTTP API for browsing and searching the prompts indexed in zetalib_prompts_index.json.

Endpoints
- GET /health -> {status, count}
- GET /prompts?q=term&category=Category -> list of prompts matching query (searches path+excerpt+category)
- GET /prompts/<id> -> full content and metadata for a prompt (id from /prompts)

Quick start
1. python3 -m venv .venv
2. source .venv/bin/activate
3. pip install -r requirements.txt
4. export FLASK_APP=bot.app
5. flask run --host=0.0.0.0 --port=5000

Notes
- The app reads zetalib_prompts_index.json created earlier. Re-generate the index if you add files.
- For production, add pagination, input sanitization, and caching.
1 change: 1 addition & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# bot package
61 changes: 61 additions & 0 deletions bot/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from flask import Flask, jsonify, request, abort
import json
import os

app = Flask(__name__)

ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
INDEX_PATH = os.path.join(ROOT, 'zetalib_prompts_index.json')

try:
with open(INDEX_PATH, 'r', encoding='utf-8') as f:
INDEX = json.load(f)
except Exception:
INDEX = []

@app.route('/health')
def health():
return jsonify({'status': 'ok', 'count': len(INDEX)})

@app.route('/prompts')
def list_prompts():
q = (request.args.get('q') or '').lower()
category = request.args.get('category')
results = []
for i, item in enumerate(INDEX):
if category and item.get('category') != category:
continue
if q:
hay = ' '.join([item.get('path',''), item.get('excerpt',''), item.get('category','')]).lower()
if q not in hay:
continue
results.append({
'id': i,
'path': item.get('path'),
'category': item.get('category'),
'excerpt': item.get('excerpt'),
})
return jsonify(results)

@app.route('/prompts/<int:pid>')
def get_prompt(pid):
if pid < 0 or pid >= len(INDEX):
abort(404)
item = INDEX[pid]
file_path = os.path.join(ROOT, item['path'])
content = ''
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
except Exception:
content = ''
return jsonify({
'id': pid,
'path': item['path'],
'category': item['category'],
'excerpt': item['excerpt'],
'content': content,
})

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask>=2.0
133 changes: 133 additions & 0 deletions zetalib_prompts_index.csv

Large diffs are not rendered by default.

662 changes: 662 additions & 0 deletions zetalib_prompts_index.json

Large diffs are not rendered by default.