66 lines
1.4 KiB
Lua
66 lines
1.4 KiB
Lua
local _VERSION = '0.2.0';
|
|
|
|
local createAiHelloWorld = require('/apis/libaihelloworld');
|
|
|
|
local args = table.pack(...);
|
|
local command = args[1];
|
|
|
|
local function printUsage()
|
|
print('ai-helloworld usage:');
|
|
print();
|
|
print(' ai-helloworld');
|
|
print(' ai-helloworld --new');
|
|
print(' ai-helloworld --sessions');
|
|
print(' ai-helloworld --version');
|
|
print(' ai-helloworld --help');
|
|
print();
|
|
print('settings required:');
|
|
print(' opencc.server_url');
|
|
print();
|
|
print('settings optional:');
|
|
print(' opencc.username (default: opencode)');
|
|
print(' opencc.password (Basic Auth password)');
|
|
print(' opencc.session_id (auto-managed)');
|
|
end
|
|
|
|
if command == '--version' or command == '-version' or command == 'version' then
|
|
print('ai-helloworld v' .. _VERSION);
|
|
return;
|
|
end
|
|
|
|
if command == '--help' or command == '-help' or command == 'help' then
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
local ai = createAiHelloWorld();
|
|
|
|
if command == '--new' then
|
|
ai.clearSession();
|
|
elseif command == '--sessions' then
|
|
local ok, result = ai.listSessions();
|
|
if not ok then
|
|
print(result);
|
|
return;
|
|
end
|
|
if #result == 0 then
|
|
print('no sessions');
|
|
else
|
|
for _, s in ipairs(result) do
|
|
print((s.id or '?') .. ' ' .. (s.title or '(untitled)'));
|
|
end
|
|
end
|
|
return;
|
|
elseif command ~= nil and command ~= '' then
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
local ok, result = ai.askHello();
|
|
if not ok then
|
|
print(result);
|
|
return;
|
|
end
|
|
|
|
print(result.reply);
|