Skip to content

Commit

Permalink
Working Sinopia-to-FOLIO workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jermnelson committed Nov 16, 2023
1 parent 6c2c0b7 commit 6ff5602
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
18 changes: 12 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
folio_btn = document.getElementById("folioButton")
folio_btn.classList.remove("btn-outline-danger")
folio_btn.classList.add("btn-outline-success")
folio_iframe = document.getElementById("folio-system-frame")
folio_iframe.src = okapi.folio
default_folio = document.getElementById("folio-default")
default_folio.classList.add("d-none")



marc_file = Element("marc-upload-btn")
Expand Down Expand Up @@ -178,9 +183,7 @@ <h1>Chatting with Catalogs</h1>
</div>
<div class="col-2">
<img src="imgs/hexsticker.png" alt="AI4LAM Hex Sticker and Logo" style="height: 100px;">
<div>
<small class="align-middle">Bugs? Ideas for improving? Please add a ticket <a href="https://github.com/AI4LAM/catalog-chat/issues" target="_blank">here</a>.</small>
</div>

</div>
</div>
<div class="row">
Expand Down Expand Up @@ -349,14 +352,17 @@ <h2>Workflows</h2>
<li>
<a href="#" py-click="asyncio.ensure_future(load_workflow('transform-bf-folio'))">Transform Sinopia BIBFRAME to FOLIO Inventory</a>
</li>
<li>
<li class="">
<a href="#" py-click="asyncio.ensure_future(load_workflow('add-lcsh'))">Add LCSH to Sinopia RDF or FOLIO Records</a>
</li>
<li>
<a href="#" py-click="asyncio.ensure_future(load_workflow('marc-to-folio'))">Upload a MARC Record to create a FOLIO Inventory Record</a>
</li>
</ul>
<div>
<div class="mt-2 alert alert-info w-75">
<small class="align-middle">Bugs? Ideas for improvment? Please add a ticket <a href="https://github.com/AI4LAM/catalog-chat/issues" target="_blank">here</a>.</small>
</div>
<div class="">
<h2>Vector stores</h2>
<p>
To improve the context of the chat and reduce model hallucinations,
Expand Down Expand Up @@ -814,7 +820,7 @@ <h5 class="offcanvas-title" id="pythonOffCanvasLabel">
</div>

</div>
<footer class="p-2 rounded bg-secondary-subtle">
<footer class="p-2 mt-2 rounded bg-secondary-subtle">
<small>
<p>
An experimental Chat application by AI4LAM Metadata Working Group.
Expand Down
3 changes: 2 additions & 1 deletion src/folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def error_card(errors, okapi):
card_html += """</div>
<div class="card-footer">FOLIO server {okapi.folio} Okapi API {okapi.urll}</div>
</div>"""
row_div = document.createElement("div")
if prompt_history.hasChildNodes():
prompt_history.insertBefore(row_div, prompt_history.firstChild)
else:
Expand Down Expand Up @@ -168,7 +169,7 @@ async def add_instance(record):
return f"""{okapi.folio}/inventory/view/{instance["id"]}"""
else:
console.log(f"Error adding {instance_response}")
error_card(instance_response, okapi)
error_card(instance_response.json()["errors"], okapi)
return instance_response


Expand Down
9 changes: 5 additions & 4 deletions src/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,16 @@ async def __handle_func__(self, function_call) -> str:
match function_name:

case "add_instance":

record = json.loads(args.get("record"))
self.__update_record__(record)
#console.log(f"SinopiaToFOLIO {record}")
console.log(f"SinopiaToFOLIO after update")
instance_url = await add_instance(json.dumps(record))
#console.log(f"After SinopiaToFOLIO func call {instance_url}")
console.log(f"After SinopiaToFOLIO func call {instance_url}")
output = instance_url

case "load_sinopia":
sinopia_rdf = await load_sinopia(args.get("resource_url"))
prompt = "Create a FOLIO Instance JSON record from"
prompt = "Add FOLIO Instance JSON record from"
add_history(f"{prompt}<pre>{sinopia_rdf}</pre>", "prompt")
output = f"{prompt}\n{sinopia_rdf}"

Expand Down Expand Up @@ -401,8 +400,10 @@ async def run(self, chat_instance: ChatGPT, initial_prompt: str):
function_call = chat_result["choices"][0]["message"].get("function_call")
if function_call:
first_result = await self.__handle_func__(function_call)
console.log(f"First result")
chat_result_rdf = await chat_instance(first_result)
final_func_call = chat_result_rdf["choices"][0]["message"].get("function_call")
console.log(f"Final func {final_func_call}")
final_result = await self.__handle_func__(final_func_call)
# console.log(f"The final result {final_result}")
add_history(chat_result_rdf, "response")
Expand Down

0 comments on commit 6ff5602

Please sign in to comment.