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:
- Fetch data from an API.
- Use that data in a prompt for natural language to SQL conversion.
- Apply cognitive search on the fetched data.
- 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:
- Create a flow to connect to the API using an HTTP action.
- Parse the response JSON using "Parse JSON."
- 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:
- 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.
- 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:
- https://learn.microsoft.com/en-us/rest/api/searchservice/
- https://learn.microsoft.com/en-us/azure/search/search-get-started-rest
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.