Hi
I have looked at the comments below
I have created a script but it keeps telling me that the openai API doesnt exist and the table doesnt exit
I have triple checked the API and the table name - even changed it to make it easier:
from seatable_api import Base, context
import requests
# Authentication with SeaTable
base = Base(context.api_token, context.server_url)
base.auth()
# Function to interact with OpenAI
def ask_openai(question):
headers = {
'Authorization': 'Bearer api', # Ensure to handle API keys securely
'Content-Type': 'application/json'
}
data = {
"model": "gpt-3.5-turbo-instruct",
"prompt": question,
"max_tokens": 150
}
try:
response = requests.post('https://api.openai.com/v1/models/gpt-3.5-turbo-instruct', headers=headers, json=data)
response_data = response.json()
print("Response:", response_data) # Debugging line
return response_data['choices'][0]['text']
except Exception as e:
print("Error:", str(e)) # Debugging line
return None
# Script to update rows based on the question column
rows = base.list_rows("tablename")
for row in rows:
if 'question' in row and row['question'] and not row['answer']: # Check if question is asked and answer is not yet provided
answer = ask_openai(row['question'])
action = "Review needed" # Define an action based on your logic
base.update_row('YourTableName', row['_id'], {'answer': answer, 'action': action})