Files
web_django_template/site/social_ai/views.py
T
westfarnandCursor 787f0e48fb Populate the client website template with catalog feature flags.
Extract always-on public/portal/UTM plus optional email_sms, directmail, blog, payments, social, and social_ai so new client sites can be bootstrapped from this seed.

Refs #1
Refs #2

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-26 07:55:26 -05:00

28 lines
902 B
Python

import json
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.views.decorators.http import require_POST
from social_ai.ollama import OllamaError, generate_social_post
@login_required
@require_POST
def api_generate(request):
"""JSON endpoint to draft posts via Ollama. POST JSON: prompt, platform."""
try:
payload = json.loads(request.body.decode() or "{}")
except json.JSONDecodeError:
payload = request.POST.dict()
prompt = (payload.get("prompt") or "").strip()
if not prompt:
return JsonResponse({"error": "prompt required"}, status=400)
try:
text = generate_social_post(
prompt, platform=(payload.get("platform") or "").strip()
)
except OllamaError as exc:
return JsonResponse({"error": str(exc)}, status=502)
return JsonResponse({"text": text})