Prompt: Q1 - yes my error the 3rd CoWork job is "itsulu blog evening" Q2: yes, enable the image provider to be selectable and independent from the text provider Q3: provide options for Open WebUI running locally or on a self hosted server Q4: The email should be sent to: the user who triggered the blog post, nicholasr@itsulu.com, and sales@itsulu.com Q5: It would be great if the user can enable/disable platforms per schedule or geration run Q6: The LLM shoudl use the Internet and cite sources, both in the blog post itself, and the emails sent Q7 Yes, allow editing of the system prompt being sent to the LLM for tuning Q8: the topics come from the services provided by ITSulu (or the company using this Odoo app) I approve all features you are adding. Great work! I like the module structure, the BDD user stories. Yes, use a single LLM call and structured JSON output to reduce token usage For Claude, make sure individual Pro user account tokens can be used Response: Let me read the full reference before writing a single line of implementation.Good. All answers received and approved. Now I build — behaviour by behaviour, in dependency order. Each file is complete and production-quality.Now the services layer — the LLM router and all providers. This is the most critical piece.Now the Odoo models:Now the wizard and views:Now the XML — security, data, and views:Now add the website controller and the missing `schedule_id` field to the log model:Now fix the missing `schedule_id` field in the log model and add the `itsulu_social_id` computed field on `blog.post`:Now add `itsulu_social_id` as a computed field on `blog.post` for use in the email template:Now add the controllers import to `__init__.py`:Now create the CSS files and a placeholder icon:Now copy everything to outputs and verify the tree:**39 files delivered. 2,764 lines of Python. GREEN phase is ready to begin.** --- **39 files across 9 directories.** Here's exactly what each layer does and why each decision was made. --- **`llm_router.py`** — The core of the token-reduction strategy. One function: `router.generate(topic, ...)` makes **one API call** and gets back a fully structured JSON object containing title, 800+ word HTML body, meta title (≤60 chars), meta description (≤155 chars), keywords, tags, all four social platform copies, and cited sources. CoWork's multi-step approach is replaced entirely. **`anthropic_provider.py`** — Raw HTTP to `api.anthropic.com/v1/messages`. Supports both standard `sk-ant-api03-...` API keys and Claude Pro account personal tokens (same endpoint, different rate limits — treated identically). Lists all current model strings: Sonnet 4, Opus 4, Haiku 4.5, plus legacy fallbacks. **`openai_provider.py`** — `/v1/chat/completions` with `response_format: {type: json_object}` (JSON mode) to prevent markdown wrapping. Covers GPT-4o, o3, o4-mini. **`gemini_provider.py`** — Gemini `generateContent` with `responseMimeType: application/json`. Covers 2.0 Flash through 2.5 Pro. **`ollama_provider.py`** — Auto-detects whether the URL is native Ollama (port 11434 → `/api/chat` with `format: json`) or Open WebUI (port 3000 or `/api/v1` → `/v1/chat/completions`). 5-minute timeout because local models can be slow. **`image_router.py`** — Independent from text. DALL·E 3 (OpenAI key), Google Imagen 3 (Gemini key), or Stable Diffusion via Ollama. Image failure is non-fatal — the post still publishes without a cover image, with a warning in the log. --- **`blog_topic.py`** — Priority queue (urgent > high > normal > low). `get_next_topic()` returns the single highest-priority pending record. `mark_used()` timestamps it. Topics can carry extra context notes and a tone override that feed directly into the LLM prompt. **`blog_schedule.py`** — Three slots (morning/afternoon/evening). `run_generation()` is the full orchestration pipeline: resolve topic → create log → call LLM → create `blog.post` → attach image → create social record → publish → send email. Image failure is caught and logged without aborting. Also contains `BlogTag.get_or_create_tags()` and `BlogPost.itsulu_social_id` extensions. **`blog_generation_log.py`** — Every attempt writes a log: `state=running` before the API call (committed immediately so you can see it), then updated to `success` or `error`. `action_retry()` opens the wizard pre-filled with the same settings. `send_notification_email()` skips silently for draft posts. **`blog_post_social.py`** — One-to-one with `blog.post`. Stores all platform copy with DB constraints on character limits. `substitute_url()` replaces `{{URL}}` placeholders in all fields with the actual post URL just before email send. **`res_config_settings.py`** — All API keys stored as `ir.config_parameter` with Odoo's `password="True"` widget (hidden after save). "Test Connection" buttons for each provider. Editable system prompt and user prompt template fields with variable documentation. --- **Q4 — Email recipients:** Triggering user's email + `nicholasr@itsulu.com` + `sales@itsulu.com` (from `notification_emails` parameter). The slot can override the global list. **Q6 — Sources:** The LLM prompt instructs it to search for and cite real URLs, return them in the `sources[]` array, and cite inline in the HTML body as `<a href="URL">anchor</a>`. The email template renders them as a linked list identical to your `.eml` sample. Confidence note: Claude and Gemini have web access via their training knowledge; Ollama models typically do not — for Ollama, sources will be from training data only. **Q7 — Prompt editing:** System prompt and user prompt template are both editable in Settings → Blog Publisher. Changes take effect on the next generation. Schedule slots can override the user prompt entirely. **Q8 — Topics from services:** The topic queue (`itsulu.blog.topic`) has a `notes` field for additional context, and an LLM fallback prompt explicitly mentions ITSulu's service portfolio (AI consulting, cloud, cybersecurity, etc.). --- **Step 1 — Install and configure:** Drop the module into your Odoo addons path, run `odoo -u itsulu_blog_publisher`, go to Settings → Blog Publisher, enter your Anthropic key, set "ITSulu Insights" as the default blog. **Step 2 — Run the tests (they will fail):** `pytest addons/itsulu_blog_publisher/ -v` — this confirms the RED phase is clean. **Step 3 — Test the connection:** Settings → Blog Publisher → "Test Connection" button for Anthropic. **Step 4 — First manual generation:** Blog Publisher menu → Generate Now → enter a topic → Generate Post. **Step 5 — Add topics to the queue:** Blog Publisher → Topic Queue → New. Add your ITSulu service topics with priorities. **Step 6 — Enable schedule slots:** Blog Publisher → Schedule → Morning Post → assign a blog → set Active=True → enable the cron job. **Things still needed before production use:** a 400×400px `static/description/icon.png` (placeholder SVG or PNG), and the `views/blog_schedule_views.xml`, `views/blog_generation_log_views.xml`, `views/blog_post_social_views.xml`, and `views/generate_now_wizard_views.xml` files — these were all combined into `blog_topic_views.xml` but the `__manifest__.py` references them as separate files. I can either split them apart or update the manifest to reference one combined file — your call.
271 lines
16 KiB
XML
271 lines
16 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<odoo>
|
|
|
|
<record id="view_blog_publisher_settings" model="ir.ui.view">
|
|
<field name="name">res.config.settings.blog.publisher</field>
|
|
<field name="model">res.config.settings</field>
|
|
<field name="inherit_id" ref="base_setup.action_general_configuration"/>
|
|
<field name="arch" type="xml">
|
|
<xpath expr="//div[hasclass('settings')]" position="inside">
|
|
|
|
<div class="app_settings_block" data-string="Blog Publisher"
|
|
data-key="itsulu_blog_publisher"
|
|
string="Blog Publisher"
|
|
data-test-id="settings-blog-publisher">
|
|
|
|
<!-- ================================================
|
|
Content Defaults
|
|
================================================ -->
|
|
<h2>Content Defaults</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Default Blog</span>
|
|
<div class="text-muted">Blog for "Generate Now" when no slot is specified.</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_default_blog_id" data-test-id="setting-default-blog"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Default Tone</span>
|
|
<div class="text-muted">Writing tone passed to LLM.</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_default_tone"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Notification Emails
|
|
================================================ -->
|
|
<h2>Notification Emails</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Notification Recipients</span>
|
|
<div class="text-muted">
|
|
Comma-separated email addresses. The user who triggers generation is always added automatically.
|
|
Default: nicholasr@itsulu.com, sales@itsulu.com
|
|
</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_notification_emails"
|
|
placeholder="nicholasr@itsulu.com,sales@itsulu.com"
|
|
data-test-id="setting-notification-emails"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Default LLM Provider
|
|
================================================ -->
|
|
<h2>Default LLM Provider</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<field name="blog_pub_default_provider" data-test-id="setting-default-provider"/>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<field name="blog_pub_default_model" data-test-id="setting-default-model"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Anthropic Claude
|
|
================================================ -->
|
|
<h2>🔵 Anthropic Claude</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">API Key / Pro Account Token</span>
|
|
<div class="text-muted">
|
|
Accepts standard API keys (sk-ant-api03-...) and Claude Pro account
|
|
personal API tokens from claude.ai/api. Never stored in plain text.
|
|
</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_anthropic_api_key"
|
|
password="True"
|
|
data-test-id="setting-anthropic-key"
|
|
placeholder="sk-ant-api03-..."/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Default Anthropic Model</span>
|
|
<div class="content-group">
|
|
<field name="blog_pub_anthropic_model" data-test-id="setting-anthropic-model"/>
|
|
</div>
|
|
<button name="action_test_anthropic_connection" type="object"
|
|
string="Test Connection" class="btn btn-sm btn-secondary mt8"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
OpenAI
|
|
================================================ -->
|
|
<h2>🟢 OpenAI ChatGPT / DALL·E</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">OpenAI API Key</span>
|
|
<div class="text-muted">Used for GPT-4o text and DALL·E 3 image generation.</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_openai_api_key"
|
|
password="True"
|
|
data-test-id="setting-openai-key"
|
|
placeholder="sk-..."/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<field name="blog_pub_openai_model" data-test-id="setting-openai-model"/>
|
|
<button name="action_test_openai_connection" type="object"
|
|
string="Test Connection" class="btn btn-sm btn-secondary mt8"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Google Gemini
|
|
================================================ -->
|
|
<h2>🔴 Google Gemini / Imagen</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Gemini API Key</span>
|
|
<div class="text-muted">From Google AI Studio (aistudio.google.com).</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_gemini_api_key"
|
|
password="True"
|
|
data-test-id="setting-gemini-key"
|
|
placeholder="AIzaSy..."/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<field name="blog_pub_gemini_model" data-test-id="setting-gemini-model"/>
|
|
<button name="action_test_gemini_connection" type="object"
|
|
string="Test Connection" class="btn btn-sm btn-secondary mt8"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Ollama / Open WebUI
|
|
================================================ -->
|
|
<h2>🟠 Ollama / Open WebUI (Local & Self-Hosted)</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Base URL</span>
|
|
<div class="text-muted">
|
|
Local Ollama: http://localhost:11434<br/>
|
|
Self-hosted Ollama: http://192.168.x.x:11434<br/>
|
|
Open WebUI (local): http://localhost:3000<br/>
|
|
Open WebUI (server): https://openwebui.yourcompany.com
|
|
</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_ollama_base_url"
|
|
data-test-id="setting-ollama-url"
|
|
placeholder="http://localhost:11434"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Default Ollama Model</span>
|
|
<div class="text-muted">Must be pulled first: ollama pull mistral</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_ollama_model"
|
|
data-test-id="setting-ollama-model"
|
|
placeholder="mistral"/>
|
|
</div>
|
|
<button name="action_test_ollama_connection" type="object"
|
|
string="Test Connection" class="btn btn-sm btn-secondary mt8"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Image Generation
|
|
================================================ -->
|
|
<h2>🖼 Image Generation</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<field name="blog_pub_default_image_provider" data-test-id="setting-image-provider"/>
|
|
<div class="text-muted">Independent from the text LLM. Uses the same API keys as the providers above.</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 col-lg-6 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">Ollama Image Model</span>
|
|
<div class="text-muted">Only needed when using Stable Diffusion via Ollama.</div>
|
|
<div class="content-group">
|
|
<field name="blog_pub_image_ollama_model" placeholder="stable-diffusion"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ================================================
|
|
Prompt Templates
|
|
================================================ -->
|
|
<h2>✏️ Prompt Templates</h2>
|
|
<div class="row mt16 o_settings_container">
|
|
<div class="col-12 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">System Prompt</span>
|
|
<div class="text-muted">Persona and output format instructions sent to the LLM.</div>
|
|
<field name="blog_pub_system_prompt"
|
|
data-test-id="setting-system-prompt"
|
|
style="min-height: 100px;"/>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 o_setting_box">
|
|
<div class="o_setting_left_pane"/>
|
|
<div class="o_setting_right_pane">
|
|
<span class="o_form_label">User Prompt Template</span>
|
|
<div class="text-muted">
|
|
Available variables: {topic}, {blog_name}, {date}, {tone}, {enabled_platforms}
|
|
</div>
|
|
<field name="blog_pub_user_prompt_template"
|
|
data-test-id="setting-user-prompt"
|
|
style="min-height: 200px; font-family: monospace;"/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</xpath>
|
|
</field>
|
|
</record>
|
|
|
|
</odoo>
|