146 lines
4.4 KiB
Julia
146 lines
4.4 KiB
Julia
module llmfunction
|
|
|
|
export wikisearch, winestock
|
|
|
|
using HTTP, JSON3
|
|
using GeneralUtils
|
|
using ..type, ..utils
|
|
#------------------------------------------------------------------------------------------------100
|
|
|
|
"""
|
|
Search wikipedia.
|
|
|
|
Arguments:
|
|
query (string): The query to search for
|
|
|
|
Returns:
|
|
string: The search result text from wikipedia
|
|
```jldoctest
|
|
julia> using HTTP, JSON3
|
|
julia> result = wikisearch("AMD")
|
|
"Advanced Micro Devices, Inc., commonly abbreviated as AMD, is an ..."
|
|
```
|
|
"""
|
|
function wikisearch(a::agentReflex, phrase::T) where {T<:AbstractString}
|
|
phrase = phrase[1] == " " ? phrase[2:end] : phrase
|
|
# prepare input phrase
|
|
if occursin("\"", phrase)
|
|
phrase = GeneralUtils.getStringBetweenCharacters(phrase, "\"", "\"")
|
|
end
|
|
phrase = replace(phrase, "\n"=>"")
|
|
|
|
url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&titles=$(replace(phrase, " " => "%20"))&exintro=1&explaintext=1"
|
|
@show url
|
|
response = HTTP.get(url)
|
|
json_data = JSON3.read(String(response.body))
|
|
page_id = first(keys(json_data["query"]["pages"]))
|
|
if page_id == "-1"
|
|
return "Sorry, I couldn't find any Wikipedia page for the given phrase."
|
|
end
|
|
|
|
result = nothing
|
|
try
|
|
result = json_data["query"]["pages"][page_id]["extract"]
|
|
wiki = result
|
|
@show wiki
|
|
catch
|
|
result = "No info available for your search query."
|
|
end
|
|
|
|
# if result == ""
|
|
# result = "No info available for your search query."
|
|
# else
|
|
# result = makeSummary(a, result)
|
|
# end
|
|
|
|
return result
|
|
end
|
|
|
|
|
|
|
|
|
|
function winestock(a::agentReflex, phrase::T) where {T<:AbstractString}
|
|
# result = [
|
|
# Dict(
|
|
# "name" => "Louis Latou - Corton-Charlamagne - Chardonnay",
|
|
# "description" => "Corton-Charlemagne 2018 is a powerful, complex wine. Its nose is intense, with notes of white stone fruits such as white peach, fresh hazelnut, vanilla, and almond paste. The wine is full-bodied for the palate, and the vanilla is complemented by aromas of fresh almond and lime blossom. The experience ends with a very fine aromatic aftertaste that has subtle saline notes.",
|
|
# "price" => "49",
|
|
# "ID" => "ws-114"
|
|
# ),
|
|
# Dict(
|
|
# "name" => "Louis Latou - Corton-Charlamagne - Chardonnay",
|
|
# "description" => "Corton-Charlemagne 2018 is a powerful, complex wine. Its nose is intense, with notes of white stone fruits such as white peach, fresh hazelnut, vanilla, and almond paste. The wine is full-bodied for the palate, and the vanilla is complemented by aromas of fresh almond and lime blossom. The experience ends with a very fine aromatic aftertaste that has subtle saline notes.",
|
|
# "price" => "49",
|
|
# "ID" => "ws-114"
|
|
# )
|
|
# ]
|
|
|
|
result =
|
|
"""
|
|
1. Name: Louis Latou - Corton-Charlamagne - Chardonnay,
|
|
Description: Corton-Charlemagne 2018 is a powerful, complex wine. Its nose is intense, with notes of white stone fruits such as white peach, fresh hazelnut, vanilla, and almond paste. The wine is full-bodied for the palate, and the vanilla is complemented by aromas of fresh almond and lime blossom. The experience ends with a very fine aromatic aftertaste that has subtle saline notes.,
|
|
Price: 49 dollars,
|
|
ID: ws-114
|
|
2. Name: Chateau de Beaucastel Hommage Jacques Perrin Chateauneuf-du-Pape,
|
|
Year: 2019,
|
|
Description: The quintessence of Château de Beaucastel, Hommage à Jacques Perrin delights us every year, and the 2019 vintage is no exception. To the eye it offers a splendid deep red color, verging on black. Full of power and supremely elegant, the nose is of magnificent aromatic complexity with notes of black fruit and spices that offer all the characteristic expression of Mourvèdre. Perfectly balanced by an incredible freshness, the mouth is eminently elegant with intense and complex aromas of great subtlety, a full, refined texture, subtle tannins of great finesse, and infinite length. A great classic Hommage à Jacques Perrin.,
|
|
Price: 42,
|
|
ID: ed-23
|
|
3. Name: M. Chapoutier Ermitage l'Ermite Blanc,
|
|
Year: 2017
|
|
Description: Brilliant pale yellow. Complex aromas of vanilla, almonds, dried fruits and linden-tree. The mineraliaty is marked (typical of soil). Very round and rich wine. An elegant balance, of very ripe white fruit aromas (peach and apricot) and light notes of minerality. Beautiful length and complexity.,
|
|
Price: 13,
|
|
ID: wwr-259
|
|
"""
|
|
return result
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end # end module |