skip to Main Content

we are creating a chatbot using gpt-35-turbo and configured cognitive search using own data stored inside storage blob. The chat completion provides result from the stored content however it also provides search results out the scope of stored content. Not sure if it is using outside content outside my data scope.
How I can Limit the search result only to return response from native data rather outside the scope.

How I can Limit the search result only to return response from native data rather outside the scope in azure open ai

2

Answers


  1. We would recommend using the latest models, Its provided as a sample here: Use your own data with Azure OpenAI Service – Azure OpenAI | Microsoft Learn

    We also have a example where you use Az Cog Search to index the data, then use RAG pattern to use Open AI completion using the matches docs from Az Cog Search.

    RAG and generative AI – Azure Cognitive Search | Microsoft Learn

    Login or Signup to reply.
  2. one thing you can do is to maybe integrate your search solution with your gpt engine.
    For instance lets say I have created a search solution for analysing papers of an engineering entrance exam and I want my engine to return all the important chapters asked in the specific question paper. So a beneficial solution to this problem would be to use your indexer to retrieve all the keywords from the specific pdf document imported into your search solution from a storage container and then pass those keywords into the chat engine prompting it to list out the important engineering chapters based on those keywords.

    Attaching a python code as well to give you a detailed idea of my approach with your problem.

    #importing namespaces
    import os
    import openai
    import json
    from dotenv import load_dotenv
    from azure.core.credentials import AzureKeyCredential
    from azure.search.documents import SearchClient
    
    #setting important configurations
    load_dotenv()
    index_name="azureblob-index"
    endpoint = os.getenv('search_endpoint')
    key = os.getenv('search_key')
    openai.api_type = "azure"
    openai.api_base = os.getenv('oai_base')
    openai.api_version = "2023-09-15-preview"
    openai.api_key = os.getenv('oai_key')
    
    #setting important variables
    max=0
    lst=[]
    
    sum=" "
    
    #create an azure search client
    credential = AzureKeyCredential(key)
    client = SearchClient(endpoint=endpoint, index_name=index_name, credential=credential)
    
    results = client.search(search_text="jee advanced 2023")
    
    for result in results: 
        if result['@search.score']>max: #listing down only the keyphrases with the most confident search score
            max=result['@search.score']
            lst=result['keyphrases']
    
    
    
    for keyphrases in lst: #parsing keyphrases from list data type to string data type so as to pass it as a query in the ChatCompletions API
        sum = sum + keyphrases + " "
        
    prompt = "You are an AI assistant. You are given a set of keyphrases extracted from the pdf file of an engineering entrance examination's question paper. By making a note of all these keyphrases, list down all the important engineering topics such as fuild dynamics, thermodynamics etc. "
    
    messages = [
        {"role":"system", "content": prompt},
        {"role":"user", "content":sum}
    ]
    
    chat_response = openai.ChatCompletion.create(
        messages = messages,
        temperature = 0.7,
        engine = "newTestingModel"
    )
    
    #printing the final response from the ChatCompletions API 
    print(chat_response["choices"][0]["message"]["content"])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search