From 96ccd5c6398e6e46ffeacb12cef5b87bb5199207 Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Fri, 29 Dec 2023 05:37:58 +0000 Subject: [PATCH] update --- src/interface.jl | 61 ++++++++++++++++++++++++++---------------------- src/utils.jl | 5 +++- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/interface.jl b/src/interface.jl index 12aad0a..a0f7f2f 100755 --- a/src/interface.jl +++ b/src/interface.jl @@ -337,15 +337,15 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="") # $conversation # """ - start = "Thought" + start = "Thought:" aware = "" 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 length(a.memory[:shortterm]) > 2 # must have User:, Plan:, Thought:, Act:, Actinput: - start = "Self-awareness" + start = "Self-awareness:" # 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 Obs, 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." + 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 = "Thought: you should always think about what to do according to self-awareness (1. let's think a single step. 2. focus on incomplete task 3. pay attention to correct numeral calculation and commonsense.)" end @@ -380,7 +380,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="") <|assistant|> $work - $start: + $start """ prompt = replace(prompt, "{toolnames}" => toolnames) @@ -393,18 +393,20 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="") tempcounter = 0.2 while true # while Thought or Act is empty, run actor again - # tempcounter += 0.1 + tempcounter += 0.2 @show tempcounter response = sendReceivePrompt(a, prompt, max_tokens=1024, temperature=tempcounter, timeout=180) response = splittext(response, ["Obs", "<|im_end|>"]) latestTask = shortMemLatestTask(a.memory[:shortterm]) +1 - if start == "Thought" - response = "Thought $latestTask: " * response - else - response = "Self-awareness $latestTask: " * response - end + # if start == "Thought:" + # response = "Thought $latestTask: " * response + # else + # response = "Self-awareness $latestTask: " * response + # end + + response = start * response headerToDetect = ["Question:", "Plan:", "Self-awareness:", "Thought:", "Act:", "Actinput:", "Obs:", "...", @@ -415,7 +417,7 @@ function actor_mistral_openorca(a::agentReflex, taskrecap="") response = split(response, "<|")[1] response = split(response, "system - You have access to the following tools: - askbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer. - wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question. + $(a.roles[a.role]) + + askbox: Useful for when you need to ask a customer for more context. Input should be a conversation to customer. + wikisearch: Useful for when you need to search an encyclopedia Input is keywords and not a question. + + + 1. Write an evaluation guideline for wine recommendation in order to be able to evaluate your response. + 2. An example of what the response should be. + + + <|assistant|> - Your work: - $(a.memory[:shortterm]["User:"]) - - Your job are: - 1. Write an evaluation guideline for your work in order to be able to evaluate your response. - 2. An example of what the response should be. - <|im_end|> """ response = sendReceivePrompt(a, prompt) @@ -1016,13 +1019,13 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString} - 1. Evaluate your response using the evaluation guideline and an example response. + 1. Evaluate your response using the evaluation guideline. 2. Give yourself a score out of 9 for your response. - + {"Evaluate": "The response does not directly address user needs. It does not include price into account and other user mentioned factors", "Score": 6} - - <|im_end|> + + """ @@ -1031,8 +1034,10 @@ function grading(a, guideline::T, text::T) where {T<:AbstractString} @show prompt_grading println("") response = sendReceivePrompt(a, prompt) - @show response = JSON3.read(response) - score = response["Score"] + response = split(response, "}")[1] * "}" + @show response + @show jsonresponse = JSON3.read(response) + score = jsonresponse["Score"] return score end diff --git a/src/utils.jl b/src/utils.jl index 90545ce..2ba4ab5 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -817,10 +817,13 @@ function replaceHeaders(text::T, headers, step::Int) where {T<:AbstractString} header = i[1:end-1] # not include ":" if occursin(header, newtext) startind = findfirst(header, newtext)[1] - stopind = findnext(":", newtext, startind+1)[end] #BUG MethodError: no method matching lastindex(::Nothing) + stopind = findnext(":", newtext, startind+1)[end] word = newtext[startind: stopind] newword = "$header $step:" newtext = replace(newtext, word=> newword) + if header == "Thought:" + error(1) + end end end