LeonceNsh commited on
Commit
c6f04cb
·
verified ·
1 Parent(s): 13f0f94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -77,24 +77,21 @@ def parse_query(nl_query):
77
  """
78
  Converts a natural language query into a SQL query using OpenAI's GPT-4-turbo model.
79
  """
80
- openai.api_key = os.getenv('OPENAI_API_KEY') # Ensure your API key is set as an environment variable
81
-
82
- messages = [
83
- {
84
- "role": "system",
85
- "content": (
86
- "You are an assistant that converts natural language queries into SQL queries "
87
- "for a DuckDB database named 'contract_data'. Use the provided schema to form accurate SQL queries."
88
- )
89
- },
90
- {
91
- "role": "user",
92
- "content": (
93
- f"Schema:\n{json.dumps(schema, indent=2)}\n\n"
94
- f"Natural Language Query:\n\"{nl_query}\"\n\nSQL Query:"
95
- )
96
- }
97
- ]
98
 
99
  try:
100
  response = openai.ChatCompletion.create(
 
77
  """
78
  Converts a natural language query into a SQL query using OpenAI's GPT-4-turbo model.
79
  """
80
+
81
+ # new
82
+ from openai import AsyncOpenAI
83
+
84
+ client = AsyncOpenAI()
85
+ completion = await client.chat.completions.create(model="gpt-3.5-turbo",
86
+ messages = [{"role": "system",
87
+ "content": (
88
+ "You are an assistant that converts natural language queries into SQL queries "
89
+ "for a DuckDB database named 'contract_data'. Use the provided schema to form accurate SQL queries.")
90
+ },
91
+ {"role": "user",
92
+ "content": ( f"Schema:\n{json.dumps(schema, indent=2)}\n\n" f"Natural Language Query:\n\"{nl_query}\"\n\nSQL Query:"
93
+ )}
94
+ ])
 
 
 
95
 
96
  try:
97
  response = openai.ChatCompletion.create(