lua-openai
lua-openai copied to clipboard
allow user-defined environment variable OPENAI_API_BASE_URL
OpenAI API does not necessarily have to point to https://api.openai.com/v1/.
user may wish to use something like http://ollama.local:11434/v1/
user-defined environment variable OPENAI_API_BASE_URL should override hard-coded base api url
That would be wonderfull. I also want to use it with my local llm setup (ollama) whicht has an openai compatible endpoint
This is already possible by adding
client.api_base = "http://your_llama.cpp.local/v1"
after client initialization, took me a minute to figure that out as well (actually had the environment var thing implemented and then thought wait ... ;) I made #15 to document this (and make luacheck happy).
For reference this would be how to do it with an environment var, i personally like it better modifying the client table in my script though to be honest
--- a/openai/init.lua
+++ b/openai/init.lua
@@ -225,11 +225,11 @@ local OpenAI
do
local _class_0
local _base_0 = {
- api_base = "https://api.openai.com/v1",
+ api_base = os.getenv("OPENAI_API_BASE_URL") or "https://api.openai.com/v1",
new_chat_session = function(self, ...)
return ChatSession(self, ...)
end,