LangEx.LLM.OpenAI (LangEx v0.11.3)

Copy Markdown View Source

OpenAI chat completions adapter with tool/function calling support.

Supports GPT-4o and other OpenAI models (and OpenAI-compatible APIs like OpenRouter) via the /v1/chat/completions endpoint.

Tool Calling

Pass :tools (list of %LangEx.Tool{}) to enable tool calling. The adapter returns {:ok, %Message.AI{tool_calls: [...]}} when the model requests tool calls. Use LangEx.Tool.Node to execute them.

LangEx.LLM.OpenAI.chat(messages,
  model: "gpt-4o-mini",
  tools: [%LangEx.Tool{name: "get_weather", ...}]
)