-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
46 lines (36 loc) · 967 Bytes
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local config = require("src.config")
local AI = require("src.ai")
local Chat = require("src.chat")
local api_keys = config.api_keys
-- local api_key = api_keys.anthropic_api_key
-- local endpoint = "https://api.anthropic.com/v1/messages"
-- local model = "claude-3-5-haiku-20241022"
-- local settings = {
-- stream = true,
-- }
local api_key = api_keys.openai_api_key
local endpoint = "https://api.openai.com/v1/chat/completions"
local model = "gpt-4o-mini"
local settings = {
stream = true,
}
local system_prompt = "Respond extremely briefly."
local ai = AI.new(api_key, endpoint)
local chat = Chat.new(ai, model, system_prompt, settings)
local function main()
while true do
local user_prompt = io.read()
if user_prompt == ":q" then break end
print()
local reply = chat:say(user_prompt) -- API call
if not chat.settings.stream then
print(reply)
else
print()
end
print()
-- break
end
print(chat:get_cost() .. " usd")
end
main()