update
This commit is contained in:
@@ -5,7 +5,7 @@ export agentReact, addNewMessage, clearMessage, removeLatestMsg, generatePrompt_
|
||||
generatePrompt_tokenSuffix, conversation, work, detectCharacters, chunktext,
|
||||
findDetectedCharacter
|
||||
|
||||
using JSON3, DataStructures, Dates, UUIDs
|
||||
using JSON3, DataStructures, Dates, UUIDs, HTTP
|
||||
using CommUtils, GeneralUtils
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
@@ -112,10 +112,10 @@ function agentReact(
|
||||
""",
|
||||
),
|
||||
tools::Dict=Dict(
|
||||
:internetsearch=>Dict(
|
||||
:name => "internetsearch",
|
||||
:wikisearch=>Dict(
|
||||
:name => "wikisearch",
|
||||
:description => "Useful for when you need to search the Internet",
|
||||
:input => "Input should be a search query.",
|
||||
:input => "Input should be a search keywords.",
|
||||
:output => "",
|
||||
:func => nothing # put function here
|
||||
),
|
||||
@@ -263,45 +263,6 @@ end
|
||||
# return prompt
|
||||
# end
|
||||
|
||||
function generatePrompt_react_mistral_openorca(messages::Dict, systemMsg::String, context::String="",
|
||||
tools::Union{Dict, Nothing}=nothing)
|
||||
promptTemplate =
|
||||
"""
|
||||
<|im_start|>system
|
||||
{systemMsg}
|
||||
You have access to the following tools:
|
||||
{tools}
|
||||
Begin!
|
||||
<|im_end|>
|
||||
Here are the context for the question:
|
||||
{context}
|
||||
"""
|
||||
for msg in messages
|
||||
role = msg[:role]
|
||||
content = msg[:content]
|
||||
|
||||
if role == "system"
|
||||
prompt = replace(promptTemplate, "{systemMsg}" => systemMsg)
|
||||
toollines = ""
|
||||
for tool in tools
|
||||
toolline = "$(tool[:name]): $(tool[:description]) $(tool[:input]) $(tool[:output])\n"
|
||||
toollines *= toolline
|
||||
end
|
||||
|
||||
prompt = replace(promptTemplate, "{tools}" => toollines)
|
||||
prompt = replace(promptTemplate, "{context}" => context)
|
||||
elseif role == "user"
|
||||
prompt *= "<|im_start|>user\n" * content * "\n<|im_end|>\n"
|
||||
elseif role == "assistant"
|
||||
prompt *= "<|im_start|>assistant\n" * content * "\n<|im_end|>\n"
|
||||
else
|
||||
error("undefied condition role = $role")
|
||||
end
|
||||
end
|
||||
|
||||
return prompt
|
||||
end
|
||||
|
||||
function generatePrompt_mistral_openorca(a::T, usermsg::String) where {T<:agent}
|
||||
prompt =
|
||||
"""
|
||||
@@ -890,7 +851,7 @@ end
|
||||
(char = "use", start = 26, stop = 28)
|
||||
(char = "i", start = 35, stop = 35) ]
|
||||
julia> findDetectedCharacter(a, "i")
|
||||
[1, 4]
|
||||
[1, 4]
|
||||
```
|
||||
"""
|
||||
function findDetectedCharacter(detectedCharacters, character)
|
||||
@@ -929,6 +890,18 @@ function chunktext(text::T, headers) where {T<:AbstractString}
|
||||
end
|
||||
|
||||
|
||||
function wikisearch()
|
||||
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
|
||||
|
||||
return json_data["query"]["pages"][page_id]["extract"]
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user