diff --git a/README.md b/README.md index 1cc0781..195b282 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,9 @@ Constructor for the OpenAI client. local openai = require("openai") local api_key = "your-api-key" local client = openai.new(api_key) + +--optionally provide an alternate API URL +client.api_base = "http://my_llama_cpp.local/v1" ``` ##### `client:new_chat_session(...)` diff --git a/examples/example2.lua b/examples/example2.lua index 88b5677..41674f7 100644 --- a/examples/example2.lua +++ b/examples/example2.lua @@ -15,13 +15,13 @@ print(chat:send("List your top 5 favorite colors")) print(chat:send("Excluding the colors you just listed, tell me your favorite color")) -- the entire chat history is stored in the messages field -for idx, message in ipairs(chat.messages) do +for _, message in ipairs(chat.messages) do print(message.role, message.content) end -- You can stream the output by providing a callback as the second argument -- the full response concatenated is also returned by the function -local response = chat:send("What's the most boring color?", function(chunk) +local _ = chat:send("What's the most boring color?", function(chunk) io.stdout:write(chunk.content) io.stdout:flush() end) diff --git a/examples/example5.lua b/examples/example5.lua index ff17c47..0e5c4b0 100644 --- a/examples/example5.lua +++ b/examples/example5.lua @@ -34,7 +34,8 @@ local chat = client:new_chat_session({ messages = { { role = "system", - content = "You are a calculator with access to specified set of functions. All computation should be done with the functions" + content = + "You are a calculator with access to specified set of functions. All computation should be done with the functions" } }, functions = { diff --git a/openai/init.lua b/openai/init.lua index e116339..ac7ddf2 100644 --- a/openai/init.lua +++ b/openai/init.lua @@ -229,7 +229,7 @@ do new_chat_session = function(self, ...) return ChatSession(self, ...) end, - create_stream_filter = function(self, chunk_callback) + create_stream_filter = function(_, chunk_callback) assert(types["function"](chunk_callback), "Must provide chunk_callback function when streaming response") local accumulation_buffer = "" return function(...)