Gathering detailed insights and metrics for open-ai-npc
Gathering detailed insights and metrics for open-ai-npc
Gathering detailed insights and metrics for open-ai-npc
Gathering detailed insights and metrics for open-ai-npc
npm install open-ai-npc
Typescript
Module System
Min. Node Version
Node Version
NPM Version
74
Supply Chain
99.4
Quality
86
Maintenance
100
Vulnerability
100
License
TypeScript (68.7%)
HTML (25.17%)
EJS (5.96%)
Shell (0.17%)
Total Downloads
9,862
Last Day
1
Last Week
2
Last Month
17
Last Year
6,640
MIT License
5 Stars
284 Commits
1 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Apr 17, 2025
Latest Version
1.0.111
Package Id
open-ai-npc@1.0.111
Unpacked Size
4.24 MB
Size
1.08 MB
File Count
28
NPM Version
10.9.2
Node Version
22.14.0
Published on
Apr 17, 2025
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
-79.3%
17
Compared to previous month
Last Year
106.1%
6,640
Compared to previous year
Using OpenAI to generate NPC dialog for characters in a JRPG.
https://jacklehamster.github.io/open-ai-npc/
https://github.com/jacklehamster/open-ai-npc/
Let's say you want to grab the repo, and setup your own project using the NPC dialog generator, perhaps tweak it so it gives you better results. You can do that! (This is an open source project after all).
Here are the steps below:
1gh repo clone jacklehamster/open-ai-npc
Or personally, I prefer UI based Git app like SourceTree
Add a bash command to save your OpenAPI key
1export OPENAI_API_KEY=sk-?????
Just run ./sample.sh
, then go to http://localhost:3000/
From there, you can test the demo or try out the rest API.
Note that a bunch of pre-filled data is cached in the ".node-persist" folder, so initially you won't hit OpenAI API. To clear the cache, just delete that folder.
Go to http://localhost:3000/api
Then select a choice, and use it as query parameter: http://localhost:3000/api?choice=A
To go further, you have to append your new choice to the choice history, separated by "|". Ex: http://localhost:3000/api?choice=A|B http://localhost:3000/api?choice=A|B|A
If your choice is a letter A,B,C or D, the choice from the AI will be selected. That said, you can write pretty much anything in the choice. If the AI is not confused, it will respond accordingly.
Ex: http://localhost:3000/api?choice=your%20name
The entry point to call the API is in choices.ts:
1fetchChoice(choice: string, 2 model: string = "gpt-3.5-turbo-1106", 3 creature: string = "an angel with wings") { 4 5}
By default, we're using gpt-3.5-turbo-1106
because it's the cheapest one. It does have mixed results, but good enough for demoing. You can upgrade to gpt-4-turbo
. It'll give you better results but costs a bit more.
You can also pass a different creature description.
While it took me quite some time to refine the prompt for OpenAI to give me consistent result, you can play around with it to improve it, or expand it to return some new game information.
The prompt is stored in the file systemprompt.ts.
Once done, you can run:
1./sample.sh
And test both the API and the demo.
You need a server that can host Bun.js. You will also need to store the Open API key in your server's environment variable.
Then start the bun application
1bun start
As you make calls to OpenAI API through the open-ai-npc API, the app caches every response into the .node-persist/storage
folder. This is helpful to keep you from spending all your OpenAI credits on repeated queries.
That said, if something funky happens, feel free to wipe out that folder.
Since that folder is checked in, you can actually test out a few paths and check in the cache. That way, your server will hit all that built-in cache when new users try your API.
So far, I've spend ~$1 of OpenAI credits, using the cheapest model. So it's not all that bad. The cache helps to bring the cost down.
If you're not cheapskate like me, you can up the model to "gpt-4". I tested it for a bit, and the responses seemed a bit more creative, and less wonky.
I hope you enjoy using this API, and have fun!
No vulnerabilities found.