working on getting AI bullshit working

This commit is contained in:
Tangent / Rose / Nebula Rosa 2024-01-13 05:19:28 -07:00
parent 81a3f1066f
commit 29f5c72f46
3 changed files with 77 additions and 33 deletions

View File

@ -1,6 +1,10 @@
# .lua-files
It's like dotfiles, but no, it's just Lua scripts I find useful.
## Most Useful Scripts
- `popen-command-test`: A badly-named WIP script for working with the doplhin-mixtral AI model through WSL using [ollama](https://github.com/jmorganca/ollama).
- `video-dl`: A few premade command lines for using `yt-dlp` to download what I want quicker.
## Installation
1. Put this folder somewhere.
2. Add that somewhere to your path. (On Windows, search for Environment Variables (it's "part of" Control Panel) and use the UI to add them to System variables.)

View File

@ -1,38 +1,37 @@
-- install command: curl https://ollama.ai/install.sh | sh
function os.command(command)
local file = assert(io.popen(command, 'r'))
local output = assert(file:read('*a'))
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?
-- 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
command = "pwsh -Command wsl --exec \"" .. util.escape_quotes(command) .. "\""
if output_return then
command = command .. " > " .. file_name
end
os.execute(command)
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
function string.trim6(s)
return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
local function query_dolphin(prompt)
local command = "ollama run dolphin-mixtral \"" .. util.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("---")
-- local home = os.command("echo %userprofile%")
-- home = string.trim6(home)
-- print(home)
-- local dolphin_cheese = os.command("wsl -- ollama run dolphin-mixtral \"Say only the word 'cheese'.\"")
-- local dolphin_cheese = os.command("wsl")
-- os.execute("C:\\Windows\\System32\\wsl.exe")
-- local dolphin_cheese = os.command("echo %path%")
-- local dolphin_cheese = os.command("where wsl")
-- print(dolphin_cheese)
-- print(os.command("bash -c \"$PATH\""))
-- os.execute("bash -c \"ollama help\"")
-- runs but doesn't return anything?
-- local dolphin_cheese = os.command("pwsh -Command wsl -- ollama run dolphin-mixtral \"Say only the word 'cheese'.\"")
-- print(dolphin)
-- os.execute("pwsh -Command wsl -- ollama run dolphin-mixtral \"Say only the word 'cheese'.\"")
-- this will output to file in the correct place :D
os.execute("pwsh -Command wsl --exec \"ollama run dolphin-mixtral \\\"Say only the word 'cheese'.\\\"\" > test-output-file.txt")
print("---")
print(query_dolphin("Say only the word 'cheese'."))

41
utility-functions.lua Normal file
View File

@ -0,0 +1,41 @@
math.randomseed(os.time())
-- TODO look for popen command and fall back to outputting to file if its unavailable
function os.command(command)
local file = assert(io.popen(command, 'r'))
local output = assert(file:read('*a'))
file:close()
return output
end
-- trim6 from Lua users wiki (best all-round pure Lua performance)
function string.trim(s)
return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
end
local utility = {}
-- NOTE: This will print errors sometimes. :D
utility.required_program = function(name)
if os.execute("where " .. tostring(name)) ~= 0 then
error(tostring(name) .. " must be installed and in the path")
end
end
-- modified from my fork of lume
utility.uuid = function()
local fn = function(x)
local r = math.random(16) - 1
r = (x == "x") and (r + 1) or (r % 4) + 9
return ("0123456789abcdef"):sub(r, r)
end
return (("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"):gsub("[xy]", fn))
end
utility.escape_quotes = function(input)
input = input:gsub("\\", "\\\\")
input = input:gsub("\"", "\\\"")
return input
end
return utility