Skip to content

Commit

Permalink
Clearer prompting
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotsayes committed Jul 24, 2024
1 parent c0afbc6 commit 0fc9e67
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions ai-demo/3_prompt.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
local system = [[
<|system|>
Only tell jokes about cats
<|end|>
function CreatePrompt(systemPrompt, userContent)
return [[<|system|>
]] .. systemPrompt .. [[<|end|>
<|user|>
]]

local finish = [[<|end|>
]] .. userContent .. [[<|end|>
<|assistant|>
]]
end

local userContent = "Tell me a joke"
local userContent = "cats"

local prompt = system .. userContent .. finish
local prompt = CreatePrompt(
"Tell a short joke on the given topic",
userContent
);

OUTPUTS = OUTPUTS or {}
JOKE_HISTORY = JOKE_HISTORY or {}

-- Full inference arguments:
Llama.run(
prompt, -- Your prompt
20, -- Number of tokens to generate
30, -- Number of tokens to generate
function(generated_text) -- Optional: A function to handle the response
print(generated_text)
table.insert(OUTPUTS, generated_text)
-- Read up until the first newline character
local joke = generated_text:match("(.+)\n")
if joke == nil then
return print("Could not find joke in: " .. generated_text)
end
print("Joke: " .. joke)
table.insert(JOKE_HISTORY, joke)
end
)

0 comments on commit 0fc9e67

Please sign in to comment.