Skip to main content

Command Palette

Search for a command to run...

Playing with ChatGPT API

Updated
2 min read
Playing with ChatGPT API
E
I make AI models like Dolphin and Samantha https://ko-fi.com/erichartford BTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4 ETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9

I thought I would try out ChatGPT's new API, so I decided to write a command line interface. My code is located here:

I wanted it to be conversational, so it will remember your conversation history as you type.

Similar to chatgpt-wrapper. https://github.com/mmabrouk/chatgpt-wrapper but in Node.

I wanted it to use TypeScript, and I wanted it to use Node's new native fetch api (which was officially promoted from "experimental" as of 18.13.0)

Example output:

I found that it's not that simple to bootstrap a TypeScript CLI. No "create" scripts here. I used ts-node so I can run it without building, like this:

I had to work around the fact that @types/node has no types for Node's native fetch library. (drop a note here if you would like to ask @types/node to add support for Node's native fetch, or contribute a pull request)

Then I had to add the typings in my tsconfig.json:

Then, it's a while loop that takes input, appends it to the history, and sends a request to the completions api, and appends the response to the history as well as displaying it.

You can find my code here:

I find this personally useful because it's much cheaper than ChatGPT Plus, and also it works even when ChatGPT is down.

Feel free to make a PR if you want to fix anything or add anything. I promise I'll review it!

More from this blog

Quixi AI

19 posts

Applied AI Researcher I make AI models like Dolphin and Samantha https://ko-fi.com/erichartford BTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4 ETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9 https://quixi.ai