LangChain.Portals (langchainex v0.2.3)

A "portal" is a function that transports knowledge between the semantic and BEAM knowledge domains A standard langhchain 'prompt' is a 'portal' into the semantic domain Likewise a template that an LLM can use to fill in Elixir code is a 'portal' into the BEAM knowledge domain

Link to this section Summary

Functions

a whirpool portal is a portal from semantic/AI knowledge domain into a VM's knowledge domain. This function will recursively ask the AI to update a snippet of Elixir source code (usally something very simply like scraping and decoding some JSON that was spit out by an LLM query) until that source code evaluates correctly with Code.eval_string. This usually only takes one iteration, since the LLM is shown both the failing code and the resulting error message, but I've seen it kind of....meander a little...before coming back.

Link to this section Functions

Link to this function

whirlpool_portal(model, elixir_code, options \\ [])

a whirpool portal is a portal from semantic/AI knowledge domain into a VM's knowledge domain. This function will recursively ask the AI to update a snippet of Elixir source code (usally something very simply like scraping and decoding some JSON that was spit out by an LLM query) until that source code evaluates correctly with Code.eval_string. This usually only takes one iteration, since the LLM is shown both the failing code and the resulting error message, but I've seen it kind of....meander a little...before coming back.

I don't try to make long elaborate elixir_code snippets, I keep them pretty simple. Example: model = %LangChain.Providers.OpenAI.LanguageModel{} # notice this JSON is broken, so this will throw a SyntaxError the first time we eval_string it: elixir_code = "Jason.decode!("{"a": 1")" # whirlpool portal isn't fazed it will make up to 3 iterations to try to correct this code { value, bindings } = Courierlive.EmailParser.whirlpool_portal(model, elixir_code, max_steps: 3) # value will be this Elixir struct: %{"a" => 1}

Options: :bindings - a map of bindings to use when evaluating the elixir_code :max_attempts - the maximum number of attempts to make before giving up