This commit is contained in:
2023-11-24 02:56:21 +00:00
parent c8d7456e0c
commit 27ae99afeb
2 changed files with 50 additions and 6 deletions

View File

@@ -645,12 +645,25 @@ function work(a::agentReflex, usermsg::String)
respond = split(respond, "<|im_end|>")[1]
@show respond
#WORKING extract Act/ActInput
headerToDetect = ["Question:", "Plan:", "Thought:", "Act:", "ActInput:", "Obs:", "...", "Answer:",
"Conclusion:", "Summary:"]
headers = detectCharacters(respond, headerToDetect)
@show headers
chunkedtext = chunktext(respond, headers)
@show chunkedtext
toolname = toolNameBeingCalled(chunkedtext["Act:"], a.tools)
@show toolname
toolinput = chunkedtext["ActInput:"]
@show toolinput
error("work done 1")
else # finish all steps
else #TODO finish all steps
error("work done 2")
break
end
@@ -663,6 +676,12 @@ function work(a::agentReflex, usermsg::String)
end
end
function actor(a::agentReflex, usermsg::String)
end
"""
make a conversation summary.
```jldoctest
@@ -724,7 +743,7 @@ function conversationSummary(a::T) where {T<:agent}
summary = summary[2:end]
end
end
println("conversation summary: $summary")
return summary
end
@@ -1109,21 +1128,39 @@ end
```
"""
function chunktext(text::T, headers) where {T<:AbstractString}
result = []
result = Dict()
for (i, v) in enumerate(headers)
if i < length(headers)
nextheader = headers[i+1]
body = text[v[:stop]+1: nextheader[:start]-1]
push!(result, (header=v[:char], body=body))
# push!(result, (header=v[:char], body=body))
result[v[:char]] = body
else
body = text[v[:stop]+1: end]
push!(result, (header=v[:char], body=body))
# push!(result, (header=v[:char], body=body))
result[v[:char]] = body
end
end
return result
end
# function chunktext(text::T, headers) where {T<:AbstractString}
# result = []
# for (i, v) in enumerate(headers)
# if i < length(headers)
# nextheader = headers[i+1]
# body = text[v[:stop]+1: nextheader[:start]-1]
# push!(result, (header=v[:char], body=body))
# else
# body = text[v[:stop]+1: end]
# push!(result, (header=v[:char], body=body))
# end
# end
# return result
# end
function extractStepFromPlan(a::agent, plan::T, step::Int) where {T<:AbstractString}

View File

@@ -21,6 +21,13 @@ using HTTP, JSON3
```
"""
function wikisearch(phrase::T) where {T<:AbstractString}
phrase = phrase[1] == " " ? phrase[2:end] : phrase
# prepare input phrase
if occursin("\"", phrase)
phrase = GeneralUtils.getStringBetweenCharacters(toolinput, "\"", "\"")
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"
response = HTTP.get(url)
json_data = JSON3.read(String(response.body))