Untitled
unknown
plain_text
2 years ago
3.8 kB
13
Indexable
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import singlestoredb as s2
import os
import streamlit as st
page_bg_img = '''
<style>
[data-testid="stAppViewContainer"] {
background-image: url("https://erp.today/wp-content/uploads/2022/12/Artificial_Intelligence.jpg);
background-size: cover;
}
[data-testid="stHeader"]{
background: lightblue;
}
</style>
'''
st.markdown(page_bg_img, unsafe_allow_html=True)
st.title('Service by Celebal Technologies')
#-------------------------------------------------------------------------------------------------------------#
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_BASE"] = "https://openaitut.openai.azure.com/"
os.environ["OPENAI_API_KEY"] = "fd57c6a45f7949f3ab8632bf26d46e2d"
os.environ["OPENAI_API_VERSION"] = "2023-05-15"
#-------------------------------------------------------------------------------------------------------------#
from langchain.llms import AzureOpenAI
llm=AzureOpenAI(max_tokens=50,temperature=0,model_kwargs={'engine':'firstdeployment'})
#-------------------------------------------------------------------------------------------------------------#
template6= """<|im_start|>
Welcome to the Smart SQL Query Assistant!
I'm here to help you craft SQL queries based on your input context.
**Context**: {input_text}
**Table**: supermarket_dataset_2020_final_dataset
**Columns**:Invoice_ID,Branch,City,Customer_ID,Customer_Type,Gender,Product_Line,Unit_Price,Quantity,Tax,Total,Date,Time,Payment_Method,Customer_Rating
Your task:
- Convert the {input_text} into a single SQL Query.
- Provide only one SQL Query at a time.
- Present the Query in a single line.
<|im_end|>
<|im_start|>
**Examples**:
- To get the total sum of sales:
Example Output: `select sum(Total) from supermarket_dataset_2020_final_dataset`
- To find the sum of sales for each branch:
Example Output: `select branch, sum(Total) from supermarket_dataset_2020_final_dataset group by branch`
- To retrieve the top 5 Customer IDs by total purchase amount:
Example Output: `select Customer ID, sum(Total) from supermarket_dataset_2020_final_dataset group by Customer ID order by sum(Total) desc limit 5`
- To count the number of invoices in each city:
Example Output: `select City, count(Invoice ID) from supermarket_dataset_2020_final_dataset group by City`
- To give me everything from the table:
Example Output: `select * from supermarket_dataset_2020_final_dataset`
- To calculate the average customer rating per product line:
Example Output: `select Product Line, avg(Customer Rating) from supermarket_dataset_2020_final_dataset group by Product Line`
<|im_end|>
<|im_start|>
If you're unsure, simply say "I don't know." Please provide only the SQL Query in the response; no comments, extra details, prompts, or user inputs are necessary. Remember, accurate column names and proper syntax are vital for accurate queries.
<|im_end|>
"""
st.title("CeleQB")
# This modified template ensures that unwanted lines are excluded from the output SQL query.
#-------------------------------------------------------------------------------------------------------------#
prompt6=PromptTemplate(template=template6,input_variables=['input_text'])
pst_chain_gpt6=LLMChain(llm=llm,prompt=prompt6)
#------------------------------------------------------------------------------------------------------------#
input_user=st.text_area(label="")
if input_user:
rf_query=pst_chain_gpt6(input_user)
query= rf_query['text']
query=query[:-10]
query=query.strip()
query=str(query)
query=query.strip()
#st.write(query)
check = st.checkbox("click to see the query", value=False)
if check:
st.write(query)
Editor is loading...