How I used AI to write a Final Fantasy VI chatbot

When I started my Blaugust project to create 31 game ideas using AI as much as possible, the actual end goal was to learn to create AI-powered tools to help me with blogging — generating ideas, titles, excerpts, correct spellings and grammar, things like that. Things that GPT-3 is actually well suited to handle.

During August, I started playing FF6 on my SteamDeck and on the PC. I haven’t played this game all the way through for a long, long time, and I’d forgotten most everything.

So I thought about loading up GPT-3 with all the Final Fantasy VI information I could find on GameFaqs, Reddit, Wikis, anything I could find. Massive copyright violation. And then I could just pack this into a chat bot and ask it anything I needed to know.

I did write the chatbot, picture below. It is real and does work, but since it costs me a small amount of money whenever I ask a question, it would be expensive and pointless to put it on a public facing server where some spammer would eventually land me with a million dollar hosting bill. So this… this is just for me. The code is at my GitHub page. You’ll have to provide your own OpenAI API key. Just run oai.py and point your browser at it.

I’ll go into more detail past the pic.

Actual conversation with TerraChat.

Telling TerraChat about Final Fantasy VI

The standard GPT-3 Da Vinci text engine actually has quite a lot of Final Fantasy 6 content built-in, but there’s lots of gaps. Da Vinci will happily make stuff up for anything it doesn’t know, and there’s no way of telling when it’s giving actual information versus just spinning an elaborate web of lies.

There are two ways of getting information into the text engine. One is by overloading the prompt with all sorts of background information. You have 4K tokens, minus the expected length of the response and minus the expected length of the question, to just put in any particular information. Right now, the prompt I use just instructs Da Vinci on who it is supposed to be (Terra, from Final Fantasy VI), some information about herself and her goals, and the list of dances Mog can learn.

It was bugging me that she would just put in some random real world dances.

After that, you can just chat with Terra in the GPT-3 Playground all you like. But she won’t know anything Da Vinci didn’t already know about Final Fantasy VI.

Enter “Fine Tuning”. This is where you prepare a large number of sample prompts and answers. Like, “What are Ultros’ elemental vulnerabilities and status weaknesses?”, and then you’d provide that answer. I wrote a tool that generates various sorts of prompt/answer pairs — it’s in the repo. OpenAI has a tool that takes the CSV that generates and formats it as a JSONL file, making some suggested changes to improve the fine tuning.

Then comes the tuning itself, which cost about a buck each time I ran it. The Da Vinci model isn’t available for tuning; it recommends the previous model, Curie, to handle that. It runs through the data several times (called ‘epochs’), and you can play with various other parameters to potentially improve results. I built three fine tuned Curie models, each with a different set of prompts and answers, and… it was very disappointing. Using Curie instead of Da Vinci was a HUGE step downward, and it was very hard to get information out of it.

Granted, I only had about four thousand training tuples vs the hundred thousand or so it likes, and I only used the default four epochs. I might have improved it, but I just don’t think there’s any way that interacting with TerraChat in a natural way could extract that info.

So I abandoned that for now, and overloading the prompt is what current TerraChat uses.

Writing a chatbot in Python

This was actually fairly easy, as there are examples online, and I just took one. I also subscribe to an AI code generator, GitHub Co-pilot, so I mostly only had to take all the stuff I’d set up in the OpenAI playground and get it working locally.

That was pretty easy, and that was where I was last night. Nobody wants to use a terminal window, though, and that meant… bringing it onto the web.

Bringing up a Flask web server

I mentioned GitHub Co-pilot, right? I opened up my Python chatbot program and asked it to write a web server with parameters I specified, endpoints and the such.

And it did. I added some routes to get the static web page that would be driving all of this, the “favicon.ico” for the tab bar, a route to get the images and stuff I’d be using, and that was that.

I ran the server and hit the test URL and it responded with “Hello, World!” and it was ready for the fun stuff, finally.

Writing the web application

I’m ages behind the curve for writing web apps. I’m still mostly using jQuery. Fortunately, GitHub Co-pilot knows all about HTML and jQuery. I asked Co-pilot to make a quickie form with a text box, an input box, and a submit button, and it did that. It looked terrible, but it was good enough to get input into the chatbot.

I initially just used straight POST parameters, but then I asked both the back end and front end to write a RESTful JSON-based interface, which it did.

I designed the UI to look like a chat conversation — this was work I did. The part you need a human for. I set to tune that for a few hours. I designed the CSS (though I had Co-pilot do a little of this work, specifically for the gradients).

AI is taking my job!

No, it isn’t. There is SO MUCH talk about AI killing jobs for creatives. Well, I am a creative, and AI is coming for coders as much as it’s coming for artists or writers.

And you know what? I am FINE with it. I had no desire to pore through online docs for setting up a Flask server or a RESTful service, or the parameters for the $.ajax call, or the URL where Google CDN stashes its jQuery library — I didn’t want to worry about ANY of that. I just wanted to make it fun and look good.

I really can’t speak for artists and writers. But I would be shocked if AI didn’t turn out to be just another tool in their toolchest. Artists will be able to make more art. Non-artists will be able to make okay art that wouldn’t have otherwise existed.

Because none of these AI tools will do a damn thing without a human guiding the job.

TerraChat was fun to write, and I used a lot of AI to make it, but it was my idea, my algorithms, my design. It just saved several trips to StackOverflow. The icon images were done by an actual artist and the artist released them for any and all uses. Terra chatting on a laptop was done by Dall-E.

No artist was going to draw that for me today. Though if I were going to make this a commercial product for some reason, I’d probably commission something. For a personal project that nobody but me ever uses, I think I’m in the clear here.

Me, though — I’ll be dancing the Ultros Boogie.

2 thoughts on “How I used AI to write a Final Fantasy VI chatbot”

  1. Well, obviously I can take as much of this stuff as you want to give us. Absolutely fascinating. Also, I am 100% with you on the implications of AI as we currently understand it. This is no more going to stop humans using and making a living from their creativity than the printing press, the industrial revolution or television, just to name three things that were going to do that and didn’t. At the outside, it might mean that different humans or different kinds of humans started using and making a living from their creativity than the ones doing it now but that’s an eternal process anyway.

    Where I think things could become problematic is if and when we reach the point where Artificial Intelligence is genuinely not discernably different from organic inteligence. At that point the ability to produce human-level creative output might be on parity but the speed at which it could be done would be almost immeasurably faster than a human could manage and potentially the quantity produced could exceed anything the entire human population could meaningfully consume. You’d have the usual issues of an over-saturated market with value being driven to near zero.

    On whether or not AI can achieve self-awareness or something that mimics self-awareness so closely it can’t be distinguished from it by humans, my gut feeling is that it’ll either happen very soon (this century) or never. It’ll either turn out to be impossible or we’re clsoing in on it right now. If the latter, I still doubt it’ll happen in my lifetime, but I’m going to be 64 in a couple of months so that’s not saying much.

    If we get quantum computing sorted out, though, we may get true AI whether we want it or not.

    • That point where artificial intelligence is equivalent to or better than human intelligence — it’s that whole question of what are humans for in a post-scarcity age? Science fiction has a million different answers for that.

      I’m kinda in love with the idea that when people aren’t wasting their lives doing the boring grunt work, they can spend more time on the actual creative work. Less drudgery, more creativity. And I hope I do see this in my lifetime (and yours!)

      Until AI can figure out how to run without being plugged in, I think we’re safe from the AI overlords.

Comments are closed.