Skip to content
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

Financial AI #1427

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ gem "logtail-rails"
gem "aws-sdk-s3", "~> 1.177.0", require: false
gem "image_processing", ">= 1.2"

# AI
gem "ruby-openai"

# Other
gem "bcrypt", "~> 3.1"
gem "jwt"
Expand All @@ -54,6 +57,7 @@ gem "csv"
gem "redcarpet"
gem "stripe"
gem "intercom-rails"
gem "holidays"
gem "plaid"

group :development, :test do
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ GEM
erubi (1.13.1)
et-orbi (1.2.11)
tzinfo
event_stream_parser (1.0.0)
faker (3.5.1)
i18n (>= 1.8.11, < 2)
faraday (2.12.2)
Expand Down Expand Up @@ -201,6 +202,7 @@ GEM
hashdiff (1.1.2)
highline (3.1.2)
reline
holidays (8.8.0)
hotwire-livereload (2.0.0)
actioncable (>= 7.0.0)
listen (>= 3.0.0)
Expand Down Expand Up @@ -432,6 +434,10 @@ GEM
sorbet-runtime (>= 0.5.10782)
ruby-lsp-rails (0.3.31)
ruby-lsp (>= 0.23.0, < 0.24.0)
ruby-openai (7.3.1)
event_stream_parser (>= 0.3.0, < 2.0.0)
faraday (>= 1)
faraday-multipart (>= 1)
ruby-progressbar (1.13.0)
ruby-vips (2.2.2)
ffi (~> 1.12)
Expand Down Expand Up @@ -539,6 +545,7 @@ DEPENDENCIES
faraday-multipart
faraday-retry
good_job
holidays
hotwire-livereload
hotwire_combobox!
i18n-tasks
Expand All @@ -563,6 +570,7 @@ DEPENDENCIES
redcarpet
rubocop-rails-omakase
ruby-lsp-rails
ruby-openai
selenium-webdriver
sentry-rails
sentry-ruby
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ bin/dev

# Optionally, load demo data
rake demo_data:reset

# Optionally, setup AI user
rake ai:setup
```

And visit http://localhost:3000 to see the app. You can use the following
Expand Down
29 changes: 29 additions & 0 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@
}
}

.loading-ellipsis {
display: inline-flex;
}

.dot {
@apply w-1.5 h-1.5 mx-1 bg-gray-400 rounded-full;
animation: ellipsis 1.5s infinite;
}

.dot:nth-child(2) {
animation-delay: 0.3s;
}

.dot:nth-child(3) {
animation-delay: 0.6s;
}

@keyframes ellipsis {

0%,
100% {
transform: scale(0.8);
}

50% {
transform: scale(1.3);
}
}

/* Custom scrollbar implementation for Windows browsers */
.windows {
::-webkit-scrollbar {
Expand Down
73 changes: 73 additions & 0 deletions app/controllers/chats_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class ChatsController < ApplicationController
def index
@chats = Current.user.chats.order(created_at: :desc)
end

def new
@chat = Current.user.chats.new
end

def create
@chat = Current.user.chats.create
@message = @chat.messages.create(
user: Current.user,
content: chat_params[:content],
role: "user"
)

# Stub reply from bot
reply = @chat.messages.create(

Choose a reason for hiding this comment

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

This could be moved to the model to clean things up a bit. Something like Message.create_pending_assistant_message

content: "...",
user: nil,
role: "assistant"
)

ChatJob.perform_later(@chat.id, reply.id)
NameChatJob.perform_later(@chat.id)

respond_to do |format|
format.turbo_stream {
render turbo_stream: turbo_stream.update("chat_content", partial: "chats/chat", locals: { chat: @chat })
}
end
end

def show
@chat = Current.user.chats.find(params[:id])
end

def update
@chat = Current.user.chats.find(params[:id])
@message = @chat.messages.create(
user: Current.user,
content: params[:message][:content],
role: "user"
)

# Stub reply from bot
reply = @chat.messages.create(
content: "...",
user: nil,
role: "assistant"
)
Comment on lines +48 to +52

Choose a reason for hiding this comment

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

If you move it to the model, that can be reused here.


ChatJob.perform_later(@chat.id, reply.id)
NameChatJob.perform_later(@chat.id)

respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.append("chat_messages", partial: "chats/message", locals: { message: @message }),
turbo_stream.append("chat_messages", partial: "chats/message", locals: { message: reply }),
turbo_stream.replace("chat_form", partial: "chats/form", locals: { chat: @chat })
]
end
end
end

private

def chat_params
params.require(:chat).permit(:content)
end
end
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ def totals_by_currency(collection:, money_method:, separator: " | ", negate: fal
.join(separator)
end

def markdown(text)
@@parser ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, tables: true)

@@parser.render(text).html_safe
end

def show_super_admin_bar?
if params[:admin].present?
cookies.permanent[:admin] = params[:admin]
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/chats_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ChatsHelper
end
Loading
Loading