-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Personal finance AI (v1) #2022
Merged
Merged
Personal finance AI (v1) #2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add chat and messages controllers - Create chat and message views - Implement chat-related routes - Add message broadcasting and user interactions - Update application layout to support chat sidebar - Enhance user model with initials method
- Update sidebar layout with dynamic width and improved responsiveness - Add new chat menu Stimulus controller for toggling between chat and chat list views - Improve chat list display with recent chats and empty state - Extract AI avatar to a partial for reusability - Enhance message display and interaction styling - Add more contextual buttons and interaction hints
- Refactor chat scroll functionality with Stimulus controller - Optimize message scrolling in chat views - Update message styling for better visual hierarchy - Enhance chat container layout with flex and auto-scroll - Simplify message rendering across different chat views
- Refactor AI avatar rendering across chat views - Replace hardcoded avatar markup with a reusable partial - Simplify avatar display in chats and messages views
- Add conditional width class for right sidebar panel - Ensure consistent sidebar toggle behavior for both left and right panels - Use specific width class for right panel (w-[375px])
- Extract message form to a reusable partial with dynamic context support - Create flexible AI greeting partial for consistent welcome messages - Simplify chat and sidebar views by leveraging new partials - Add support for different form scenarios (chat, new chat, sidebar) - Improve code modularity and reduce duplication
- Implement clear chat action in ChatsController - Add clear chat route to support clearing messages - Update AI sidebar with dropdown menu for chat actions - Preserve system message when clearing chat - Enhance chat interaction with new menu options
- Create initial frontmatter for structure.mdc file - Include description and configuration options - Prepare for potential dynamic documentation rendering
- Add rule for using `Current.family` instead of `current_family` - Include new guidelines for testing, API routes, and solution approach - Expand project-specific rules for more consistent development practices
- Add `ruby-openai` gem for AI integration - Implement `to_ai_readable_hash` methods in BalanceSheet and IncomeStatement - Include Promptable module in both models - Add savings rate calculation method in IncomeStatement - Prepare financial models for AI-powered insights and interactions
…apabilities - Implement comprehensive AI financial query system with function-based interactions - Add detailed debug logging for AI responses and function calls - Extend BalanceSheet and IncomeStatement models with AI-friendly methods - Create robust error handling and fallback mechanisms for AI queries - Update chat and message views to support debug mode and enhanced rendering - Add AI query routes and initial test coverage for financial assistant
- Remove inline AI chat from application layout - Enhance AI sidebar with more semantic HTML structure - Add descriptive comments to clarify different sections of chat view - Improve flex layout and scrolling behavior in chat messages container - Optimize message rendering with more explicit class names and structure
- Implement `markdown` helper method in ApplicationHelper using Redcarpet - Update message view to render AI messages with Markdown formatting - Add comprehensive Markdown rendering options (tables, code blocks, links) - Enhance AI Financial Assistant prompt to encourage Markdown usage - Remove commented Markdown CSS in Tailwind application stylesheet
- Update @biomejs/biome to latest version with caret (^) notation - Refactor AI query and chat controllers to use template literals - Standardize npm scripts formatting in package.json
- Add family association to chat fixtures and tests - Set consistent password digest for test users - Enable AI for test users - Add OpenAI access token for test environment - Update chat and user model tests to include family context
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a continuation of #1985 and finalizes the "V1" of the personal finance AI chat feature.
Domain overview
Chat
- has many messages, has one "assistant"Chat::Debuggable
- defines "debug mode", where the chat will persist verbose debug messages to help better understand the path it took to get to its final responseMessage
- a message can be a "user message", "assistant message", or "developer message" (uses STI)ToolCall
- belongs to aMessage
and is a "subroutine" a message uses to augment its response. Tool calls are only relevant forassistant
messages and are optional.Assistant
- owned byChat
, this represents a generic "LLM assistant" that can perform chat completionsAssistant::Provided
is responsible for finding the correct provider for a given response (i.e. the user can select a model to use for each message)Assistant::Functions
- the assistant comes with a library of pre-defined "functions" that the LLM provider can call to augment chat responses. AnAssistant::Functions::ConcreteFunction
must provide aname
,description
,parameters
schema, andcall(params = {})
method. These are passed to and executed by the Provider.Provider::ConcreteLLMProvider
(e.g.Provider::OpenAI
)Assistant::Provideable
defines the interface that all LLM providers must implement to provide completions for the assistantSwappable LLM Providers
This first version of the chat implements a single
Provider::OpenAI
, which implements to theAssistant::Provideable
interface.Provider responsibilities
Each "LLM Provider" is responsible for:
Assistant::Provideable::ChatResponse
for theAssistant
to useConcrete LLM implementations
To introduce a new LLM, simply implement the interface:
This way,
Assistant
can easily choose different models for each chat message:Turbo frames, streams, and broadcasts
The AI chat feature is entirely contained within the global sidebar, and uses Turbo frames to load the various resource views for the
Chat
resource (i.e.new
,show
,index
).In
application.html.erb
layout, thechat_view_path(@chat)
helper is used to determine which resource view should currently show in the chat sidebar:@chat
is set and it is a persisted record, the sidebar loads theshow
path@chat
is set and its a new record, the sidebar loadsnew
@chat
isnil
, showindex
Chat state
There are two important concepts for managing the sidebar chat state:
@chat
controller instance variableThe
@chat
variable is set via inheritance inApplicationController
andChatsController
. In other words, the sidebar defaults to showing the "last viewed chat" unless told otherwise by a more specific action in the inheritance hierarchy:Broadcasts and "thinking"
Assistant responses run in background jobs and therefore require a "thinking" indicator. The base
Message
model implements bothcreate
andupdate
callbacks, which both broadcast the changes to the Chat ifbroadcast?
returns true on the specific type.show
action can have a?thinking=true
param to trigger the AI "thinking" message. TheAssistantResponseJob
is then responsible for removing that message when the response is complete (otherwise, it is just removed on the next page refresh since the param is passed in a turbo frame). SeeChatsController#create
andMessagesController#create
where weredirect_to chat_path(@chat, thinking: true)
to immediately show the "thinking" message.