ianarawjo / ianarawjo/ChainForge
Custom Azure Provider
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 256
- Avg merge
- 4h 40m
- Merged PRs (30d)
- 22
Description
Can you point me to where the Azure Provider code is or can the current version be updated. The MS preferred way is to epically in enterprise organizations is to use it behind an APIM with application regenerations. It's basically just proxying the auth beforehand and then obscuring the "keys" to the load balanced instances in the APIM so that way people don't have full access to the instances.
https://github.com/microsoft/AzureOpenAI-with-APIM
Ex for app registration you get a token and pass it as the bearer token to the APIM for auth instead of a subscription key.
```
import requests
import os
###############################
# Variables you will need
# Load sensitive information from environment variables, such as client id/secret
# Can source as you see fit, but you will need these
# #############################
client_id = "customId"
client_secret = "topSecret"
tenant_id = "123-123-4124-124"
token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token'
###############################
# example function
# #############################
def get_azure_openai_api_token(client_id: str, client_secret: str, token_url: str):
"""
Obtain an access token from Azure AD using app registration client credentials.
Args:
client_id (str): The client ID of the Azure app registration.
client_secret (str): The client secret of the Azure app registration.
token_url (str): The URL to obtain the OAuth2 token from Azure AD.
Returns:
str: The access token if the request is successful, None otherwise.
Raises:
requests.exceptions.RequestException: If there is an issue with the
HTTP request.
"""
token_data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'scope': 'https://cognitiveservices.azure.com/.default'
}
try:
token_r = requests.post(token_url, data=token_data)
token_r.raise_for_status()
return token_r.json().get('access_token')
except requests.exceptions.RequestException as e:
print(f"Error obtaining access token: {e}")
return None
###############################
# Example usage
# #############################
token = get_azure_openai_api_token(client_id, client_secret, token_url)
print(token)
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the Azure OpenAI with APIM example linked in the issue and locating the repository's existing Azure Provider implementation. Determine how app-registration bearer-token authentication and APIM proxying should fit the current provider, then define the configuration and verification needed for the feature to be considered complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, python
- Domain
- authentication, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100