Overview

When building a chat interface using RAG (Retrieval-augmented generation) with OpenAI’s Assistants API, I used the following repository.

https://github.com/openai/openai-assistants-quickstart

A modification was needed regarding the handling of citation, so I am documenting it here as a memo.

Background

I used the above repository to try RAG with OpenAI’s Assistants API.

With the default settings, citation markers like “4:13†” were displayed as-is, as shown below.

Solution

I modified annotateLastMessage as follows. By changing file_path to file_citation, the citation markers could be replaced.

As an example, the following replaces them with links to the File API.

con}s;ts}e)atcc}a}r;nGMoo;n)eneennni};totsssofutstt.tu)ratala(p;nthgluatada`eeeapsinan[[Lssdtontn.ac(taMnoeo.su(Mtestdt.trpees.aLa]pMrrsdsftat(reeesLaoisiesnvaagrotavstMgseEnMnpMaeet,a.e.iegmsMctst/sees=ehysefssas(paxia=sgps(egtlgaeraae,ee(gsegn=.ssae)ven=t/.nsMo=e$sn=e=tx{lo>sa"taits{tfnca{aii=netgolo(ieneut0os)_pa,n[cdtsp=iai-)r>tto1eaen)=v{td.,>MiLfeoaiu{snslps"teda)M_agecte{siesstd.aaLlgtaeeisn.otgtnMte.ehxfstis-.lareg1e_e]pi];ld;a}c)e`All(

As a result, links are now displayed as shown below.

Summary

The replacement content can be changed depending on your purpose. I hope this serves as a helpful reference.