Background AI translator in Ash
https://kenkost.substack.com/p/background-ai-translator-in-ash
I also posted it on my blog where code blocks look better:
https://kenkost.me/blog/background-ai-translator-in-ash
As promised, I made a tutorial where I use
AshOban
, AshTrans
and LangChain
to do translations for database fields. First real article I made. 🎉
It's nothing fancy and might not even be worth an article & I'm sure there's like a million things I could've done better 😅 but I wanted to do it & so I did. 👺
tagging @Nefcairon because he wanted to see something in regards to ash trans, don't know if it will be helpful. But AFAIS ash trans is simple, not much to it. 🤷Background AI Translator in Ash
Tutorial on how to trigger a background job (AshOban) to translate (LangChain) database fields and store them (AshTrans)
Background AI Translator in Ash
Tutorial on how to trigger a background job (AshOban) to translate (LangChain) database fields and store them (AshTrans)
7 Replies
Very interesting!
I'm not familiar with AshOban yet,
Does that mean the whole action itself runs in an Oban job? What does the action return then?
the trigger triggers an oban job that does
:translate
action in the job, :update_about_me
action just updates :about_me
and calls the trigger.
In the Run section you can see that this action returns a record where translations are nil, but you also see the triggering after.oh I see! I kinda skimmed over that part, sorry about that 😅 thanks!
so the action runs normally as an update action, and enqueues an oban job as a side effect
exactly! 🤠
What's the advantage of using AshTrans vs Gettext + Cldr?
I'm guessing the ability to translate dynamic values
afaik the translation is stored in db. So it can change on runtime. It says: "AshTrans - An Ash extension that provides translations to a resource."
you can use ash_trans with cldr
I will go trough your tutorial as soon as the heat is gone... regarding ash_trans I will still have to wait to see somebody using it with liveview (it's the same as with ash in general: I know how to use it backend-wise, but as soon as I want to use it with phoenix-liveview, I'm blocked; most beginner ash tutorials end before that step).
yes, I think this enables you to have translations not only for the static parts, but everything. & taken to extreme, if everything was dynamic i.e. stored in the db then no more work needed with gettext. But idk, that's extreme. 😆
yea, I haven't played with this on FE (yet), but I imagine you just need the locale key, with it you can fetch the appropriate translation of a resource. but now that you mention this, maybe I could further expand this, a part 2, which I hinted at in the conclusion 🤔 I'll think about it. 👍