Spaces:
Runtime error
Runtime error
Update app.py
Browse files13 unmodified lines141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667689 unmodified lines7879808182838427 unmodified lines1121131141151161171181191201214 unmodified lines1261271281291301311321331341351361371381391401411421432 unmodified lines14614714814915015115213 unmodified lines# you need to set your OpenAI API key as environment variableopenai.api_key = st.secrets["API_KEY"]MOVIES_EXAMPLE_DOC = """{_id: ObjectId("573a1390f29313caabcd4135"),genres: [ 'Short' ],runtime: 1,cast: [ 'Charles Kayser', 'John Ott' ],num_mflix_comments: 0,title: 'Blacksmith Scene',countries: [ 'USA' ],released: ISODate("1893-05-09T00:00:00.000Z"),directors: [ 'William K.L. Dickson' ],rated: 'UNRATED',awards: { wins: 1, nominations: 0, text: '1 win.' },lastupdated: '2015-08-26 00:03:50.133000000',year: 1893,imdb: { rating: 6.2, votes: 1189, id: 5 },type: 'movie',tomatoes: {viewer: { rating: 3, numReviews: 184, meter: 32 },lastUpdated: ISODate("2015-06-28T18:34:09.000Z")}}"""MOVIES_EXAMPLE_QUESTIONS = [("How many fantasy or horror movies from the USA with an imdb rating ""greater than 6.0 are there in this dataset?"),("Which movies were released on a Monday and have a higher tomato rating ""than IMDB rating? Keep in mind that IMDB goes from 1-10 and tomatoes ""only from 1-5, so you need to normalise the ratings to do a fair comparison."),"What movies should I watch to learn more about Japanse culture?",("How many movies were released in each decade? Write decade as a string, e.g. ""'1920-1929'. Sort ascending by decade."),("Find movies that are suitable to watch with my kids, both by genre and their ""parental guidance rating. Just recommend good movies."),]BASE_CHAT_MESSAGES = [{"role": "system","content": "You are an expert English to MongoDB aggregation pipeline translation system.""You will accept an example document from a collection and an English question, and return an aggregation ""pipeline that can answer the question. Do not explain the query or add any additional comments, only ""return a single code block with the aggregation pipeline without the aggregate command.",}]9 unmodified linesmessages = BASE_CHAT_MESSAGES + [{"role": "user","content": f"Example document: {doc.strip()}\n\nQuestion: {question.strip()}\n\n",}]27 unmodified linesst.markdown("""# English to MQL DemoThis demo app uses OpenAI's GPT-4 (gpt-4) model to generate a MongoDBaggregation pipeline from an English question and example document.🚧 The app is experimental and may return incorrect results. Do not enter any sensitive information! 🚧"""4 unmodified linescol_left, col_right = st.columns(2, gap="large")with col_left:st.markdown("### Example Document and Question")# wrap textareas in formwith st.form("text_inputs"):doc = st.text_area("Enter example document from collection, e.g. db.collection.findOne()",value=MOVIES_EXAMPLE_DOC,height=300,)# question textareaquestion = st.text_area(label="Ask question in English",value=st.session_state.default_question,)2 unmodified linesif submitted:st.session_state._id = Nonest.session_state.feedback = Falsest.session_state.response = ask_model(doc, question)with col_right:13 unmodified lines141516171819202122232425262728293031323334353637389 unmodified lines4849505152535427 unmodified lines828384858687888990914 unmodified lines969798991001011021031041051061072 unmodified lines11011111211311411511613 unmodified lines# you need to set your OpenAI API key as environment variableopenai.api_key = st.secrets["API_KEY"]SQL_EXAMPLE_QUERIES = [("SELECT CustomerName, City FROM Customers;"),("Select distinct Salary from Employee e1 where 2=Select count(distinct Salary) from Employee e2 where e1.salary<=e2.salary;"),"Select Employee_name,Salary/12 as ‘Monthly Salary’ from employee;",("Select * from Employee where Rowid= select min(Rowid) from Employee;"),]BASE_CHAT_MESSAGES = [{"role": "system","content": "You are an expert SQL to MongoDB aggregation pipeline translation system.""You will accept SQL query and return a MongoDB aggregation pipeline ""that can convert the SQL query. Do not explain the query or add any additional comments, only ""return a single code block with the aggregation pipeline without the aggregate command.",}]9 unmodified linesmessages = BASE_CHAT_MESSAGES + [{"role": "user","content": f"Example SQL Query: {question.strip()}\n\n",}]27 unmodified linesst.markdown("""# SQL to MQL DemoThis demo app uses OpenAI's GPT-3.5 (gpt-3.5) model to generate a MongoDBaggregation pipeline from a SQL query.🚧 The app is experimental and may return incorrect results. Do not enter any sensitive information! 🚧"""4 unmodified linescol_left, col_right = st.columns(2, gap="large")with col_left:st.markdown("### Example SQL query")# wrap textareas in formwith st.form("text_inputs"):# question textareaquery = st.text_area(label="SQL query",value=st.session_state.default_question,)2 unmodified linesif submitted:st.session_state._id = Nonest.session_state.feedback = Falsest.session_state.response = ask_model(query)with col_right:
app.py+16-52