update :translate_to_en do change fn changeset, _context -> term = changeset.data description = term.description openai = ChatOpenAI.new!(%{ model: "gpt-4o-mini", }) {:ok, openai} = ChatOpenAI.new(%{model: "gpt-4o-mini"}) {:ok, chain} = LLMChain.new!(%{llm: openai}) |> LLMChain.add_message(Message.new_system!("You are a professional translator. Translate text to English accurately. Only return the text. Do not add any prose or 'okay'. Just the text, no quotes or anything.")) |> LLMChain.add_message(Message.new_user!(description)) |> LLMChain.run(mode: :step) %LangChain.Chains.LLMChain{last_message: last_message} = chain [%LangChain.Message.ContentPart{content: translation}] = last_message.content IO.inspect(translation, label: "translation") changeset |> Ash.Changeset.change_attribute(:translation_en, translation) end end
update :translate_to_en do change fn changeset, _context -> term = changeset.data description = term.description openai = ChatOpenAI.new!(%{ model: "gpt-4o-mini", }) {:ok, openai} = ChatOpenAI.new(%{model: "gpt-4o-mini"}) {:ok, chain} = LLMChain.new!(%{llm: openai}) |> LLMChain.add_message(Message.new_system!("You are a professional translator. Translate text to English accurately. Only return the text. Do not add any prose or 'okay'. Just the text, no quotes or anything.")) |> LLMChain.add_message(Message.new_user!(description)) |> LLMChain.run(mode: :step) %LangChain.Chains.LLMChain{last_message: last_message} = chain [%LangChain.Message.ContentPart{content: translation}] = last_message.content IO.inspect(translation, label: "translation") changeset |> Ash.Changeset.change_attribute(:translation_en, translation) end end
I'm expecting the changeset to end up in the translation_en attribute. The log is
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.