By code, how to include AI Search results based on files data for citations using CompletionClient complete call ?

Matt B 0 Reputation points
2025-01-31T20:31:15.5166667+00:00

Hi,

Starting from the basic example provided in Azure AI SDK (https://learn.microsoft.com/en-us/azure/ai-studio/quickstarts/get-started-code?tabs=windows) based on the OpenAI gpt model I trained using files as datasources in AI Foundry, I wanted to do something similar to the Playground Chat application.

So in the complete() call I added: model_extras to:

    return chat.complete(
        model="gpt-4o-mini",
        messages=system_message + messages,
        temperature=1,
        frequency_penalty=0.5,
        presence_penalty=0.5,
        model_extras=model_extras,
    )

with models_extras defining my index in AI Search created by AI Foundry:

{
    "data_sources": [
        {
            "type": "azure_search",
            "parameters": {
                "top_n_documents": 5,
                "strictness": 3,
                "in_scope": true,
                "index_name": "my_index",
                "semantic_configuration": "azureml-default",
                "query_type": "vector_simple_hybrid",
                "endpoint": "https://myaisearch.search.windows.net",
                "authentication": {
                    "type": "api_key",
                    "key": "sonmekey"
                },
                "embedding_dependency": {
                    "type": "deployment_name",
                    "deployment_name": "text-embedding-ada-000"
                },
                "fields_mapping": {
                    "content_fields": [
                        "content"
                    ],
                    "title_field": "title",
                    "url_field": "url",
                    "filepath_field": "filepath",
                    "vector_fields": [
                        "contentVector"
                    ]
                }
            }
        }
    ]
}

but the complete calls fails with:

azure.core.exceptions.ResourceNotFoundError: Operation returned an invalid status 'Not Found'
Content: <html><title>404: Not Found</title><body>404: Not Found</body></html>

The webapp example tool seems to use the REST API directly and an extra_body field. Is model_extra different from extra_body ?

Or better, is there a python example on our to retrieve the AI Search results as citations using the complete() call ?

Thanks !

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,167 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,597 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,079 questions
0 comments No comments
{count} votes

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.