Portal returns updated results while the API returns outdated ones

Hassan Kaleem 0 Reputation points
2025-01-06T07:37:01.02+00:00

I have created a GPT4 model in Azure OpenAI Service, and I want to add data source which is Azure AI Search (Cognitive Search Service).
The problem is at the time of deployment i cannot see any data source adding option, it is deployed first and then data source is added in the portal but when we do that .NET api return old data only portal gives us updated data with source. How do i fix this problem?

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,142 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
362 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,504 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel FANG 1,040 Reputation points MVP
    2025-01-06T09:34:48.87+00:00

    hi, you can try to add extra_body section in the GPT4 API call in your client side. see below example

    import os
    from openai import AzureOpenAI  
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider  
      
    endpoint = os.getenv("ENDPOINT_URL", "https://xxxxx.openai.azure.com/")
    deployment = os.getenv("DEPLOYMENT_NAME", "xxxx")
      
    # Initialize Azure OpenAI client with Entra ID authentication  
    cognitiveServicesResource = os.getenv('AZURE_COGNITIVE_SERVICES_RESOURCE', 'YOUR_COGNITIVE_SERVICES_RESOURCE')  
    token_provider = get_bearer_token_provider(  
        DefaultAzureCredential(),  
        f'{cognitiveServicesResource}.default'  
    )  
            
    client = AzureOpenAI(  
        azure_endpoint=endpoint,  
        azure_ad_token_provider=token_provider,  
        api_version='2024-05-01-preview',  
    )  
           
    completion = client.chat.completions.create(  
        model=deployment,  
        messages=[
        {
            "role": "system",
            "content": "You are an AI assistant that helps people find information."
        },
        {
            "role": "user",
            "content": "hi"
        }
    ],  
        past_messages=10,
        max_tokens=800,  
        temperature=0.7,  
        top_p=0.95,  
        frequency_penalty=0,  
        presence_penalty=0,  
        stop=None,  
        extra_body={  
            "data_sources": [  
                {  
                    "type": "azure_search",  
                    "parameters": {  
                        "endpoint": os.environ["AZURE_AI_SEARCH_ENDPOINT"],  
                        "index_name": os.environ["AZURE_AI_SEARCH_INDEX"],  
                        "authentication": {  
                            "type": "system_assigned_managed_identity"  
                        }  
                    }  
                }  
            ]  
        }  
    )
    print(completion.model_dump_json(indent=2))  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.