diff --git a/src/ChatAgent.jl b/src/ChatAgent.jl index 2411420..39b073c 100755 --- a/src/ChatAgent.jl +++ b/src/ChatAgent.jl @@ -10,6 +10,9 @@ module ChatAgent include("type.jl") using .type + include("llmfunction.jl") + using .llmfunction + include("interface.jl") using .interface diff --git a/src/interface.jl b/src/interface.jl index 14edef2..ad62de9 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -1037,40 +1037,21 @@ function chunktext(text::T, headers) where {T<:AbstractString} return result end -""" - Search wikipedia. - Args: - 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(phrase::T) where {T<:AbstractString} - url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&titles=$(replace(phrase, " " => "%20"))&exintro=1&explaintext=1" - 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"] - catch - result = "No info available." - end - if result == "" - result = "No info available." - end - return result -end + + + + + + + + + + + + diff --git a/src/llmfunction.jl b/src/llmfunction.jl new file mode 100644 index 0000000..d141b93 --- /dev/null +++ b/src/llmfunction.jl @@ -0,0 +1,99 @@ +module llmfunction + +export wikisearch + +using HTTP, JSON3 + +#------------------------------------------------------------------------------------------------100 + +""" + Search wikipedia. + + Args: + 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(phrase::T) where {T<:AbstractString} + url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&titles=$(replace(phrase, " " => "%20"))&exintro=1&explaintext=1" + 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"] + catch + result = "No info available." + end + if result == "" + result = "No info available." + end + return result +end + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +end # end module \ No newline at end of file diff --git a/src/type.jl b/src/type.jl index 4ab0974..321e819 100644 --- a/src/type.jl +++ b/src/type.jl @@ -100,13 +100,6 @@ function agentReflex( Begin!""", ), tools::Dict=Dict( - :wikisearch=>Dict( - :name => "wikisearch", - :description => "Useful for when you need to search an encyclopedia", - :input => "Input is keywords and not a question.", - :output => "", - :func => wikisearch, # put function here - ), :chatbox=>Dict( :name => "chatbox", :description => "Useful for when you need to ask a customer for more context.", @@ -114,6 +107,13 @@ function agentReflex( :output => "" , :func => nothing, ), + # :wikisearch=>Dict( + # :name => "wikisearch", + # :description => "Useful for when you need to search an encyclopedia", + # :input => "Input is keywords and not a question.", + # :output => "", + # :func => wikisearch, # put function here + # ), # :wineStock=>Dict( # :name => "wineStock", # :description => "useful for when you need to search for wine by your description, price, name or ID.", @@ -153,7 +153,7 @@ function agentReflex( newAgent.role = role newAgent.roles = roles newAgent.thinkingFormat = thinkingFormat - newAgent.name = agentName + newAgent.agentName = agentName return newAgent end