Non-OpenAI support for prompt-backed-actions has been merged into Ash AI
Zach Daniel (@zachdaniel.dev)
π€Just merged support for non-OpenAI models in prompt-backed-actions (structured outputs) via adapters. The adapter is inferred from the model, and supplied via an option otherwise. Thanks to @brainlid.bsky.social for LangChain, it's been very useful for Ash AI.
#AshFramework #ElixirLang
Bluesky

34 Replies
Why does it need Enumerable?
define analyze_sentiment, args: [:text]
Can we improve the error a little ?
I have been bitten by not defining
args
in define.
Will send PR
Can you tell me module / relevant place where the validation/ error has to be popped Up?Its in
Ash.CodeInterface
I think?
Probably line 660:
We should just wrap that an a try/rescue I think?Also,
how to define my
LangChain.ChatModels.ChatOpenAI.new!(%{ model: "gpt-4o", api_key: System.get_env("OPENAI_API_KEY"), endpoint: System.get_env("OPENAI_ENDPOINT")}),
defining this here does not work. How to run custom elixir code just before prompt? so that I can use these environment variables/.
you configure those things in your application config
in
runtime.exs
it is there. I want to config the endpoint as well.
How is that normally configured in langchain?
https://github.com/brainlid/langchain/blob/7e0959d894aa229e474679651814b760b04fb417/lib/chat_models/chat_open_ai.ex#L139-L150
----
it is defined here
GitHub
langchain/lib/chat_models/chat_open_ai.ex at 7e0959d894aa229e474679...
Elixir implementation of a LangChain style framework that lets Elixir projects integrate with and leverage LLMs. - brainlid/langchain
tried this. This does not work.
error
What is your open api endpoint configured to be?
It seems like a misconfiguration to me, you may want to start off just using langchain directly to figure out the options you're trying to set for example
the issue seems unrelated to Ash's prompt action
Thanks. I had messed up environment variables.
fn _, _
was a the trick I could not figure out myself though.
Should I add that to usage_rules.md of ash_ai ?Yes please π and also the other docs somewhere
fun fact, you can clone down
ash_ai
, paste our back and forth into claude and ask it to update the docs accordingly and you'll get a decent result
πI must say, with Ash, I always have this feeling that 'there is a way this works , i just don't know how' π
life saver!
Its the nature of the beast w/ a 0.1 package TBH
Anyone using it is abit of a pioneer
but as long as we focus on docs anytime anything is confusing, we can fix these problems
Also, out of curiosity, what are you trying to do?
Are you trying to use a different OpenAI compatible model?
Because that other model likely does not support json schema responses
You'll likely need to use the new completion tool adapter
Using kluster.ai for now, because they i got credits there.
I will write a generic adapter which can extract json via LangChain Jsonprocessor and then coerce them to ash types.
Without tool calls.
High level goal - Writing dspy in elixir.
We should add a built in adapter for that
thats the strategy I didn't add yet
which is "ask nicely for JSON" π
Point me to the relevant place / file !
Basically just copying and modifying the
CompletionTool
adapterBaml is a project which does this.
They ask nicely for json, then coerce the json into their own types
Yeah so we have the infra, the adapters are pretty straightforward
but if they support tool calls then
CompletionTool
is better to use typicallyAgreed. Not everyone does. π
But we can add a fallback LLM to fallback to asking nicely for JSON even on the completion tool one
That way if the agent doesn't call the tool w/in max runs we fallback to asking nicely for JSON and trying to parse it
How would that work ?
A new
FallbackTool
which first uses CompletionTool and then NiceJsonTool (if previous fails)?https://hexdocs.pm/langchain/0.3.3/LangChain.Chains.LLMChain.html#run_until_tool_used/3
either with
with_fallbacks
(something we may need to figure out how to integrate) or with just handling the error case and starting a new chainI'll try the error and new chain for now. See how far can we go
I think your first thing would be the new adapter
since you know your model doesn't support tools
Yup.
1. New adapter
2. Fallback adapter
3. Dspy example
1,3,2 in that order.
New PR in ash for code_interface validation.
https://github.com/ash-project/ash/pull/2102/files
it even caught two missing in existing tests. π
posting it here because the discussion context for the bug was here.
P.S.: I would need a little help from you regarding test cases. Claude wrote tests not sure how accurate that is.
Responded on PR