OpenAI Crystal Library

OpenAI Crystal Library

June 21, 2023
OpenAI, Crystal Lang, Programming, Autonomous Systems, API, guppi, Code Assistant, Library, AI

Hello everyone! I’ve been developing a new library for OpenAI in Crystal Lang.

My fascination with autonomous systems led me to create a semi-autonomous assistant to aid my coding process. There was an existing OpenAI library in Crystal, but it didn’t quite meet my needs and lacked some key features. The most significant addition I’ve made is streaming, which is necessary for streaming code output to the user that guppi is writing. I’ll write more into guppi in a later post. For now, you can check it out here: https://github.com/lancecarlson/guppi

But let’s get back to my OpenAI library.

Installation #

Installing openai.cr is a breeze. Here’s how:

  • Add the dependency to your shard.yml.
  • Run shards install. And voila! The party can start.

Usage #

With openai.cr, you can:

  • List and show models.
  • Create a completion for the chat message.
  • Create a new edit for the provided input instruction and parameters.
  • Create an embedding vector representing the input text.
  • Classify if text violates OpenAI’s content policy.

Get it! #

You can download and read more here:

https://github.com/lancecarlson/openai.cr

Endpoints Under Development #

  • Files
  • Fine tunes
  • Images

These are all currently missing because I need to implement the sending of files to the API.