Teaching ChatCraft to do Citations

Back in the summer, I did a bunch of work to give chatcraft.org the power to use functions.  Since then, Taras has improved it to allow you to use TypeScript and JavaDoc-style comments to build your function with full metadata understood by OpenAI.  I didn't really have a reason to use it at the time, but it was the kind of "nice to have" feature that seemed good to include.

But this week I did need it.  I was talking with some people about how they were using ChatCraft to help format citations properly, but they were frustrated that it would make up details.  "It's too bad it can't get the real info and use that."  But it can!

I wrote a small TypeScript function to use the CrossRef REST API to get all the metadata that's known about a given DOI or DOI URL.  I then gave ChatCraft access to the function by including this in my prompt @fn-url:https://gist.github.com/humphd/74cf88283239c62f53caff5cddf4cfe5.  This @fn-url:... syntax tells the app it can use a function hosted at the given Gist URL.  The function describes what it can do, and the inputs/outputs.  OpenAI can then decide when/if to use it.

Here's an example of what it looks like when you use it:

https://chatcraft.org/c/humphd/CVwmeKqB8iwwIO9CYKeV2

I prompt the LLM like so:

I need to cite https://doi.org/10.1093/ajae/aaq063 in APA, MLA, and Chicago

And it calls the function, gets back the metadata, and returns a response:

To cite the article "An Analysis of the Pricing of Traits in the U.S. Corn Seed Market" in APA, MLA, and Chicago styles, you can use the following formats
APA: Shi, G., Chavas, J., & Stiegert, K. (2010). An analysis of the pricing of traits in the U.S. corn seed market. *American Journal of Agricultural Economics, 92*(5), 1324-1338. doi:10.1093/ajae/aaq063
MLA: Shi, Guanming, Jean-paul Chavas, and Kyle Stiegert. "An Analysis of the Pricing of Traits in the U.S. Corn Seed Market." *American Journal of Agricultural Economics*, vol. 92, no. 5, 2010, pp. 1324-1338. doi:10.1093/ajae/aaq063.
Chicago: Shi, Guanming, Jean-paul Chavas, and Kyle Stiegert. "An Analysis of the Pricing of Traits in the U.S. Corn Seed Market." *American Journal of Agricultural Economics* 92, no. 5 (2010): 1324-1338. doi:10.1093/ajae/aaq063.
Please note that the DOI (Digital Object Identifier) is included at the end of each citation.

Extending ChatCraft with extra powers is really easy by adding @fn:name (for functions you write in the app itself) or @fn-url:url for functions you want to share with others.

Show Comments