import tempfile
import json


def convert_txt_to_tmp_json_file(txt_inference: str) -> str:
    """Converts a txt with inference content to a JSON file with schema
    expected by read_examples. Returns a filename to the temp JSON file."""
    tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
    json_data = [{"doc_id": 0, "doc_text": txt_inference}]

    tmp_file.write(json.dumps(json_data))
    tmp_file.close()

    return tmp_file.name