svilupp / PromptingTools.jl

Streamline your life using PromptingTools.jl, the Julia package that simplifies interacting with large language models.
https://svilupp.github.io/PromptingTools.jl/dev/
MIT License
113 stars 12 forks source link

OpenAI organization keys #54

Open cpfiffer opened 7 months ago

cpfiffer commented 7 months ago

I have a personal & private account with OpenAI, and I would like to set an organization key when requesting usage from OpenAI. See the docs for more.

Looks like I just need to add a header to the llm_openai.jl code. Here's the curl stuff from OpenAI:

curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Organization: org-Q557wG3tc1TZvSp4D3AWAamJ"

Should this be addressed in this library or upstream in OpenAI.jl? Either way I suspect it's a pretty easy task (I can do it) but would love some input.

svilupp commented 7 months ago

I think this is OpenAI specific, so it would be better to upstream to OpenAI.jl for others.

All API provider kwargs (‘api_kwargs=(; a=1…)’) from ai* functions are passed directly, so it should just work.

svilupp commented 7 months ago

After considering, I think it might be best to adapt the Providers in OpenAI.jl (eg, OpenAIProvider) to have the optional org key and then customize OpenAI.auth_header to add it to your HTTP header if available.

Then on the PT side, I'll probably need to allow the api_key kwarg to be not only a string but also an OpenAI.Provider object.

That's the "easiest" way I can think of, because api_kwargs actually just send parameters directly to the model. They don't tend to change the headers etc.