Skip to content

Instantly share code, notes, and snippets.

@zachdaniel
Created June 13, 2025 21:00
Show Gist options
  • Save zachdaniel/241c0b9bf46b76b654b5fb7f84563a13 to your computer and use it in GitHub Desktop.
Save zachdaniel/241c0b9bf46b76b654b5fb7f84563a13 to your computer and use it in GitHub Desktop.
action :analyze_sentiment, :atom do
constraints one_of: [:positive, :negative]
description """
Analyzes the sentiment of a given piece of text to determine if it is overall positive or negative.
"""
argument :text, :string do
allow_nil? false
description "The text for analysis"
end
run prompt(
LangChain.ChatModels.ChatOpenAI.new!(%{ model: "gpt-4o"}),
# setting `tools: true` allows it to use all exposed tools in your app
tools: true
# alternatively you can restrict it to only a set of tools
# tools: [:list, :of, :tool, :names]
# provide an optional prompt, which is an EEx template
# prompt: "Analyze the sentiment of the following text: <%= @input.arguments.description %>",
# adapter: {Adapter, [some: :opt]}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment