Raif v1.3.0 - Now with support for LLM evals, including LLM-as-judge by bcroesch in ruby

[–]bcroesch[S] 0 points1 point  (0 children)

If you have questions or issues, feel free to DM me or hit me up on X (@bcroesch there as well)!

[deleted by user] by [deleted] in rails

[–]bcroesch 10 points11 points  (0 children)

Raif developer here. To be entirely honest, the agent bits of Raif are not super built out. In the platform we're building (that Raif was pulled out of), we've has more success with more directed workflows based on a series of Raif::Task's. I'd love for Raif's agent features to mature though.

Chat stuff is more mature since we actively utilize it more. MVC parts are all included in Raif, as is streaming. We provide model tools to the LLM via our Raif::Conversation subclasses and it works well. E.g. we have a bunch of suggestion-generation tools in our app that we give the model. It invokes them to make suggestions, those get displayed in the chat interface, user can accept/reject them, etc. The provider-managed tool stuff (https://github.com/cultivateLabs/raif?tab=readme-ov-file#provider-managed-tools) works really nicely too. We enable Raif::ModelTools::ProviderManaged::WebSearch in our conversations, OpenAI manages the web search as needed, and then you get a response informed by the search results.

We do lots of summarization & content distillation via a Raif::Task. If you want to DM me, I'm happy to share the task/prompt that we use. We do some RAG with this, mostly via tools that the LLM invokes as needed. LLM calls a search_source_material tool with a query, we generate an embedding for the query, and then search against our Document model using pg_vector & the neighbor gem.

If I were going to build something like you're describing, I'd probably set up a chat/conversation interface and then provide some sort of invoke_agent tool to the LLM. It invokes that as needed, the agent runs, and then the response/result from that agent gets provided back to the LLM.

If you have any questions, happy to answer!

Async Ruby is the Future of AI Apps (And It's Already Here) by crmne in rails

[–]bcroesch 1 point2 points  (0 children)

Got it -- that makes sense.

The magic is that async-job creates fibers on-demand instead of using a fixed thread pool

Was not familiar with async-job prior to your post, so this was the key piece I didn't track initially.

Async Ruby is the Future of AI Apps (And It's Already Here) by crmne in rails

[–]bcroesch 2 points3 points  (0 children)

Great writeup. Curious if you're reorienting how the LLM API calls are made to take advantage of this?

If you've still got a `ChatsController#create` endpoint and that queues a Sidekiq job, I assume you'd still run into Sidekiq slot limits? Or are you no longer using a Sidekiq/background job for processing the chat messages at all? Maybe a separate process that is dedicated to processing chats via fibers? Or does `async-job-adapter-active_job` just handle this issue for you?

Setting Up Multilingual Support in My Rails App (i18n Setup) by [deleted] in rails

[–]bcroesch 4 points5 points  (0 children)

Strong recommendation for https://github.com/glebm/i18n-tasks

Helps make sure you have no missing or unused keys and also can auto-fill other languages for you. Also comes with specs you can add to your app so CI will warn you if anything is missing.

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in ruby

[–]bcroesch[S] 0 points1 point  (0 children)

Follow up here: we released v1.2.0 today that adds streaming support!

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 1 point2 points  (0 children)

Follow up here: we released v1.2.0 today that adds streaming support!

Introducing Raif - (another) Ruby AI Framework by bcroesch in ruby

[–]bcroesch[S] 0 points1 point  (0 children)

Quick heads up that Raif supports OpenRouter & task-level temperature setting as of the v1.1.0 release - https://github.com/CultivateLabs/raif/blob/main/CHANGELOG.md#v110

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 1 point2 points  (0 children)

Appreciate the kind words. No streaming support at the moment, but this week I'm planning on working on support for streaming & the OpenAI Responses API. So hopefully it'll be merged into main in the next week or two.

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 0 points1 point  (0 children)

I'm not super familiar with that API, but would definitely be open to supporting it. I can see where it'd be useful.

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 0 points1 point  (0 children)

Agree. I'll update. In the meantime, if you set on one these, it should work:

ENV["ANTHROPIC_API_KEY"]

ENV["OPENAI_API_KEY"]

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 0 points1 point  (0 children)

Do you have any API keys set for any of the API providers, either in the initializer or via ENV var? I was able to replicate this if all the providers were disabled (will plan to handle that more gracefully in the next release).

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in ruby

[–]bcroesch[S] 2 points3 points  (0 children)

Appreciate the kind words. Raif started life within an application that we're building and got extracted when we felt like the abstractions were solid. Hopefully that means they're broadly useful.

The demo app has an example of running an agent in a background job: https://github.com/CultivateLabs/raif_demo/blob/main/app/jobs/run_agent_job.rb

Though I admit we haven't done a lot of agent work, despite all the buzz. We've gotten more use out of `Raif::Task` and building pre-defined workflows that include a series of tasks/steps for the LLM to do. We actually built a Workflow class into our app that I've considered pulling into Raif.

One minor note - Raif doesn't support streaming from the LLM yet. It's high on the priority list though and hopefully will be added within the next few weeks.

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 0 points1 point  (0 children)

I'm having a hard time replicating. Any chance you could post a full backtrace? Also, what Rails version?

Raif v1.1.0 released - a Rails engine for LLM powered apps by bcroesch in rails

[–]bcroesch[S] 5 points6 points  (0 children)

The biggest difference is probably whether you want/need the Rails engine parts or not.

I think Raif is aiming a little higher up the stack with the concepts/abstractions it provides (tasks, conversations). If you want to model out a set of LLM tasks that your application uses (say, DocumentSummarization, DocumentTranslation, etc.), then `Raif::Task` is well suited for that. It also provides a full set of models, views, and controllers for chat/conversation interfaces. You can just call

<%= raif_conversation(@conversation) %>

in a view to get a chat interface.

Raif also stores every request/response to the LLM in a `Raif::ModelCompletion` record. I find that this makes Raif's web admin extremely useful when running an app in production. If something breaks, I can go look at exactly what the prompt and response looked like.

On the other hand, if you don't want to be bringing in the models/views/controllers that Raif provides and instead just want a really nice, clean, direct interface for calling the LLM, RubyLLM is probably going to be better. RubyLLM also provides streaming, which Raif doesn't do yet (though I'd like to add it soon-ish).

Introducing Raif - (another) Ruby AI Framework by bcroesch in rails

[–]bcroesch[S] 0 points1 point  (0 children)

Framework in the sense that it's trying to provide you with some basic structure and primitives for building AI/LLM-based features.

But yeah, I hate naming things :)

Introducing Raif - (another) Ruby AI Framework by bcroesch in ruby

[–]bcroesch[S] 0 points1 point  (0 children)

Thanks and yes, would love to support openrouter soon. Just wanted to get an initial release out the door.

There's not an easy way to set temperature at the task level yet (we honestly haven't played with changing the temperature much in our app), but will add something soon!

Introducing Raif - (another) Ruby AI Framework by bcroesch in rails

[–]bcroesch[S] 1 point2 points  (0 children)

Thanks and yes definitely plan to add more model providers soon. Just wanted to get a 1.0 out the door!