OpenAI in seatable environment

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})

error: Error: line 29, in rows = base.list_rows(“Table Name”) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/root/.local/lib/python3.11/site-packages/seatable_api/main.py”, line 60, in wrapper return func(obj, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/root/.local/lib/python3.11/site-packages/seatable_api/main.py”, line 397, in list_rows data = parse_response(response) ^^^^^^^^^^^^^^^^^^^^^^^^ File “/root/.local/lib/python3.11/site-packages/seatable_api/main.py”, line 41, in parse_response raise ConnectionError(response.status_code, response.text) ConnectionError: [Errno 404] {“error_msg”:“table not found”}

The error message is super clear: “table not found”. There is no such table in your base with the name you provided. Please provide a screenshot of your tables in your base.

Tried the base name and then the table name

did you try to replace “tablename” with “Namebio5yrs25K”?

yes I did - in fact I deleted it to change it for here

Look at the last line of your script.

How embarrasing.

Thanks

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.