cc-libs/programs/ai-helloworld.lua

47 lines
960 B
Lua

local _VERSION = '0.1.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 --version');
print(' ai-helloworld --help');
print();
print('settings required:');
print(' opencc.proxy_url');
print(' opencc.proxy_token');
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 ~= nil and command ~= '' then
printUsage();
return;
end
local ok, result = ai.askHello();
if not ok then
print(result);
return;
end
print(result.reply);