Ash FrameworkAF
Ash Framework2mo ago
7 replies
jannibeu

Why is this changeset not applied?

    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 translation: "Someone boils an egg."

What am I doing wrong?
Was this page helpful?