# /blank: A blank template.
#
let main = fun(args: {input: Str}) -> {output: Str} do
let output = args.input
return(output)
end
#
# /echoInput: An action that returns the input object.
# Illustrates how to specify the input and output types.
#
# A custom input type object with many properties.
let Args = type {
# Name: a mandatory string.
mandatory!: Str,
# Age: an optional integer.
age: Int,
# Favorite number: a mandatory number (float).
favorite!: Num,
# Hobbies: an optional array of strings.
hobbies: [Str],
# is_green: a mandatory boolean.
is_green!: Bool,
# Coffee: a mandatory string.
coffee!: Enum(Str, ["espresso", "cortado", "latte", "cappuccino"])
}
# Echo the input.
let main = fun(args: Args) -> Args do
return(args)
end
#
# /summarize: An action to scrape pages and summarize the
# information they contain about a given topic.
#
# Given a topic, summarize the information about it found
# in the web.
let main = fun(args: {topic!: Str}) -> {summary: Str} do
# First we create an oracle for summarizing information.
# Given a topic and text from web pages, summarize the
# information about the requested topic.
let summarize = oracle(topic: Str, text: Str) -> Str
# Next we get some auxiliary actions.
let googleSearch = getAction("@daios/google/search")
let webScrape = getAction("@daios/webscraping/www")
# Perform a Google search.
let results = googleSearch({query: args.topic})
println(results)
let text = ""
for n in range(0, 3) do
let link = results.organic[n].link
let page = webScrape({url: link})
if page == null do
continue(null)
end
text = text + "page: " + page.text + "\\n\\n"
end
# Summary of the page results.
let summary = summarize(args.topic, text)
return({summary: summary})
end