-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: main
Are you sure you want to change the base?
Financial AI #1427
Conversation
Are you planning enable using Ollama too ? |
No immediate plans. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really like what you have going on here. Not sure if you're actually looking for feedback but I was bored and looking over the repo and decided to give some suggestions. Feel free to tell me to piss off 😄.
@@ -0,0 +1,4 @@ | |||
class Message < ApplicationRecord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth making the role
and status
an enum? Rails supports string enum values now.
if ENV.fetch("OPENAI_ACCESS_TOKEN", nil).present? | ||
OpenAI.configure do |config| | ||
config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN") | ||
config.log_errors = true if Rails.env.development? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do the following to simplify
config.log_errors = true if Rails.env.development? | |
config.log_errors = Rails.env.development? |
<div class="flex-1"> | ||
<div class="inline-block max-w-full"> | ||
<div class="text-sm prose text-gray-900" id="message_content_<%= message.id %>"> | ||
<% if message.content == '...' %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could move some of the logic to the model so the magic '...'
string logic isn't in several different places. Could be something like message.pending_message?
or something like that 🤷🏻.
<% if message.status == 'pending' %> | ||
Determing the best route to answer your question. | ||
<% elsif message.status == 'data' %> | ||
Grabbing the necessary information to answer your question. | ||
<% elsif message.status == 'processing' %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These become predicate methods if you use an enum.
@@ -8,13 +8,20 @@ | |||
<% end %> | |||
</div> | |||
|
|||
<main class="grow px-20 py-6 h-full <%= require_upgrade? ? "relative overflow-hidden" : "overflow-y-auto" %>"> | |||
<main class="grow py-6 h-full <%= require_upgrade? ? "relative overflow-hidden" : "overflow-y-auto" %>"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the class_names
helper here:
<main class="grow py-6 h-full <%= require_upgrade? ? "relative overflow-hidden" : "overflow-y-auto" %>"> | |
<main class="<%= class_names("grow py-6 h-full", {"relative overflow-hidden" => require_upgrade?, "overflow-y-auto" => !require_upgrade?}) %>"> |
<%= turbo_frame_tag "chat_content" do %> | ||
<div class="flex flex-col h-full"> | ||
<div id="chat_messages" class="grow overflow-y-auto"> | ||
<% @chat.messages.where.not(content: nil).where.not(content: "...").where.not(hidden: true).order(created_at: :asc).each do |message| %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you move the magic string to the Message
model you could make this a scope to filter it out.
) | ||
|
||
# Stub reply from bot | ||
reply = @chat.messages.create( |
There was a problem hiding this comment.
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
reply = @chat.messages.create( | ||
content: "...", | ||
user: nil, | ||
role: "assistant" | ||
) |
There was a problem hiding this comment.
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.
|
||
def perform(chat_id, message_id) | ||
chat = Chat.find(chat_id) | ||
nil if chat.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line won't ever be hit because find
would raise and ActiveRecord::RecordNotFound
error if there isn't a Chat
for the chat_id
.
|
||
private | ||
def determine_viability(openai_client, chat) | ||
chat_history = chat.messages.where.not(content: [ nil, "" ]).where.not(content: "...").where.not(role: "log").order(:created_at) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you extract the scope for where.not(content: "...")
then you can reuse that here.
Hi @Shpigford , curious about how the AI feature will work. At the moment, any estimate for the timing to have the first release? |
This will work only with OpenAI? Or another LLM? |
This is the start on integrating AI in to the app.
It's still very early and right now the major focus is on security and choice (making sure it's 100% opt-in).