I meant to ammend the previous commit with this, whoops.

This commit is contained in:
Tangent / Rose / Nebula Rosa 2024-01-13 17:54:25 -07:00
parent 48a3cce7f3
commit 7104919254
4 changed files with 30 additions and 36 deletions

View File

@ -16,7 +16,7 @@ if arg[1] and arg[1]:find("help") then
return false return false
end 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") utility.required_program("ffpmeg")
local threads = tonumber(arg[1]) or arg[1] or 1 local threads = tonumber(arg[1]) or arg[1] or 1

View File

@ -1,37 +1,44 @@
-- install command: curl https://ollama.ai/install.sh | sh #!/usr/bin/env luajit
util = require("utility-functions") -- ollama install command: curl https://ollama.ai/install.sh | sh
-- 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? 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. -- On my system, it is impossible to call wsl directly from Lua. No idea why.
local function wsl_command(command, output_return) local function wsl_command(command, get_output)
local file_name = ".tmp." .. util.uuid() local file_name = utility.tmp_file_name()
local output 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 command = command .. " > " .. file_name
end end
os.execute(command) os.execute(command)
if output_return then if get_output then
local file = io.open(file_name, "r") local file = io.open(file_name, "r")
local output = file:read("*a") local output = file:read("*all")
file:close() file:close()
os.execute("rm " .. file_name) -- TODO replace with version I know works from somewhere else os.execute("rm " .. file_name) -- TODO replace with version I know works from somewhere else
return output return output:trim()
end end
end end
local function query_dolphin(prompt) local function query_model(model, prompt)
local command = "ollama run dolphin-mixtral \"" .. util.escape_quotes(prompt) .. "\"" local command = "ollama run " .. model .. " \"" .. utility.escape_quotes(prompt) .. "\""
return wsl_command(command, true) 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 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?"))

View File

@ -1,27 +1,11 @@
#!/usr/bin/env luajit #!/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 -- 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 -- 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 = require("utility-functions") utility = dofile(arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)") .. "utility-functions.lua")
print("---") 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 for k,v in pairs(utility) do
print(k,v) print(k,v)
end end

View File

@ -79,6 +79,9 @@ utility.ls = function(path)
else else
command = "ls -1" command = "ls -1"
end end
if path then
command = command .. "\"" .. path .. "\""
end
local tmp_file_name = utility.tmp_file_name() local tmp_file_name = utility.tmp_file_name()
local output = os.capture_safe(command, tmp_file_name) local output = os.capture_safe(command, tmp_file_name)