Getting data through api for using it in prompt on my application

Jasmeet Singh 0 Reputation points
2025-01-23T10:41:39.2733333+00:00

Hi, I want to use data which I'm getting from Api in my prompt, the data is present at client side and I can access it through Api, now I want to use that data for prompt, I want to fetch info from natural language to SQL, which I've done manually using model in my Jupiter env, I can go with no code approach as well, please tell how can I get data from Api for applying cognitive search on that data.

Thanks

J. Singh

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,282 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 17,016 Reputation points
    2025-01-23T20:39:19.8566667+00:00

    Hello

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to do the followings:

    1. Fetch data from an API.
    2. Use that data in a prompt for natural language to SQL conversion.
    3. Apply cognitive search on the fetched data.
    4. Explore a no-code approach if possible.

    This page can not contain all the steps to practically implement your questions, and also, there are many methods to achieve this. However, you can start by using data fetched from an API for natural language to SQL translation in a prompt, with minimal coding if possible.

    To Fetch Data from API, a no-code/low-code approach such as Microsoft Power Automate or Logic Apps is recommended. In Power Automate:

    1. Create a flow to connect to the API using an HTTP action.
    2. Parse the response JSON using "Parse JSON."
    3. Store the parsed data in a data source like Azure SQL Database or Dataverse for easy querying.

    For a code-based approach, use Python:

    import requests
    url = "https://api.example.com/data"
    headers = {"Authorization": "Bearer YOUR_API_KEY"}
    response = requests.get(url, headers=headers)
    data = response.json()
    # Save data to a database if needed
    

    To use Natural Language to SQL (NL2SQL) manual implementation:

    • Fine-tune an open-source model like OpenAI Codex or Azure OpenAI GPT for NL2SQL tasks. This is snippet example of using OpenAI API for NL2SQL:
          import openai
          openai.api_key = "YOUR_API_KEY"
          prompt = f"Convert this natural language query to SQL: '{natural_language_query}' using this schema: {schema}"
          response = openai.Completion.create(
              engine="text-davinci-003",
              prompt=prompt,
              max_tokens=150
          )
          sql_query = response.choices[0].text.strip()
          print(sql_query)
    
    • For a no-code solution:
      • Use Azure OpenAI Studio to create a custom model deployment for NL2SQL.
      • Integrate the API data with Dataverse or Azure SQL, and connect the custom model using tools like Power Apps or Power Automate.

    For a Cognitive Search as an optional, if you needs additional search functionality on the API data:

    1. Index the data in Azure Cognitive Search using:
    • REST APIs (as described in the original response).
    • No-code integration with Power Automate or Azure Data Factory.
    1. Use the search API to allow for text-based queries on the indexed data.

    The below are the summary of tools for No-Code/Low-Code Approach**

    • API Data Fetching: Power Automate or Azure Logic Apps.
    • NL2SQL Translation: Azure OpenAI Studio or Power Apps.
    • Data Management: Azure SQL Database or Dataverse.
    • Cognitive Search: Azure Cognitive Search integrated with Power Automate.

    Use the links below to read more about no-code guides and steps:

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

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.