update
This commit is contained in:
@@ -291,20 +291,20 @@ julia> result = checkinventory(agent, input)
|
||||
function checkinventory(a::T1, input::T2
|
||||
) where {T1<:agent, T2<:AbstractString}
|
||||
|
||||
println("\n~~~ checkinventory order: $input ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
println("\ncheckinventory order: $input ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
wineattributes_1 = extractWineAttributes_1(a, input)
|
||||
wineattributes_2 = extractWineAttributes_2(a, input)
|
||||
|
||||
_inventoryquery = "retailer name: $(a.retailername), $wineattributes_1, $wineattributes_2"
|
||||
inventoryquery = "Retrieves winery, wine_name, vintage, region, country, wine_type, grape, serving_temperature, sweetness, intensity, tannin, acidity, tasting_notes, price and currency of wines that match the following criteria - {$_inventoryquery}"
|
||||
println("~~~ checkinventory input: $inventoryquery ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
println("\ncheckinventory input: $inventoryquery ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
# add suppport for similarSQLVectorDB
|
||||
textresult, rawresponse = SQLLLM.query(inventoryquery, a.func[:executeSQL],
|
||||
a.func[:text2textInstructLLM],
|
||||
insertSQLVectorDB=a.func[:insertSQLVectorDB],
|
||||
similarSQLVectorDB=a.func[:similarSQLVectorDB])
|
||||
|
||||
println("\n~~~ checkinventory result ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
println("\ncheckinventory result ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
println(textresult)
|
||||
|
||||
return (result=textresult, rawresponse=rawresponse, success=true, errormsg=nothing)
|
||||
@@ -731,7 +731,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
- N/A
|
||||
|
||||
You should then respond to the user with:
|
||||
1) Paraphrase: Paraphrased text
|
||||
Paraphrase: Paraphrased text
|
||||
|
||||
You should only respond in format as described below:
|
||||
Paraphrase: ...
|
||||
@@ -739,6 +739,9 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
Let's begin!
|
||||
"""
|
||||
|
||||
header = ["Paraphrase:"]
|
||||
dictkey = ["paraphrase"]
|
||||
|
||||
errornote = ""
|
||||
response = nothing # placeholder for show when error msg show up
|
||||
|
||||
@@ -756,17 +759,14 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
]
|
||||
|
||||
# put in model format
|
||||
prompt = GeneralUtils.formatLLMtext(_prompt; formatname="llama3instruct")
|
||||
prompt *= """
|
||||
<|start_header_id|>assistant<|end_header_id|>
|
||||
"""
|
||||
prompt = GeneralUtils.formatLLMtext(_prompt; formatname="qwen")
|
||||
|
||||
try
|
||||
response = text2textInstructLLM(prompt)
|
||||
# sometime the model response like this "here's how I would respond: ..."
|
||||
if occursin("respond:", response)
|
||||
errornote = "You don't need to intro your response"
|
||||
error("\n~~~ paraphrase() response contain : ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
error("\nparaphrase() response contain : ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
end
|
||||
response = GeneralUtils.remove_french_accents(response)
|
||||
response = replace(response, '*'=>"")
|
||||
@@ -774,8 +774,16 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
response = replace(response, '`' => "")
|
||||
response = GeneralUtils.remove_french_accents(response)
|
||||
|
||||
header = ["Paraphrase:"]
|
||||
dictkey = ["paraphrase"]
|
||||
# check whether response has all header
|
||||
detected_kw = GeneralUtils.detect_keyword(header, response)
|
||||
if sum(values(detected_kw)) < length(header)
|
||||
errornote = "\nYiemAgent paraphrase() response does not have all header"
|
||||
continue
|
||||
elseif sum(values(detected_kw)) > length(header)
|
||||
errornote = "\nnYiemAgent paraphrase() response has duplicated header"
|
||||
continue
|
||||
end
|
||||
|
||||
responsedict = GeneralUtils.textToDict(response, header;
|
||||
dictKey=dictkey, symbolkey=true)
|
||||
|
||||
@@ -793,7 +801,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
end
|
||||
end
|
||||
|
||||
println("\n~~~ paraphrase() ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
println("\nparaphrase() ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
pprintln(Dict(responsedict))
|
||||
|
||||
result = responsedict[:paraphrase]
|
||||
@@ -807,7 +815,7 @@ function paraphrase(text2textInstructLLM::Function, text::String)
|
||||
println("\nAttempt $attempt. Error occurred: $errorMsg\n$st ", Dates.now(), " ", @__FILE__, " ", @__LINE__)
|
||||
end
|
||||
end
|
||||
error("generatechat failed to generate a response")
|
||||
error("paraphrase() failed to generate a response")
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user