What I’m trying to do:
My app has gotten a number of users and I am encountering a number of errors. I am working with Jay and Stu on them and sent an email to Anvil support, where Ryan asked me to post about them in the forums. We have checked each of these extensively and couldnt solve them, so would love support!
Here I have many, many backgrouund tasks failing at the same time. They all have the same error.
Error: anvil.server.RuntimeUnavailableError: Downlink disconnected
Time: Wed 17.4 around 12:00 CEST
Session IDs:
SYHZK5D6KBPYG4B6HBAOSJMSADMRXWYX
OVAI6KRSCCA3DD75RRN7XIIHYEIV4QM7
3HZSH5EVCER4W3FEUHMVCHT36YFIISI6
6WVTWYYJSWEO3LKZLJRNMXTMUMPGETEZ
…
Here the failing task, which runs smoothly at all other times:
@anvil.server.background_task
def openai_background_task(ai_prompt, ai_token_num):
start_time = time.time()
token_multiplyer = 1.5 # how much longer the answer can be than the input
openAI_key = anvil.secrets.get_secret("openAI_key")
client = OpenAI(api_key=openAI_key)
print(f"ai_token_num: {ai_token_num}, token_multiplier: {token_multiplyer}")
response = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
messages=[
{
"role": "user",
"content": ai_prompt
}
],
temperature=0.2,
max_tokens=int(ai_token_num * token_multiplyer),
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
time_taken = time.time()-start_time
openai_message_cotent = response.choices[0].message.content
print(f'Completing API call took {time_taken} seconds')
print(f"openai_message_cotent: {openai_message_cotent}")
return openai_message_cotent