fancy_sql_process.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can generate a Python program that retrieves data from a SQL file."
  3. TAGS = ['sql']
  4. question = """
  5. I have a sqlite3 database name TEXT, favorite_friend TEXT, age INT, profession TEXT.
  6. Write me a python program that prints out the favorite friend of the youngest person who isn't anyone's favorite friend.
  7. The database is called people.db and the table is called people.
  8. """
  9. def setup():
  10. import sqlite3
  11. # Create a connection object using the connect function
  12. conn = sqlite3.connect('people.db')
  13. # Create a cursor object using the cursor method
  14. cursor = conn.cursor()
  15. # Create table named people with columns for name, favorite friend, age, and profession
  16. cursor.execute('''CREATE TABLE people
  17. (name TEXT, favorite_friend TEXT, age INT, profession TEXT)''')
  18. # List of people data to insert into the people table
  19. people_data = [
  20. ('Alice', 'Bob', 29, 'Engineer'),
  21. ('Bob', 'Alice', 32, 'Doctor'),
  22. ('Charlie', 'Alice', 28, 'Artist'),
  23. ('David', 'Eve', 35, 'Architect'),
  24. ('Eve', 'Frank', 26, 'Teacher'),
  25. ('Frank', 'Alice', 31, 'Scientist'),
  26. ('Grace', 'Heidi', 30, 'Nurse'),
  27. ('Heidi', 'Ivy', 25, 'Lawyer'),
  28. ('Ivy', 'Charlie', 34, 'Chef'),
  29. ('Judy', 'Grace', 27, 'Accountant')
  30. ]
  31. # Insert each person into the people table
  32. cursor.executemany('INSERT INTO people VALUES (?,?,?,?)', people_data)
  33. # Commit the changes
  34. conn.commit()
  35. # Close the connection
  36. conn.close()
  37. TestSqlSubquery = Setup(setup) >> question >> LLMRun() >> ExtractCode(keep_main=True, lang='python') >> Echo() >> PythonRun() >> SubstringEvaluator("Grace")
  38. if __name__ == "__main__":
  39. print(run_test(TestSqlSubquery))