This commit is contained in:
2023-12-04 10:49:58 +00:00
parent 45bd332b6f
commit 479d17589e
3 changed files with 54 additions and 35 deletions

View File

@@ -3,7 +3,7 @@ module interface
export agentReact, agentReflex,
addNewMessage, clearMessage, removeLatestMsg, conversation, writeEvaluationGuideline,
grading, analyze, selfReflext, actor_mistral_openorca2
grading, analyze, selfReflext, actor_mistral_openorca2, formulateUserRespond
using JSON3, DataStructures, Dates, UUIDs, HTTP
using CommUtils, GeneralUtils
@@ -246,7 +246,7 @@ function chat_mistral_openorca(a::agentReflex, usermsg::String)
return prompt
end
#WORKING mark only attemp, step
function planner_mistral_openorca(a::agentReflex)
"""
general prompt format:
@@ -299,7 +299,7 @@ function planner_mistral_openorca(a::agentReflex)
- occasion
- user's personal taste of wine
- wine price range
- temperature at the serving location
- ambient temperature at the serving location
- wines we have in stock
You job is to provide a personalized recommendation of up to two wines based on the user's info above, and you describe the benefits of each wine in detail.
"""
@@ -380,17 +380,7 @@ function actor_mistral_openorca(a::agentReflex)
prompt = replace(prompt, "{thinkingFormat}" => a.thinkingFormat[:actor])
prompt = replace(prompt, "{step}" => a.step)
s = ""
for (k, v) in a.memory[:shortterm]
if k ["user:", "Plan 1:"]
s1 = "$k $v"
s *= s1
if s[end] != "\n"
s *= "\n"
end
end
end
s = shortMemoryToString(a.memory[:shortterm], ["user:", "Plan 1:"])
prompt = replace(prompt, "{shorttermMemory}" => s)
toolnames = ""
@@ -419,6 +409,8 @@ function actor_mistral_openorca(a::agentReflex)
return prompt
end
"""
Chat with llm.
@@ -685,16 +677,16 @@ function work(a::agentReflex, usermsg::String)
a.newplan = false
end
# enter actor loop
actorstate, msgToUser = actor(a)
if actorstate == "chatbox"
respond = msgToUser
break
elseif actorstate == "all steps done" #WORKING add canceled during plan
elseif actorstate == "all steps done" || actorstate == "formulateUserRespond"
println("all steps done")
respond = formulateUserRespond(a)
error("10")
a.memory[:shortterm]["Respond $mark_plan:"] = respond
a.memory[:log]["Respond $mark:"] = respond
@@ -710,7 +702,7 @@ function work(a::agentReflex, usermsg::String)
a.memory[:log] = OrderedDict{String, Any}()
break
else # self evaluate and reflect then try again
analysis = analyze(a, a.memory[:shortterm])
analysis = analyze(a)
@show analysis
error(12)
lessonwithcontext = selfReflext(a, analysis)
@@ -830,6 +822,9 @@ function actor(a::agentReflex)
msgToUser = respond
actorState = toolname
break
elseif toolname == "formulateUserRespond"
actorState = "formulateUserRespond"
break
else # function call
f = a.tools[Symbol(toolname)][:func]
toolresult = f(a, toolinput)
@@ -948,7 +943,10 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString}
{Evaluation} Score {}/10.
<|im_end|>
"""
println("prompt 11 ", prompt)
println("")
prompt_grading = prompt
@show prompt_grading
respond = sendReceivePrompt(a, prompt)
println("grading respond 11 = $respond")
_score = split(respond[end-5:end], "/")[1]
@@ -985,8 +983,7 @@ julia> report = analyze(agent, shorttermMemory)
```
"""
function analyze(a)
shorttermMemory = shortMemoryToString(a.memory[:shortterm], ["user:"])
prompt =
"""
<|im_start|>system
@@ -1092,12 +1089,7 @@ julia> report = formulateRespond(agent, shorttermMemory)
function formulateUserRespond(a)
stimulus = a.memory[:shortterm]["user:"]
work = ""
for (k, v) in a.memory[:shortterm]
if k ["user:",]
work *= "$k, $v\n"
end
end
work = shortMemoryToString(a.memory[:shortterm], ["user:"])
prompt =
"""