Comments (2)
I managed to solve this issue by adding a new method called get_token in the "evaluate" function that retreive a token that allows the access to the chat, with login enabled.
To use this new method you need:
- tenant_id: str,
- client_id: str,
- client_secret: str,
For client_id and client_secret check
https://learn.microsoft.com/en-us/answers/questions/834401/hi-i-want-my-client-id-and-client-secret-key
The client_secret key is visible only when it is created therefore it is likely that you need to add a new one, check
https://techcommunity.microsoft.com/t5/microsoft-defender-for-identity/app-secret-application-secret-azure-ad-azure-ad-app-secrets/m-p/3775325
The get_token method to retrieve the token
def get_token(tenant_id:str, client_id: str, client_secret: str):
token_url = "https://login.microsoftonline.com/{tenant_id}/oauth2/token"
data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'resource': "api://" + client_id
}
# Make a POST request to the token endpoint
response = requests.post(token_url.format(tenant_id=tenant_id), data=data)
# Check if the request was successful
if response.status_code == 200:
# Extract the access token from the response
access_token = response.json()['access_token']
return access_token
else:
return -1
In the run_evaluation function before calling the send_question_to_target you have to add
...
logger.info("Getting token...")
try:
token = get_token(tenant_id, client_id, client_secret)
except Exception as e:
logger.error("Failed to get token: \n%s", e)
return False
...
...
Then you have to modify the two calls to the function send_question_to_target adding the retrieved token
target_data = send_question_to_target(
"What information is in your knowledge base?", "So much", target_url, token, target_parameters, raise_error=True
)
Finally you have to modify the send_question_to_target as follows:
def send_question_to_target(question: str, truth: str, target_url: str, access_token: str, parameters: dict = {}, raise_error=False):
headers = {"Content-Type": "application/json",
"Authorization": "Bearer " + access_token # Include the access token in the Authorization header
}
...
...
Here below you may find a script that test the retrieval of the token.
You have just to modify the tenand_id, client_id, client_secret.
import requests
# Your Azure AD tenant ID
tenant_id = your_tenant_id
# Your Azure AD application (client) ID
client_id = your_client_id
# Your Azure AD application (client) secret
client_secret = your_client_secret
# Azure AD OAuth 2.0 token endpoint
token_url = "https://login.microsoftonline.com/{tenant_id}/oauth2/token"
# Request body parameters
data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'resource': "api://" + client_id
}
# Make a POST request to the token endpoint
response = requests.post(token_url.format(tenant_id=tenant_id), data=data)
# Check if the request was successful
if response.status_code == 200:
# Extract the access token from the response
access_token = response.json()['access_token']
print("Access Token:", access_token)
else:
print("Failed to retrieve access token. Status code:", response.status_code)
from azure-search-openai-demo.
Related Issues (20)
- Understand file structure in blob storage HOT 4
- Answer won't search global content blob HOT 1
- Connect user with their Onedrive/Sharepoint data HOT 3
- openai.error.AuthenticationError: Principal does not have access to API/Operation HOT 1
- How to make user uploaded files globally available to all the users using ChatApp. HOT 2
- suggestions for ways to give access to resources in main storage HOT 1
- Setting up optional login HOT 3
- Should `AAD` be changed to `Azure Entra ID`? HOT 2
- Deleting The "ASK" tab HOT 1
- Search resource fails in swedencentral HOT 1
- Advanced RAG
- Chat answer layout differs in oai from deployment HOT 1
- I am not able to change the "Retrieval mode" in the UX
- Request for company Azure account (needed to get Azure OpenAI account) fails.
- Supporting files with apostrophy / punctuation mark in the file name HOT 3
- local running error: Incomplete environment configuration for EnvironmentCredential. HOT 3
- Error in login_and_acl.md when using ./script/manage.acl should be --document, not --url HOT 4
- adlsgen2setup fails three bugs - 1. cannot set AZURE_ADLS_GEN2_STORAGE_ACCOUNT 2. ./data/* should be ./data in adlsgensetup.sh and 3. Code changes required in adlsgensetup.py HOT 1
- Can we get some examples for AZURE_ADLS_GEN2_FILESYSTEM_PATH and how to use it in documentation please HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-search-openai-demo.