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 13 commits into
base: main
Choose a base branch
from
Draft

Financial AI #1427

wants to merge 13 commits into from

Conversation

Shpigford
Copy link
Member

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).

@zdehasek
Copy link

zdehasek commented Dec 23, 2024

Are you planning enable using Ollama too ?

@Shpigford
Copy link
Member Author

Are you planning enable using Ollama too ?

No immediate plans.

Copy link

@chadwilken chadwilken left a 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

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?

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

Suggested change
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 == '...' %>

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 🤷🏻.

Comment on lines +24 to +28
<% 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' %>

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" %>">

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:

Suggested change
<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| %>

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(

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

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

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?

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)

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.

@asdasdad23332s
Copy link

Hi @Shpigford , curious about how the AI feature will work. At the moment, any estimate for the timing to have the first release?

@asdasdad23332s
Copy link

This will work only with OpenAI? Or another LLM?

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.

4 participants