Microsoft Dev Blogs

Dynamic Sqlite queries with OpenAI chat functions

thumbnail
  • This blog post explains how to use OpenAI's chat functions to execute dynamic SQLite queries.
  • The post provides an example of implementing the model-generated arguments function call in Kotlin, using droidcon SF 2023 conference schedule data as the source.
  • The blog highlights the potential risks of using dynamically generated SQL in production applications, but notes that for this specific use case (read-only database API with single-user favorites), there is no risk of data loss or privacy concerns.
  • The post includes code snippets and instructions on how to debug the SQL generated by the model.
  • The model is taught the latest schema by dynamically generating the schema using Sqlite system tables.
  • The dynamically generated schema is used to execute the queries generated by the model.
  • The model demonstrates its ability to understand complex return datasets and generate responses that correctly interpret the data.
  • The blog explains how the model can now answer various types of questions related to conference data using SQL querying capabilities.
  • Examples of possible questions and the corresponding SQL queries and responses are provided.
  • The post concludes by highlighting the expanded capabilities of the model now that it can generate and execute SQL queries.