Adapt to latest openai API.
This commit is contained in:
parent
1d21c99562
commit
3c123069af
13
table.py
13
table.py
|
@ -329,9 +329,11 @@ class Table(DeactivableMixin, ModelSQL, ModelView):
|
|||
def ai(cls, tables):
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
import openai
|
||||
openai.organization = config.get('openai', 'organization')
|
||||
openai.api_key = config.get('openai', 'api_key')
|
||||
from openai import OpenAI
|
||||
client = OpenAI(
|
||||
organization=config.get('openai', 'organization'),
|
||||
api_key=config.get('openai', 'api_key')
|
||||
)
|
||||
for table in tables:
|
||||
sqltables = dict.fromkeys(table.ai_sql_tables)
|
||||
|
||||
|
@ -361,9 +363,8 @@ class Table(DeactivableMixin, ModelSQL, ModelView):
|
|||
'role': 'user',
|
||||
'content': request,
|
||||
}]
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=messages)
|
||||
response = client.chat.completions.create(model="gpt-3.5-turbo",
|
||||
messages=messages)
|
||||
if response.choices:
|
||||
query = response.choices[0].message.content
|
||||
if not table.query:
|
||||
|
|
Loading…
Reference in New Issue