import io import jieba from supabase import create_client, Client from api.openai_scripts_chinese.config import SUPABASE_URL, SUPABASE_KEY supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) def load_word_database_dictionary_from_supabase(): table_name = "word_database" response = supabase.table(table_name).select("term, weight, type").execute() if response.data: dict_data = io.StringIO() for item in response.data: dict_data.write(f"{item['term']} {item['weight']} {item['type']}\n") dict_data.seek(0) jieba.load_userdict(dict_data) # print("Loaded dictionary from Supabase") return True else: print(f"No data found or an error occurred: {response.error}") print("Using default dictionary as Supabase data couldn't be fetched.") return False