Skip to content

feat(gpt): add multi-provider AI support for TinyMCE - #116

Open
sebastienheyd wants to merge 3 commits into
masterfrom
feat/multi-ai-providers
Open

sebastienheyd wants to merge 3 commits into
masterfrom
feat/multi-ai-providers

Conversation

@sebastienheyd

@sebastienheyd sebastienheyd commented Apr 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Refactor the hardcoded OpenAI integration into an extensible multi-provider architecture supporting OpenAI, Anthropic Claude, Ollama, and custom providers.

  • New architecture: Abstract AiProvider base class with AiProvidersRepository singleton (follows existing pattern from DashboardWidgetsRepository)
  • New providers: OpenAI, Anthropic Claude, Ollama built-in; custom providers extensible
  • Normalized streaming: All providers emit unified SSE format {"content":"..."} for frontend compatibility
  • Backward compatible: Existing OpenAI config still works; new multi-provider config optional
  • Configuration: Set AI_PROVIDER=openai|anthropic|ollama in .env, or register custom providers

Changes

New files

  • src/Ai/AiProvider.php — abstract base class
  • src/Ai/AiProvidersRepository.php — registry singleton
  • src/Ai/AiStreamer.php — provider-agnostic cURL + SSE handler
  • src/Ai/Providers/OpenAiProvider.php — with legacy config fallback
  • src/Ai/Providers/AnthropicProvider.php — Anthropic Claude support
  • src/Ai/Providers/OllamaProvider.php — Ollama local LLM support

Modified files

  • src/config/app.php — new ai section with provider selection + per-provider config
  • src/BoilerplateServiceProvider.php — register boilerplate.ai.providers singleton
  • src/Controllers/GptController.php — stream() delegates to AiStreamer; sendRequest() removed
  • src/View/Composers/TinymceLoadComposer.php — inject $aiEnabled variable
  • src/resources/views/load/tinymce.blade.php — use $aiEnabled instead of OpenAI config check
  • src/resources/assets/js/vendor/tinymce/plugins/gpt/generator.js — parse normalized SSE payload

Configuration examples

Using default OpenAI (backward compatible):

OPENAI_API_KEY=sk-...

Using Anthropic Claude:

AI_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_MODEL=claude-3-5-haiku-20241022

Using Ollama (local):

AI_PROVIDER=ollama
OLLAMA_ENDPOINT=http://localhost:11434
OLLAMA_MODEL=llama3

Custom provider:

// AppServiceProvider::boot()
app('boilerplate.ai.providers')->registerAiProvider(\App\Ai\MyProvider::class);

Test plan

  • ✅ All existing tests pass (232 tests)
  • ✅ Coding standards pass
  • Test OpenAI with existing config (OPENAI_API_KEY only) — button visible, generation works
  • Test Anthropic with AI_PROVIDER=anthropic and ANTHROPIC_API_KEY
  • Test Ollama with AI_PROVIDER=ollama and OLLAMA_MODEL set (no API key needed)
  • Test with no provider configured — GPT button absent from TinyMCE
  • Test custom provider registration in consuming application

sebastienheyd and others added 2 commits April 19, 2026 08:58
Refactor the hardcoded OpenAI integration into an extensible multi-provider
architecture supporting OpenAI, Anthropic Claude, Ollama, and custom providers.

- Add AiProvider abstract base class and AiProvidersRepository singleton
- Create OpenAiProvider, AnthropicProvider, OllamaProvider implementations
- Add AiStreamer service to normalize streaming responses across providers
- Update config/app.php with provider selection and per-provider settings
- Refactor GptController.stream() to delegate to AiStreamer
- Normalize SSE payload to {"content":"..."} for all providers
- Update TinyMCE view/composer to check for any configured provider
- Fix generator.js to parse normalized SSE format
- Maintain backward compatibility with legacy boilerplate.app.openai config

New config structure:
  AI_PROVIDER=openai|anthropic|ollama|custom
  OPENAI_API_KEY, OPENAI_MODEL, OPENAI_API_ORGANIZATION
  ANTHROPIC_API_KEY, ANTHROPIC_MODEL
  OLLAMA_ENDPOINT, OLLAMA_MODEL

Custom providers can be registered via:
  app('boilerplate.ai.providers')->registerAiProvider(CustomProvider::class)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ddb014d44

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Route registration was still checking boilerplate.app.openai.key while the
view used hasConfiguredProvider(), causing a RouteNotFoundException when
using Anthropic or Ollama without an OpenAI key configured.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant