switched to in memory file

This commit is contained in:
gilcu3
2023-11-09 18:07:31 +01:00
parent d637e35498
commit bc1a3f38a1

View File

@@ -10,7 +10,7 @@ import openai
import requests import requests
import json import json
import httpx import httpx
import tempfile import io
from datetime import date from datetime import date
from calendar import monthrange from calendar import monthrange
@@ -350,8 +350,9 @@ class OpenAIHelper:
response_format='opus' response_format='opus'
) )
temp_file = tempfile.NamedTemporaryFile() temp_file = io.BytesIO()
response.stream_to_file(temp_file.name) temp_file.write(response.read())
temp_file.seek(0)
return temp_file, len(text) return temp_file, len(text)
except Exception as e: except Exception as e:
raise Exception(f"⚠️ _{localized_text('error', bot_language)}._ ⚠️\n{str(e)}") from e raise Exception(f"⚠️ _{localized_text('error', bot_language)}._ ⚠️\n{str(e)}") from e