packages = ["pydantic", "./wheels/pymarc-4.2.2-py3-none-any.whl"] [[fetch]] from = "src" files = ["airflow.py", "chat.py", "folio.py", "github.py"] import asyncio from js import console, document, localStorage from airflow import Airflow from airflow import login as airflow_login from chat import marc2folio_prompt, lcsh_prompt from chat import login as chat_gpt_login, ChatGPT from folio import Okapi, load_marc_record, get_instance from folio import login as okapi_login airflow_instance = Airflow() chat_gpt_instance = None existing_token = localStorage.getItem("chat_gpt_token") if existing_token: chat_gpt_instance = ChatGPT(key=existing_token) chatgpt_button = document.getElementById("chatGPTButton") chatgpt_button.classList.remove("btn-outline-danger") chatgpt_button.classList.add("btn-outline-success") chat_prompts_div = document.getElementById("chat-gpt-prompts") chat_prompts_div.classList.remove("d-none") okapi = Okapi() marc_file = Element("marcFile") async def login_airflow(): await airflow_login(airflow_instance) async def login_chatgpt(): global chat_gpt_instance chat_gpt_instance = await chat_gpt_login() async def login_okapi(): folio_logged_in = await okapi_login(okapi) async def display_prompt(prompt_name): chat_gpt_instance.messages = [] prompt_div = document.getElementById("prompt-text") m2f_wkflow_div = document.getElementById("marc2folio-workflow") lcsh_wkflow_div = document.getElementById("lcsh-workflow") match prompt_name: case "lcsh": prompt_div.innerHTML = lcsh_prompt m2f_wkflow_div.classList.add("d-none") lcsh_wkflow_div.classList.remove("d-none") await chat_gpt_instance.set_system(lcsh_prompt) case "marc2folio": prompt_div.innerHTML = marc2folio_prompt m2f_wkflow_div.classList.remove("d-none") lcsh_wkflow_div.classList.add("d-none") await chat_gpt_instance.set_system(marc2folio_prompt) case _: prompt_div.innerHTML = "No prompt" m2f_wkflow_div.classList.add("d-none") lcsh_wkflow_div.classList.add("d-none") async def lcsh_conversation(): instance_uuid_elem = document.getElementById("instance-uuid") instance = await get_instance(okapi, instance_uuid_elem.value) raw_instance_elem = document.getElementById("raw-instance") raw_instance_elem.innerHTML = instance instance_subjects = document.getElementById("instance-subjects") h3 = document.createElement("h3") h3.innerHTML = "Instance Subjects" instance_subjects.appendChild(h3) subjects_ul = document.createElement("ul") for subject in instance["subjects"]: li = document.createElement("li") li.innerHTML = subject subjects_ul.appendChild(li) instance_subjects.appendChild(subjects_ul) results_div = document.getElementById("lcsh-result") conversation = await chat_gpt_instance("\n".join(instance["subjects"])) if "error" in conversation: results_div.innerHTML = f"""Error status {conversation["error"]}\n{conversation["message"]}""" else: for choice in conversation.get("choices"): pre_elem = document.createElement("pre") pre_elem.innerHTML = choice["text"] results_div.appendChild(pre_elem) async def marc2folio_conversation(): result_div = document.getElementById("marc2folio-result") marc_str = await load_marc_record(marc_file) raw_marc_pre = document.getElementById("raw_marc") raw_marc_pre.innerHTML = marc_str prompt_elem = Element("prompt-01") additional_prompt = prompt_elem.value if marc_str is not None: additional_prompt += f"\n{marc_str}" conversation = await chat_gpt_instance(additional_prompt.strip()) convo_div = document.createElement("div") if "error" in conversation: convo_div.innerHTML = f"Error status {conversation['error']}" else: for choice in conversation.get('choices'): pre_elem = document.createElement("pre") pre_elem.innerHTML = choice['text'] convo_div.appendChild(pre_elem) result_div.appendChild(convo_div) async def chatGPTModalContents(): if chat_gpt_instance is not None: modal_body = document.getElementById("chatApiKeyModalBody") modal_body.innerHTML = "Already logged into ChatGPT"

FOLIO ML Tools

Chat GPT

A ReAct inspired static side toolkit using OpenAI for FOLIO workflows using code from this blog post

Prompts


        

MARC-to-FOLIO


           

LCSH Workflow


           

Interact Programmatically with Tools through the REPL