This commit is contained in:
narawat lamaiin
2024-08-20 23:03:40 +07:00
parent a5dc2c1122
commit 4ac9a7ee12
2 changed files with 52 additions and 18 deletions

View File

@@ -255,7 +255,7 @@ function decisionMaker(a::T)::Dict{Symbol, Any} where {T<:agent}
5) mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No" 5) mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No"
You should only respond in format as described below: You should only respond in format as described below:
thought: Let's think step by step. In order to ... thought: ...
plan: ... plan: ...
action_name: ... action_name: ...
action_input: ... action_input: ...
@@ -1100,7 +1100,7 @@ function think(a::T)::NamedTuple{(:actionname, :result), Tuple{String, String}}
elseif actionname == "PRESENTBOX" elseif actionname == "PRESENTBOX"
x = """ x = """
1) Introduce $actioninput in details for the user to choose." 1) Introduce $actioninput in details for the user to choose."
2) compare each option against the others in details and explain why each one is a suitable match for the user's specific needs. 2) Comprehensively compare each option against the others and explain why each one is a suitable match for the user's specific needs.
""" """
(result=x, errormsg=nothing, success=true) (result=x, errormsg=nothing, success=true)
elseif actionname == "ENDCONVERSATION" elseif actionname == "ENDCONVERSATION"
@@ -1292,6 +1292,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
Your responsibility does not include: Your responsibility does not include:
1) Processing sales orders or engaging in any other sales-related activities. 1) Processing sales orders or engaging in any other sales-related activities.
2) Ordering the wines.
At each round of conversation, you will be given the current situation: At each round of conversation, you will be given the current situation:
Your conversation with the user: ... Your conversation with the user: ...
@@ -1307,7 +1308,7 @@ function generatechat(memory::Dict, chathistory::Vector, text2textInstructLLM::F
You should then respond to the user with: You should then respond to the user with:
1) chat: Given the situation, what would you say to convey your thoughts to the user? 1) chat: Given the situation, what would you say to convey your thoughts to the user?
2) mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No" 2) mentioning_wine: Are you mentioning specific wine name to the user? Can be "Yes" or "No"
3) note: Put everything you want to add here 3) note: Put everything you want to add here. Otherwise, put "NA"
You should only respond in format as described below: You should only respond in format as described below:
chat: ... chat: ...
@@ -1599,9 +1600,9 @@ function generatequestion(a, text2textInstructLLM::Function)::String
You should then respond to the user with: You should then respond to the user with:
1) thought: State your reasoning about the current situation 1) thought: State your reasoning about the current situation
2) Q: Given the situation, "ask yourself" about the situation at least two, but no more than five, questions. 2) Q: Given the situation, "ask yourself" about the situation at least three, but no more than ten, questions.
3) A: Given the situation, "answer to yourself" the best you can 3) A: Given the situation, "answer to yourself" the best you can
4) note: Put everything you want to add here 4) note: Additional info you want to say. Otherwise, "NA"
Here are some examples: Here are some examples:
Q: The user is asking for a cappuccino. Do I have it at my cafe? Q: The user is asking for a cappuccino. Do I have it at my cafe?
@@ -1611,18 +1612,18 @@ function generatequestion(a, text2textInstructLLM::Function)::String
Q: Are they allergic to milk? Q: Are they allergic to milk?
A: Since they mentioned a cappuccino before, I think they are not allergic to milk. A: Since they mentioned a cappuccino before, I think they are not allergic to milk.
Q: Do I search the database yet? Q: Do I search the database yet?
A: I've searched the database and found ... A: Not yet.
Q: Did I introduce the wines to the user yet? Q: Did I introduce the wines to the user yet?
A: Not yet. I will introduce the wines now. A: Not yet. I will introduce the wines now.
You must only respond in format as described below: You must only respond in format as described below:
thought: ... , In order to ..., I should ask myself the following questions. thought: ...
Q_1: ... Q1: ...
A_1: ... A1: ...
Q_2: ... Q2: ...
A_2: ... A2: ...
Q_3: ... Q3: ...
A_3: ... A3: ...
... ...
note: ... note: ...
@@ -1663,15 +1664,15 @@ function generatequestion(a, text2textInstructLLM::Function)::String
try try
response = text2textInstructLLM(prompt) response = text2textInstructLLM(prompt)
q_number = count("Q_", response) q_number = count("Q", response)
if q_number < 1 if q_number < 3
error("too few questions only $q_number questions are generated ", @__FILE__, " ", @__LINE__) error("too few questions only $q_number questions are generated ", @__FILE__, " ", @__LINE__)
end end
# response = string(split(response, "Please")[1]) # LLM usually add comments which is no need. # response = string(split(response, "Please")[1]) # LLM usually add comments which is no need.
responsedict = GeneralUtils.textToDict(response, responsedict = GeneralUtils.textToDict(response,
["thought", "Q_1", "note"], ["thought", "Q1", "note"],
rightmarker=":", symbolkey=true) rightmarker=":", symbolkey=true)
response = "Q_1: " * responsedict[:Q_1] response = "Q1: " * responsedict[:Q1]
println("--> generatequestion ", @__FILE__, " ", @__LINE__) println("--> generatequestion ", @__FILE__, " ", @__LINE__)
pprintln(response) pprintln(response)
return response return response
@@ -1713,7 +1714,7 @@ function generateSituationReport(a, text2textInstructLLM::Function)::Dict
systemmsg = systemmsg =
""" """
You are the assistant being in the given events. You are the assistant being in the given events.
Your task is to writes a summary for each event in an ongoing series. Your task is to writes a summary for each event in an ongoing, interleaving series.
At each round of conversation, you will be given the situation: At each round of conversation, you will be given the situation:
Total events: number of events you need to summarize. Total events: number of events you need to summarize.

View File

@@ -123,7 +123,40 @@ main()
error("test done")
function run_with_timeout(f, args...; timeout=5)
result = Ref{Any}()
task = Threads.@spawn try
result[] = f(args...)
catch e
println("Task interrupted: ", e)
end
Timer(timeout) do _
if !istaskdone(task)
schedule(task, InterruptException())
println("Task did not complete in time. Aborting.")
else
println("Task completed within the timeout.")
end
end
return result[]
end
# Example function that takes arguments and returns a value
function example_function(x, y)
sleep(10) # Simulate a long-running task
return x + y
end
# Example usage
result = run_with_timeout(example_function, 3, 4; timeout=5)
println("Result: ", result)