andrewyng / aisuite

Simple, unified interface to multiple Generative AI providers
MIT License
6.84k stars 585 forks source link

Support keyless auth for Azure OpenAI (token provider) #127

Open pamelafox opened 1 hour ago

pamelafox commented 1 hour ago

Many of our Azure developers do not use API keys, they use "keyless auth" which passes in a short-lived OAuth token, which can then be refreshed. The OpenAI package already supports that keyless auth, by accepting a token_provider callback, calling that at the appropriate times, and passing in a Bearer header with the resulting token. Would you consider adding bearer token auth for this wrapper? Or is this wrapper meant for hobbyist scenarios only?

pamelafox commented 1 hour ago

Here's an example of how I would use keyless auth with Azure with the openai package, by the way: https://github.com/pamelafox/python-openai-demos/blob/c7de0ec332cab9340ff1bf327efceebdec2f6364/chat.py#L16

client = openai.AzureOpenAI(
    api_version=os.getenv("AZURE_OPENAI_VERSION"),
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    azure_ad_token_provider=token_provider,
)