feat: editable LLM prompts and per-family preferred model#951
feat: editable LLM prompts and per-family preferred model#951MkDev11 wants to merge 17 commits intowe-promise:mainfrom
Conversation
- Add .cursor/rules/api-endpoint-consistency.mdc: checklist that applies when editing app/controllers/api/v1, spec/requests/api/v1, or test/controllers/api/v1. Enforces (1) Minitest-only behavioral coverage for new endpoints, (2) rswag docs-only (no expect/assert), (3) same API key auth pattern in all rswag specs. - Reference the rule in AGENTS.md under API Development Guidelines.
- Minitest: test/api_endpoint_consistency_rule_test.rb checks rule file exists, globs, and all three sections (Minitest, rswag docs-only, API key auth) plus AGENTS.md reference. - Standalone: test/support/verify_api_endpoint_consistency.rb runs same checks without loading Rails (use when app fails to boot). - Rule: add mdc: links for Cursor, note valuations_spec OAuth outlier.
…mise#938) - Add family columns: custom_system_prompt, custom_intro_prompt, preferred_ai_model - Assistant::Configurable uses family overrides when present, else built-in defaults - Chat.default_model(family) supports per-family preferred model; controllers pass family - Settings AI Prompts page: form to edit custom prompts and preferred model, validation - Route and Settings::AiPromptsController#update with strong params and error handling - Family validations: prompt length cap 32k chars, preferred_ai_model 128 chars
…er tests - Gemfile: add sidekiq-throttled (required by IndexaCapitalActivitiesFetchJob) - ChatTest: stub ENV/Setting and clear family preferred_ai_model for default-model tests - AiPromptsControllerTest: drop assigns/assert_template; assert response content and non-persistence
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds per-family AI prompt and model overrides, custom OpenAI endpoint support, family-aware model/provider resolution, admin-editable settings, database columns for family overrides, controller and helper updates to use family context, provider registry changes, and related tests and UI/locales. Changes
Sequence DiagramsequenceDiagram
participant Browser as User (Browser)
participant Controller as ChatsController / MessagesController
participant Chat as Chat Model
participant Family as Family Record
participant Registry as Provider::Registry
participant Provider as Provider::Openai
participant Assistant as Assistant
Browser->>Controller: POST /chats or /messages (no ai_model)
Controller->>Chat: Chat.default_model(Current.user.family)
Chat->>Family: read preferred_ai_model/custom prompts
alt family has preferred_ai_model
Family-->>Chat: family preferred_ai_model
else
Chat-->>Chat: fallback to ENV/Setting/default
end
Chat-->>Controller: resolved ai_model
Controller->>Assistant: create/message with ai_model and family
Assistant->>Registry: get_model_provider(ai_model, family: family)
Registry->>Family: check openai_uri_base & preferred_ai_model
alt family has custom endpoint & token
Registry->>Provider: instantiate Provider::Openai(custom uri, model)
else
Registry->>Provider: return default provider
end
Provider-->>Assistant: provider instance
Assistant->>Assistant: apply family custom prompts if present
Assistant-->>Browser: AI response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d33c85c384
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
… tests - Add family.openai_uri_base; when set, chat uses this endpoint for that household - Provider::Registry.openai_for_family(family) builds provider from family endpoint and model (public) - Assistant uses family provider when present and supports model; validation requires model when endpoint set - AI Prompts UI: endpoint field, locale keys; controller permits openai_uri_base - Fix: openai_for_family moved to public class method (was private, would raise) - Assistant tests: expect get_model_provider(ai_model, family:)
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
1 similar comment
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
- before_action :ensure_admin for show and update; redirect non-admins with alert - Add not_authorized locale; tests for show/update requiring admin
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
3 similar comments
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
…int_consistency.rb - family.rb: keep AI prompt/endpoint validations and custom_openai_endpoint?; add moniker validation and moniker_label/moniker_label_plural from main - db/schema.rb: keep schema version from main; families table includes both AI columns and vector_store_id/moniker - verify_api_endpoint_consistency.rb: add --compliance option and comment from main
…keep moniker column)
9d5a7de to
fdbf0da
Compare
- assistant.rb: keep upstream module + registry; family-aware lookup in Builtin - builtin.rb: pass family: chat.user&.family to get_model_provider - schema.rb: keep both vector_store_id and assistant_type on families
…tantConfig - Add builtin_assistant_configs table and BuiltinAssistantConfig model - Backfill from families, remove custom_system_prompt, custom_intro_prompt, preferred_ai_model, openai_uri_base from families - Family has_one :builtin_assistant_config; remove prompt validations from Family - Assistant::Configurable, Provider::Registry.openai_for_family, Chat.default_model read from family.builtin_assistant_config - Settings::AiPromptsController and views use builtin_assistant_config params - Update tests and make AddAssistantTypeToFamilies migration idempotent - Add docs/assistant_config_refactor.md and refactor review
- Add turbo_frame_tag 'modal' to properties/edit so response targets modal frame - Fixes PropertiesEditTest#test_can_persist_property_subtype (selector not found)
What this does
The AI Prompts settings page was always read-only. This PR makes it actually useful: you can now edit the main system prompt, the intro (welcome) prompt, and choose a default AI model for your household. Each family can tune how the assistant behaves and which model new chats use.
Changes
custom_system_prompt,custom_intro_prompt,preferred_ai_model. All optional; leave blank to keep the built-in defaults.sidekiq-throttledto the Gemfile so the test suite can boot (required byIndexaCapitalActivitiesFetchJob).Why
So each household can adjust the assistant’s personality and target model without touching code or config files. Matches the intent behind #938 and the discussion in #906.
How to verify
gpt-4-turbo), optionally edit the main or intro prompt, and save.Run the tests:
bin/rails test test/controllers/settings/ai_prompts_controller_test.rb test/models/chat_test.rb test/models/family_test.rbCloses #938.
Summary by CodeRabbit
New Features
Chores