I am having an issue with a background task where I am trying to use the CodeInterpreter to call OpenAI via the api codeinterpreterapi . This class is attempting to write to the file system, which I understand Anvil does not permit on its servers.
This is the code I have:
@anvil.server.background_task
def launch_code_interpreter_background(history, query):
print("launch_code_interpreter_background:", query)
session = CodeInterpreterSession(openai_api_key=anvil.secrets.get_secret('OPENAI_API_KEY'), model="gpt-4")
user_request = "Analyze this dataset and plot something interesting about it."
files = [
File.from_url(f"{anvil.server.get_app_origin()}/_/theme/...1.csv"),
File.from_url(f"{anvil.server.get_app_origin()}/_/theme/...2.csv"),
File.from_url(f"{anvil.server.get_app_origin()}/_/theme/...3.csv"),
]
async def generate_response_coro():
response = await session.generate_response(user_request, files=files, detailed_error=True)
return response
response = asyncio.run(generate_response_coro())
print('response', response)
return response
When I run this code, I receive the following error:
Error in CodeInterpreterSession: OSError - [Errno 30] Read-only file system: '.codebox'
Any help you could provide would be greatly appreciated. Thank you in advance!