update
This commit is contained in:
221
src/interface.jl
221
src/interface.jl
@@ -273,6 +273,7 @@ function updatePlan(a::agentReflex)
|
||||
|
||||
prompt =
|
||||
"""
|
||||
<s>
|
||||
<|system|>
|
||||
$(a.roles[a.role])
|
||||
Request the user’s input for the following info initially, and use alternative sources of information only if they are unable to provide it:
|
||||
@@ -307,8 +308,8 @@ function updatePlan(a::agentReflex)
|
||||
|
||||
end
|
||||
|
||||
|
||||
# function selfAwareness(a::agentReflex)
|
||||
|
||||
# getonlykeys = ["Actinput", "Obs"]
|
||||
# worknoplan = similar(a.memory[:shortterm])
|
||||
# for (k, v) in a.memory[:shortterm]
|
||||
@@ -332,40 +333,6 @@ end
|
||||
|
||||
# """
|
||||
|
||||
# # prompt =
|
||||
# # """
|
||||
# # <|system|>
|
||||
# # <About yourself>
|
||||
# # $aboutYourself
|
||||
# # $(a.roleSpecificInstruction[a.role])
|
||||
# # </About yourself>
|
||||
# # <Your earlier work>
|
||||
# # $work
|
||||
# # </Your earlier work>
|
||||
|
||||
# # <Your plan>
|
||||
# # $(a.memory[:shortterm]["Plan 1:"])
|
||||
# # </Your plan>
|
||||
# # <Your job>
|
||||
# # Use the following format strictly:
|
||||
# # What do I know: based on observed results, repeat all the information you got.
|
||||
# # Info matching: using JSON format, explicitly state what information matches which variable name in my plan.
|
||||
# # What am I missing: based on Info match, describe in detail what you are still missing based on the plan.
|
||||
# # P.S. do not mention any toolnames
|
||||
# # </Your job>
|
||||
# # <Example>
|
||||
# # What do I know:
|
||||
# # - The user is buying an electric SUV car.
|
||||
# # Info matching: {"car type": "SUV", "engine": "electric motor", "color": "N/A", "financing": "N/A"}
|
||||
# # What am I missing:
|
||||
# # - The user's preferred color
|
||||
# # - The user's financing method
|
||||
# # </Example>
|
||||
# # </s>
|
||||
# # <|assistant|>
|
||||
# # What I know:
|
||||
# # """
|
||||
|
||||
# prompt =
|
||||
# """
|
||||
# <|system|>
|
||||
@@ -376,36 +343,62 @@ end
|
||||
# <Your earlier work>
|
||||
# $work
|
||||
# </Your earlier work>
|
||||
|
||||
# <Your plan>
|
||||
# $(a.memory[:shortterm]["Plan 1:"])
|
||||
# </Your plan>
|
||||
# <Your keyword memory>
|
||||
# $(JSON3.write(a.memory[:keyword]))
|
||||
# </Your keyword memory>
|
||||
# <Your job>
|
||||
# Use the following format strictly:
|
||||
# What I know: based on observed results, repeat all the information you got thoroughly
|
||||
# Info match: using JSON format, explicitly state what information might matches which variable name in my plan
|
||||
# What am I missing: based on Info match, describe in detail what you are still missing based on the plan
|
||||
# P.S. do not mention any toolnames
|
||||
# Info extraction: repeat all important info from the latest observed result thoroughly
|
||||
# Info mapping: based on extracted info, explicitly state what each info could match which keyword memory's key
|
||||
# Info matching: using JSON format, what key in my memory matches which info
|
||||
# </Your job>
|
||||
|
||||
# <Example>
|
||||
# user response:
|
||||
# - EV could mean electric vehicle
|
||||
# What do I know:
|
||||
# - The user is buying an electric SUV car.
|
||||
# Info matching: {"car type": "SUV", "engine type": "electric motor", "color": "not know yet", "financing": "not know yet"}
|
||||
# What am I missing:
|
||||
# - The user's preferred color
|
||||
# - The user's financing method
|
||||
# <Your earlier work>
|
||||
# The user wants to buy an electric SUV car under 20000 dollars.
|
||||
# </Your earlier work>
|
||||
# <Your keyword memory>
|
||||
# {"car type": null, "color": null, "financing": null}
|
||||
# </Your keyword memory>
|
||||
# Info extraction:
|
||||
# - The user is buying an electric SUV car.
|
||||
# Info mapping:
|
||||
# - SUV could matches "car type" key
|
||||
# - electric could matches "engine type" key
|
||||
# Info matching: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
|
||||
# </Example>
|
||||
# </s>
|
||||
# <|assistant|>
|
||||
# What I know:
|
||||
# Info extraction:
|
||||
# """
|
||||
# response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
|
||||
# response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.2, timeout=180,
|
||||
# stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
|
||||
# response = split(response, "<|")[1]
|
||||
# response = split(response, "</")[1]
|
||||
# @show response
|
||||
# response = "Info extraction:" * response
|
||||
|
||||
# println("")
|
||||
# @show selfaware_1 = response
|
||||
|
||||
# headerToDetect = ["Info extraction:", "Info mapping:", "Info matching:", "Actinput"]
|
||||
# headers = detectCharacters(response, headerToDetect)
|
||||
|
||||
# # headers[1:2] is for when LLM generate more than a paire of "Info extraction" and "Info matching", discard the rest
|
||||
# chunkedtext = chunktext(response, headers[1:3])
|
||||
# println("")
|
||||
# _infomatch = chunkedtext["Info matching:"]
|
||||
# _infomatch = GeneralUtils.getStringBetweenCharacters(_infomatch, '{', '}', endCharLocation="next")
|
||||
# infomatch = copy(JSON3.read(_infomatch))
|
||||
|
||||
# println("")
|
||||
# @show chunkedtext
|
||||
|
||||
# keywordMemoryUpdate!(a.memory[:keyword], infomatch)
|
||||
|
||||
# response = "What I know about user:" * JSON3.write(a.memory[:keyword]) # * response
|
||||
# println("")
|
||||
# @show selfaware_2 = response
|
||||
|
||||
|
||||
# return response
|
||||
# end
|
||||
@@ -414,18 +407,24 @@ function selfAwareness(a::agentReflex)
|
||||
|
||||
getonlykeys = ["Actinput", "Obs"]
|
||||
worknoplan = similar(a.memory[:shortterm])
|
||||
for (k, v) in a.memory[:shortterm]
|
||||
count = 0
|
||||
for i in getonlykeys
|
||||
if occursin(i, k)
|
||||
count += 1
|
||||
worklength = length(a.memory[:shortterm])
|
||||
for (i, (k, v)) in enumerate(a.memory[:shortterm])
|
||||
if i >= worklength - 1
|
||||
count = 0
|
||||
for i in getonlykeys
|
||||
if occursin(i, k)
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
if count != 0
|
||||
worknoplan[k] = v
|
||||
end
|
||||
end
|
||||
if count != 0
|
||||
worknoplan[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
println("")
|
||||
@show worknoplan
|
||||
|
||||
work = dictToString(worknoplan)
|
||||
|
||||
aboutYourself =
|
||||
@@ -434,49 +433,53 @@ function selfAwareness(a::agentReflex)
|
||||
$(a.roles[a.role])
|
||||
|
||||
"""
|
||||
|
||||
#WORKING
|
||||
prompt =
|
||||
"""
|
||||
<s>
|
||||
<|system|>
|
||||
<About yourself>
|
||||
$aboutYourself
|
||||
$(a.roleSpecificInstruction[a.role])
|
||||
</About yourself>
|
||||
<Your earlier work>
|
||||
$work
|
||||
</Your earlier work>
|
||||
<Your keyword memory>
|
||||
$(JSON3.write(a.memory[:keyword]))
|
||||
</Your keyword memory>
|
||||
<Your job>
|
||||
Use the following format strictly:
|
||||
Info extraction: repeat all important info from the latest observed result thoroughly
|
||||
Info mapping: based on extracted info, explicitly state what each info could match which keyword memory's key
|
||||
Info matching: using JSON format, what key in my memory matches which info
|
||||
</Your job>
|
||||
|
||||
<Example>
|
||||
<Your earlier work>
|
||||
The user wants to buy an electric SUV car under 20000 dollars.
|
||||
</Your earlier work>
|
||||
<Your keyword memory>
|
||||
{"car type": null, "color": null, "financing": null}
|
||||
</Your keyword memory>
|
||||
</|system|>
|
||||
<Example>
|
||||
<Your earlier work>
|
||||
The user wants to buy an electric SUV car under 20000 dollars.
|
||||
</Your earlier work>
|
||||
<Your keyword memory>
|
||||
{\"car type\": null, \"color\": null, \"financing\": null}
|
||||
</Your keyword memory>
|
||||
<|assistant|>
|
||||
Info extraction:
|
||||
- The user is buying an electric SUV car.
|
||||
Info mapping:
|
||||
- SUV could matches "car type" key
|
||||
- electric could matches "engine type" key
|
||||
Info matching: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
|
||||
</Example>
|
||||
</s>
|
||||
<|assistant|>
|
||||
Info extraction:
|
||||
</|assistant|>
|
||||
</Example>
|
||||
</s>
|
||||
<Your earlier work>
|
||||
$work
|
||||
</Your earlier work>
|
||||
<Your keyword memory>
|
||||
$(JSON3.write(a.memory[:keyword]))
|
||||
</Your keyword memory>
|
||||
<|assistant|>
|
||||
Info extraction:
|
||||
"""
|
||||
response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.2, timeout=180,
|
||||
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
|
||||
response = split(response, "<|")[1]
|
||||
response = split(response, "</")[1]
|
||||
response = split(response, "</|assistant|>")[1]
|
||||
response = "Info extraction:" * response
|
||||
|
||||
println("")
|
||||
@@ -587,8 +590,6 @@ end
|
||||
# winestocksearchresult = "\n"
|
||||
# end
|
||||
|
||||
# #WORKING I need a llm json read function
|
||||
|
||||
# prompt =
|
||||
# """
|
||||
# <|system|>
|
||||
@@ -847,6 +848,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
- No info on the car color yet
|
||||
- No info on the financing method yet
|
||||
- Luxury level is high
|
||||
{\"car type\": "SUV",\"brand\":\"Lexus\",\"price\":\"20k dollar\",\"color\": null,\"financing method\": null, \"luxury level\":\"high\"}
|
||||
"""
|
||||
|
||||
prompt =
|
||||
@@ -862,7 +864,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
</You have access to the following tools>
|
||||
<Your job>
|
||||
Use the following format:
|
||||
Thought: considering what you know about the user and your plan thoroughly then you should think about what to do next by prioritize what you don't know (null means don't know) first. (PS. 1. let's think a single step. 2. pay attention to correct numeral calculation and commonsense.)
|
||||
Thought: considering what you know about the user thoroughly then you should think about what to do next according to your plan while prioritize what you don't know (null means don't know) first. (PS. 1. let's think a single step. 2. pay attention to correct numeral calculation and commonsense.)
|
||||
Act: based on your thought what action to choose?, must be one of [{toolnames}].
|
||||
Actinput: your input to the action (pay attention to the tool's input)
|
||||
Obs: observed result of the action
|
||||
@@ -873,7 +875,12 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
I'll ask the user for car type, brand, price, color, financing method and luxury level before I'll give them any advice.
|
||||
</my plan>
|
||||
<What I know about the user>
|
||||
{\"car type\": "SUV",\"brand\":\"Lexus\",\"price\":\"20k dollar\",\"color\": null,\"financing method\": null, \"luxury level\":\"high\"}
|
||||
- Car type is SUV
|
||||
- Brand is Lexus
|
||||
- Price is 20k dollar
|
||||
- No info on the car color yet
|
||||
- No info on the financing method yet
|
||||
- Luxury level is high
|
||||
</What I know about the user>
|
||||
<|assistant|>
|
||||
Thought: I still don't know what color the user like. I should ask the user.
|
||||
@@ -886,7 +893,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
$(a.memory[:shortterm]["Plan 1:"])
|
||||
</My plan>
|
||||
<What I know about the user>
|
||||
$(JSON3.write(a.memory[:keyword]))
|
||||
$(readKeywordMemory(a))
|
||||
</What I know about the user>
|
||||
<|assistant|>
|
||||
Thought:
|
||||
@@ -979,6 +986,8 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
if occursin('{', response)
|
||||
try
|
||||
act = GeneralUtils.getStringBetweenCharacters(response, '{', '}', endCharLocation="end")
|
||||
println("")
|
||||
@show act
|
||||
act = JSON3.read(act)
|
||||
check_7 = true
|
||||
catch
|
||||
@@ -986,14 +995,14 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
end
|
||||
end
|
||||
|
||||
# print all check_1 to check_6
|
||||
println("check_1: $check_1, check_2: $check_2, check_3: $check_3, check_4: $check_4,
|
||||
check_5: $check_5, check_6: $check_6, check_7: $check_7")
|
||||
if check_1 && check_2 && check_3 && check_4 && check_5 && check_6 && check_7
|
||||
|
||||
#TODO paraphrase selfaware
|
||||
break
|
||||
end
|
||||
# print all check_1 to check_6
|
||||
println("")
|
||||
println("check_1: $check_1, check_2: $check_2, check_3: $check_3, check_4: $check_4,
|
||||
check_5: $check_5, check_6: $check_6, check_7: $check_7")
|
||||
@show retrying_actor = response
|
||||
end
|
||||
|
||||
@@ -1016,25 +1025,19 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
chunkedtext = chunktext(response, headers)
|
||||
println("")
|
||||
@show chunkedtext
|
||||
|
||||
|
||||
|
||||
toolinput = chunkedtext["Actinput $latestTask:"]
|
||||
|
||||
|
||||
# because tools has JSON input but sometime LLM output is not JSON, we need to check.
|
||||
if occursin("{", toolinput) #WORKING
|
||||
if occursin("{", toolinput)
|
||||
act = GeneralUtils.getStringBetweenCharacters(response, '{', '}', endCharLocation="end")
|
||||
println("")
|
||||
@show act
|
||||
act = GeneralUtils.JSON3read_stringKey(act) #copy(JSON3.read(act))
|
||||
chunkedtext["Actinput $latestTask:"] = JSON3.write(act[toolname])
|
||||
toolinput = act[toolname]
|
||||
act = copy(JSON3.read(act))
|
||||
chunkedtext["Actinput $latestTask:"] = JSON3.write(act[Symbol(toolname)])
|
||||
a.memory[:c] = chunkedtext
|
||||
toolinput = act[Symbol(toolname)]
|
||||
end
|
||||
|
||||
|
||||
chunkedtext["Act $latestTask:"] = toolname
|
||||
|
||||
|
||||
|
||||
return (toolname=toolname, toolinput=toolinput, chunkedtext=chunkedtext, selfaware=selfaware)
|
||||
end
|
||||
@@ -1973,13 +1976,13 @@ function readKeywordMemory(a; keywordmemory::Union{AbstractDict, Nothing}=nothin
|
||||
"""
|
||||
<s>
|
||||
<|system|>
|
||||
<About yourself>
|
||||
Your name is $(a.agentName)
|
||||
$(a.roles[a.role])
|
||||
</About yourself>
|
||||
<Your job>
|
||||
Readout all the key and value pairs in memory, one by one. Do not say anything else.
|
||||
</Your job>
|
||||
<About yourself>
|
||||
Your name is $(a.agentName)
|
||||
$(a.roles[a.role])
|
||||
</About yourself>
|
||||
<Your job>
|
||||
Readout all the key and its value pairs in memory, one by one. Do not say anything else.
|
||||
</Your job>
|
||||
</|system|>
|
||||
<Example 1>
|
||||
<Memory>
|
||||
|
||||
@@ -87,8 +87,13 @@ end
|
||||
```
|
||||
"""
|
||||
function winestock(a::agentReflex, input::NamedTuple)
|
||||
query = JSON3.write(input[:toolinput])
|
||||
println("")
|
||||
@show input
|
||||
query = JSON3.write(input)
|
||||
|
||||
println("")
|
||||
@show query
|
||||
|
||||
prompt =
|
||||
"""
|
||||
<|system|>
|
||||
|
||||
Reference in New Issue
Block a user