add prefix suffic

This commit is contained in:
ton
2023-10-10 09:07:34 +07:00
parent ece426cc89
commit a9e2e4b2a6

View File

@@ -78,8 +78,8 @@ function removeLatestMsg(a::agent)
end
end
function generatePrompt(a::agent;
userToken::String=" [/INST]", assistantToken=" [INST]",
function generatePrompt_tokenSuffix(a::agent;
userToken::String="[/INST]", assistantToken="[INST]",
systemToken="[INST]<<SYS>> content <</SYS>>")
prompt = nothing
for msg in a.messages
@@ -100,6 +100,28 @@ function generatePrompt(a::agent;
return prompt
end
function generatePrompt_tokenPrefix(a::agent;
userToken::String=" [/INST]", assistantToken=" [INST]",
systemToken="[INST]<<SYS>> content <</SYS>>")
prompt = nothing
for msg in a.messages
role = msg[:role]
content = msg[:content]
if role == "system"
prompt = replace(systemToken, "content" => content)
elseif role == "user"
prompt *= userToken * content * " "
elseif role == "assistant"
prompt *= assistantToken * content * " "
else
error("undefied condition role = $role")
end
end
return prompt
end
@@ -154,7 +176,6 @@ end
end # module