# Need to use pinboard env
import datetime
from search.tools.gptlabeler.gptlabeler_api import get_or_create_prompt, create_labeling_request

def write_to_log(prompt_id, input_id, inputs_hive_table, job_config_id):
    with open("helix_bulk_api_log.txt", "a") as f:
        cur_line = f"prompt_id: {str(prompt_id)}, input_id: {str(input_id)}, Job submition time: {datetime.datetime.now()} using {job_config_id} for table {inputs_hive_table}"
        f.write(cur_line+ "\n")

get_category_sys_prompt = """
    I want you to act as my personal taxonomist and create a hierarchical categorization system for media, genres, or topics that accurately represents their underlying content, while avoiding categories that describe areas or fields of activity, rather than paradigmatic categories?
    Please do not include anything for which one cannot provide many examples.
    I Want: "productivity tool" (good, has specific instances) or "personal development book" (good, has specific instances), "fashion style" (good), "fashion label" (good).
    Don't want: "productivity" (bad; too generic),  "personal development" (bad; too generic), fashion (bad; broad area).
    Please be thorough: if there are more than one sense, please provide hypernyms for each sense. Please try to maintain precision: it is better to provide fewer hypernyms that are more relevant than many hypernyms that are less relevant. Please reply in English even if the term is in another language.
    Each reply should contain "title", "blurb", and "hypernyms" types
    - "title" type to show the term whose hypernyms these are.
    - "blurb" type to describe the major senses of the term (just one if just one meaning).
    - "canonical" type is a spell-corrected correctly-cased form.
    - "hypernyms" type to show associated hypernyms. 
    Please respond only in JSON format, with just one title.
    ```
    {  
        "title": "Message or question to user",  
        "blurb": "a description of title",  
        "canonical": "the canonical form of the title",  
        "hypernyms": [{"hypernym": "option 1", "blurb": "a description of option 1"}]  
    }  
    ```
    """
get_category_user_prompt = """
    Starting with the term "{{annotation}}", please give me a set of hypernyms that accurately categorize this term and others like it. 
    Please only respond in the specific JSON format, and include up to 10 results but only if they are relevant. 
"""

def main():
    nimbus_project = 'alignment_paper_exps'
    creator_ldap = 'abadrinath'
    # create get category prompt
    prompt = get_or_create_prompt(get_category_sys_prompt, get_category_user_prompt, 
                                  nimbus_project, creator_ldap)
    prompt_id = prompt['prompt_id']
    print("Prompt ID: ", prompt_id)

    # create labling request
    inputs_hive_table = f"xiaochunma.annotation_v7_gpt"
    job_config_id = "n1-temp0-chatgpt4"
    input_id = create_labeling_request(prompt_id, 
                                       nimbus_project, 
                                       creator_ldap, 
                                       inputs_hive_table, 
                                       job_config_id)
    print("Input ID: ", input_id)

    print(f"Job submition time: {datetime.datetime.now()}")

    write_to_log(prompt_id, input_id, inputs_hive_table, job_config_id)

    print("Added to log")

if __name__ == "__main__":
    main()
