lua-openai icon indicating copy to clipboard operation
lua-openai copied to clipboard

allow user-defined environment variable OPENAI_API_BASE_URL

Open mike2194 opened this issue 10 months ago • 3 comments

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

mike2194 avatar Feb 01 '25 18:02 mike2194

That would be wonderfull. I also want to use it with my local llm setup (ollama) whicht has an openai compatible endpoint

semidark avatar May 18 '25 15:05 semidark

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).

corarona avatar Aug 03 '25 02:08 corarona

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,

corarona avatar Aug 03 '25 03:08 corarona