update
This commit is contained in:
183
src/interface.jl
183
src/interface.jl
@@ -4,7 +4,7 @@ module interface
|
||||
export agentReact, agentReflex,
|
||||
addNewMessage, clearMessage, removeLatestMsg, conversation, directconversation,
|
||||
writeEvaluationGuideline, grading, analyze, selfReflext,
|
||||
formulateUserresponse, extractinfo, updateEnvState, chat_mistral_openorca,
|
||||
formulateUserResponse, extractinfo, updateEnvState, chat_mistral_openorca,
|
||||
recap
|
||||
|
||||
using JSON3, DataStructures, Dates, UUIDs, HTTP, Random
|
||||
@@ -229,7 +229,7 @@ function planner_mistral_openorca(a::agentReflex)
|
||||
<|assistant|>
|
||||
Plan:
|
||||
"""
|
||||
# WORKING provide ecmaple that show good planning
|
||||
# provide ecmaple that show good planning
|
||||
plan = sendReceivePrompt(a, assistant_plan_prompt, max_tokens=1024, temperature=0.1,
|
||||
timeout=180, stopword=["<|user|>", "</"])
|
||||
plan = split(plan, "<|")[1]
|
||||
@@ -290,6 +290,7 @@ function updatePlan(a::agentReflex)
|
||||
|
||||
end
|
||||
|
||||
|
||||
# function selfAwareness(a::agentReflex)
|
||||
# getonlykeys = ["Actinput", "Obs"]
|
||||
# worknoplan = similar(a.memory[:shortterm])
|
||||
@@ -310,33 +311,83 @@ end
|
||||
# aboutYourself =
|
||||
# """
|
||||
# Your name is $(a.agentName)
|
||||
# $(a.roles[a.role])
|
||||
# $(a.roles[a.role])
|
||||
|
||||
# """
|
||||
|
||||
# # 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|>
|
||||
# <About yourself>
|
||||
# $aboutYourself
|
||||
# $(a.roleSpecificInstruction[a.role])
|
||||
# </About yourself>
|
||||
# <Your work>
|
||||
# <Your earlier work>
|
||||
# $work
|
||||
# </your work
|
||||
# </Your earlier work>
|
||||
|
||||
# <Your plan>
|
||||
# $(a.memory[:shortterm]["Plan 1:"])
|
||||
# </Your plan>
|
||||
# <Your job>
|
||||
# Use the following format:
|
||||
# What I know: based on observed results, repeat all the details of what you have been gathered.
|
||||
# Current progress: focus on checking your progress against the plan.
|
||||
# What I am missing: describe in detail what you are missing.
|
||||
# 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
|
||||
# </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
|
||||
# </Example>
|
||||
# </s>
|
||||
# <|assistant|>
|
||||
# What I know:
|
||||
# """
|
||||
# response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
|
||||
# stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
|
||||
# response = split(response, "<|")[1]
|
||||
# response = split(response, "</")[1]
|
||||
# @show response
|
||||
|
||||
# return response
|
||||
@@ -366,40 +417,6 @@ function selfAwareness(a::agentReflex)
|
||||
|
||||
"""
|
||||
|
||||
# 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|>
|
||||
@@ -416,17 +433,15 @@ function selfAwareness(a::agentReflex)
|
||||
</Your plan>
|
||||
<Your job>
|
||||
Use the following format strictly:
|
||||
What I know: based on observed results, repeat all the information you got
|
||||
Info match: 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
|
||||
What I know: based on observed results, breakdown then repeat all information you got one by one
|
||||
Info matching: using JSON format, explicitly state what information matches which variable name in my plan
|
||||
What am I missing: based on Info matching, describe in detail what you are still missing based on the plan
|
||||
P.S. do not mention any toolnames
|
||||
</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"}
|
||||
Info matching: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
|
||||
What am I missing:
|
||||
- The user's preferred color
|
||||
- The user's financing method
|
||||
@@ -435,11 +450,58 @@ function selfAwareness(a::agentReflex)
|
||||
<|assistant|>
|
||||
What I know:
|
||||
"""
|
||||
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
|
||||
|
||||
@show selfaware_1 = response
|
||||
|
||||
#WORKING
|
||||
headerToDetect = ["What I know:", "Info matching:", "What am I missing:",]
|
||||
headers = detectCharacters(response, headerToDetect)
|
||||
chunkedtext = chunktext(response, headers)
|
||||
println("")
|
||||
_infomatch = chunkedtext["Info matching:"]
|
||||
_infomatch = GeneralUtils.getStringBetweenCharacters(_infomatch, '{', '}', endCharLocation="next")
|
||||
infomatch = copy(JSON3.read(_infomatch))
|
||||
keywordMemoryUpdate!(a.memory[:keyword], infomatch)
|
||||
|
||||
prompt =
|
||||
"""
|
||||
<|system|>
|
||||
<About yourself>
|
||||
$aboutYourself
|
||||
$(a.roleSpecificInstruction[a.role])
|
||||
</About yourself>
|
||||
|
||||
<Your plan>
|
||||
$(a.memory[:shortterm]["Plan 1:"])
|
||||
</Your plan>
|
||||
<Your job>
|
||||
Use the following format strictly:
|
||||
What am I missing: based on Info matching, describe in detail what you are still missing according to the plan
|
||||
P.S. do not mention any toolnames
|
||||
</Your job>
|
||||
<Example>
|
||||
Info matching: {"car type": "SUV", "engine type": "electric motor", "color": null, "financing": null}
|
||||
What am I missing:
|
||||
- The user's preferred color
|
||||
- The user's financing method
|
||||
</Example>
|
||||
</s>
|
||||
<|assistant|>
|
||||
Info matching: $(JSON3.write(a.memory[:keyword]))
|
||||
What am I missing:
|
||||
"""
|
||||
response = "What am I missing:" * sendReceivePrompt(a, prompt, max_tokens=1024, temperature=0.4, timeout=180,
|
||||
stopword=["/n/n", "END", "End", "Obs", "<|", "</"])
|
||||
response = split(response, "<|")[1]
|
||||
response = split(response, "</")[1]
|
||||
|
||||
response = "Info matching:" * chunkedtext["Info matching:"] * response
|
||||
@show selfaware_2 = response
|
||||
|
||||
|
||||
return response
|
||||
end
|
||||
@@ -506,13 +568,9 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
thought = "Thought: you should always think about what to do according to the plan (pay attention to correct numeral calculation and commonsense and do one thing at a time.)"
|
||||
if selfaware !== nothing
|
||||
|
||||
# aware = "Self-awareness: based on the recap, assess your progress against the plan then identify areas where you need to address."
|
||||
# aware = "Self-awareness: based on the recap and the plan, state your current understanding of the matter in details then identify areas where you need to address."
|
||||
# aware = "Self-awareness: Based on Obs, review your progress against the plan. Then, describe in detail the results you have achieved so far. Finally, describe in detail what you are missing. (focus on your actions and their results)"
|
||||
# aware = "Self-awareness: Based on action's input and observed results, check your progress against the plan. Then, repeat all the details of what you have been gathered. Finally, describe in detail what you are missing."
|
||||
thought =
|
||||
"Self-awareness: $selfaware
|
||||
Thought: based on self-awareness, you should always think about what to do next by prioritizing what you missed first. (P.S. 1) let's think a single step. 2) pay attention to correct numeral calculation and commonsense.)
|
||||
Thought: To think about your next step, reflect on your self-awareness and prioritize what you need to improve first then consult your plan. (P.S. 1) let's think a single step. 2) pay attention to correct numeral calculation and commonsense.)
|
||||
"
|
||||
end
|
||||
# your should request the missing information first before making a decision
|
||||
@@ -564,6 +622,7 @@ function actor_mistral_openorca(a::agentReflex, selfaware=nothing)
|
||||
$work
|
||||
"Thought: "
|
||||
"""
|
||||
|
||||
prompt = replace(prompt, "{toolnames}" => toolnames)
|
||||
|
||||
println("")
|
||||
@@ -826,7 +885,7 @@ function work(a::agentReflex)
|
||||
elseif actorstate == "formulateFinalResponse"
|
||||
println("all tasks done")
|
||||
|
||||
response = formulateUserresponse(a)
|
||||
response = formulateUserResponse(a)
|
||||
|
||||
println("")
|
||||
formulatedresponse = response
|
||||
@@ -928,8 +987,6 @@ function actor(a::agentReflex)
|
||||
selfaware = nothing
|
||||
if length(a.memory[:shortterm]) > 2 # must have User:, Plan:, Thought:, Act:, Actinput: already
|
||||
selfaware = selfAwareness(a)
|
||||
println("")
|
||||
@show selfaware
|
||||
end
|
||||
|
||||
actorResult = actor_mistral_openorca(a, selfaware)
|
||||
@@ -1229,10 +1286,10 @@ end
|
||||
"Actinput 2:" => " amd graphics card latest\n",
|
||||
"Obs 2:" => "No info available for your search query.")
|
||||
|
||||
julia> report = formulateUserresponse(agent, shorttermMemory)
|
||||
julia> report = formulateUserResponse(agent, shorttermMemory)
|
||||
```
|
||||
"""
|
||||
function formulateUserresponse(a)
|
||||
function formulateUserResponse(a)
|
||||
conversation = messagesToString_nomark(a.messages, addressAIas="I")
|
||||
work = dictToString(a.memory[:shortterm])
|
||||
|
||||
@@ -1256,7 +1313,7 @@ function formulateUserresponse(a)
|
||||
</your earlier work>
|
||||
|
||||
<your job>
|
||||
Based on your talk with the user and your work, present a response that compares and justifies each option in great detail.
|
||||
Based on your talk with the user and your work, present a response that compares and justifies each option in great detail to the user.
|
||||
</your job>
|
||||
</s>
|
||||
<|assistant|>
|
||||
@@ -1266,7 +1323,7 @@ function formulateUserresponse(a)
|
||||
return response
|
||||
end
|
||||
|
||||
# function formulateUserresponse(a)
|
||||
# function formulateUserResponse(a)
|
||||
# conversation = messagesToString_nomark(a.messages, addressAIas="I")
|
||||
# work = dictToString(a.memory[:shortterm])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user