diff --git a/2webm.lua b/2webm.lua index 6cb7f67..1f136ed 100644 --- a/2webm.lua +++ b/2webm.lua @@ -16,7 +16,7 @@ if arg[1] and arg[1]:find("help") then return false end -local error_occurred, utility = pcall(function() return require("utility-functions") end) if not error_occurred then error("This script is installed improperly. Follow instructions at https://github.com/TangentFoxy/.lua-files#installation") end +local error_occurred, utility = pcall(function() return dofile(arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") .. "utility-functions.lua") end) if not error_occurred then error("\n\nThis script is installed improperly. Follow instructions at:\n\thttps://github.com/TangentFoxy/.lua-files#installation\n") end utility.required_program("ffpmeg") local threads = tonumber(arg[1]) or arg[1] or 1 diff --git a/popen-command-test.lua b/popen-command-test.lua index dd81f37..dc61e7c 100644 --- a/popen-command-test.lua +++ b/popen-command-test.lua @@ -1,37 +1,44 @@ --- install command: curl https://ollama.ai/install.sh | sh +#!/usr/bin/env luajit -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? +-- ollama install command: curl https://ollama.ai/install.sh | sh + +local error_occurred, utility = pcall(function() return dofile(arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") .. "utility-functions.lua") end) if not error_occurred then error("\n\nThis script is installed improperly. Follow instructions at:\n\thttps://github.com/TangentFoxy/.lua-files#installation\n") end +-- util.required_program("wsl") -- This fails on my system, necessitating a special function to run commands in WSL. +utility.required_program("pwsh") -- Apparently this is and isn't PowerShell. Isn't the future amazing? -- 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 function wsl_command(command, get_output) + local file_name = utility.tmp_file_name() local output - command = "pwsh -Command wsl --exec \"" .. util.escape_quotes(command) .. "\"" + command = "pwsh -Command wsl --exec \"" .. utility.escape_quotes(command) .. "\"" - if output_return then + if get_output then command = command .. " > " .. file_name end os.execute(command) - if output_return then + if get_output then local file = io.open(file_name, "r") - local output = file:read("*a") + local output = file:read("*all") file:close() os.execute("rm " .. file_name) -- TODO replace with version I know works from somewhere else - return output + return output:trim() end end -local function query_dolphin(prompt) - local command = "ollama run dolphin-mixtral \"" .. util.escape_quotes(prompt) .. "\"" +local function query_model(model, prompt) + local command = "ollama run " .. model .. " \"" .. utility.escape_quotes(prompt) .. "\"" return wsl_command(command, true) - -- TODO trim the above - - -- os.execute("pwsh -Command wsl --exec \"ollama run dolphin-mixtral \\\"Say only the word 'cheese'.\\\"\" > test-output-file.txt") end -print(query_dolphin("Say only the word 'cheese'.")) +local function query_dolphin(prompt) + query_model("dolphin-mixtral", prompt) +end +-- print(query_dolphin("Say only the word 'cheese'.")) + +-- TEMPORARY creation, need to make this system able to manage models automatically or semi-automatically +wsl_command("ollama create curt --file ") + +print(query_model("curt", "How are you?")) diff --git a/test.lua b/test.lua index e393969..dade58e 100644 --- a/test.lua +++ b/test.lua @@ -1,27 +1,11 @@ #!/usr/bin/env luajit -- if utility-functions.lua has an error, this won't show it, so for testing purposes, I don't use it here --- local error_occurred, utility = pcall(function() return require("utility-functions") end) if not error_occurred then error("This script is installed improperly. Follow instructions at https://github.com/TangentFoxy/.lua-files#installation") end --- utility = require("utility-functions") - +-- local error_occurred, utility = pcall(function() return dofile(arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") .. "utility-functions.lua") end) if not error_occurred then error("\n\nThis script is installed improperly. Follow instructions at:\n\thttps://github.com/TangentFoxy/.lua-files#installation\n") end +utility = dofile(arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") .. "utility-functions.lua") print("---") -local error_occurred, utility = pcall(function() return dofile(arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") .. "utility-functions.lua") end) if not error_occurred then error("\n\nThis script is installed improperly. Follow instructions at:\n\thttps://github.com/TangentFoxy/.lua-files#installation\n") end -print("Success?") - --- local error_occurred, utility = pcall( --- function() --- local path = arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") --- return require(path .. "utility-functions") --- end) --- if not error_occurred then --- error("\n\nThis script is installed improperly. Follow instructions at:\n\thttps://github.com/TangentFoxy/.lua-files#installation\n") --- end - --- local path = arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") --- utility = dofile(path .. "utility-functions.lua") --- print(utility) for k,v in pairs(utility) do print(k,v) end diff --git a/utility-functions.lua b/utility-functions.lua index cad0429..4e7adbd 100644 --- a/utility-functions.lua +++ b/utility-functions.lua @@ -79,6 +79,9 @@ utility.ls = function(path) else command = "ls -1" end + if path then + command = command .. "\"" .. path .. "\"" + end local tmp_file_name = utility.tmp_file_name() local output = os.capture_safe(command, tmp_file_name)