2024-01-13 12:19:28 +00:00
|
|
|
-- install command: curl https://ollama.ai/install.sh | sh
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
util = require("utility-functions")
|
|
|
|
-- util.required_program("wsl") -- This fails on my system.
|
|
|
|
util.required_program("pwsh") -- Apparently this is and isn't PowerShell. Isn't the future amazing?
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
-- On my system, it is impossible to call wsl directly from Lua. No idea why.
|
|
|
|
local function wsl_command(command, output_return)
|
|
|
|
local file_name = ".tmp." .. util.uuid()
|
|
|
|
local output
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
command = "pwsh -Command wsl --exec \"" .. util.escape_quotes(command) .. "\""
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
if output_return then
|
|
|
|
command = command .. " > " .. file_name
|
|
|
|
end
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
os.execute(command)
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
if output_return then
|
|
|
|
local file = io.open(file_name, "r")
|
|
|
|
local output = file:read("*a")
|
|
|
|
file:close()
|
|
|
|
os.execute("rm " .. file_name) -- TODO replace with version I know works from somewhere else
|
|
|
|
return output
|
|
|
|
end
|
|
|
|
end
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
local function query_dolphin(prompt)
|
|
|
|
local command = "ollama run dolphin-mixtral \"" .. util.escape_quotes(prompt) .. "\""
|
|
|
|
return wsl_command(command, true)
|
|
|
|
-- TODO trim the above
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
-- os.execute("pwsh -Command wsl --exec \"ollama run dolphin-mixtral \\\"Say only the word 'cheese'.\\\"\" > test-output-file.txt")
|
|
|
|
end
|
2024-01-13 11:31:10 +00:00
|
|
|
|
2024-01-13 12:19:28 +00:00
|
|
|
print(query_dolphin("Say only the word 'cheese'."))
|