Beyond the typo, there’s another issue that’ll cause problems. You’re doing api_client = openai.Completion() but that’s not how the OpenAI library works. You need to call openai.Completion.create() directly on the module instead. Depending on your OpenAI version, you might want openai.ChatCompletion.create() for better results. I hit the same issue when migrating between library versions - the API changed big time between v0.x and v1.x. Run pip show openai to check your version and look at the docs for the right syntax.
heads up - you’re missing error handling for when the file doesn’t exist. log_file = open("", "r") will crash after you fix the openai typo since there’s no filename. wrap it in try/except or use os.path.exists() to check first. learned this one the hard way lol
I’m seeing the same bug others mentioned, but here’s a better approach I’ve used for chatbot projects.
Skip wrestling with file handling and API calls manually - I built my last chatbot using Latenode. The OpenAI integration becomes drag and drop, so no more typos like openai("", "r") when you meant open("", "r").
Latenode handles conversation logging automatically. No manually reading/writing files or managing conversation state. Just connect OpenAI node to a database node and it stores everything.
I deployed a customer service bot this way last month. Took maybe 30 minutes to set up vs the hours I used to spend debugging Python file operations and API calls.
Your current approach will work once you fix the typo, but you’ll hit more issues with file locking, error handling, and scaling. Latenode removes all that complexity.