I’m getting this error:
TypeError: 'ChatCompletion' object is not subscriptable
From this code:
Calling the object:
def nl_to_sql(prompt):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "system", "content": "You are an assistant skilled in SQL."}, {"role": "user", "content": prompt}],
max_tokens=150
)
return response['choices'][0]['text'].strip()
converting to SQL Query:
#QUERY
nl_query = "sample query goes here"
#END QUERY
sql_query = nl_to_sql(nl_query)
print(f"SQL Query: {sql_query}")
result = execute_sql(sql_query, engine)
if result is not None:
display(result)
else:
print("Failed to retrieve data.")
Any ideas?
Attempting to translate natural language input to a SQL query using the OpenAI API. The object that was working before is no longer working in the current version.