Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
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(
|