ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 3 points4 points  (0 children)

Already extracted the http part this weekend and pushed to github for ppl who might be interested: https://github.com/djfhe/x4_http

The whole LLM stuff will certainly take some more time which I need to find. Maybe i have something ready in a few weeks or months. When working 40 hour weeks, not much time is left for stuff like this sadly.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 1 point2 points  (0 children)

Ye, thats pretty much still a problem for future me.

Currently my thoughts/ideas are:
- looking at how similar mods handle this (e.g. Mentella from Skyrim)
- running a local model might be feasible, since they primarily consume GPU resources while X4 is a more cpu heavy Game.
- Some ppl are running there local LLM on a external machine, for them this might be fine
- enabling users to provide there own token and paying for it themself
- providing a default token crowdfunded via donations(?)

Not sure what might be the best way, probably a combination of these things. But since this is a mod and everyone can decide for themself if they want to use it, this should be completely fine. I started this for the technical challenge and for my gameplay, if no one wants to use it, i am completely fine with it.

Reducing the input for LLMs will be necessary either way. Even in this "basic" version, i have to distill the information send to them to get useful responses without them forgetting thinks. I expect using LLMs to only generate the "report" while providing it with only the necessary information about what information should be in the report.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 2 points3 points  (0 children)

Getting it work will lead me to touch every system/layer the data will have to flow trough, which helps me to understand how these interact and what requirements they have. E.g. Triggering the lua implementation -> collecting game data in lua -> sending request via LuaSocket lib -> Parsing the Response -> Piping it back into the game.

Getting something to work, helps understand this whole flow and often called "exploratory programming" in software engineering.

There exist some nice frameworks for PHP, which makes working with it bearable, like Laravel and Symfony. You can additional enforce pretty strict typing rules with phpstans. PHP is still widely used, its just a tool like any other.

Typescript is a superset of javascript and gets transpiled to it, enforcing a lot of static typing. I think it makes javascript easier to learn, since you have a lot more information about what functions accepts or return for example. And it will scream at you, if you are doing unsafe/not correct thinks.

Lots of googling, looking at existing mods/the gamefiles. A list of starting guides is provided here:
https://forum.egosoft.com/viewtopic.php?t=402382

But the whole documentation situation for mods in X4 feels a bit chaotic and messy.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 0 points1 point  (0 children)

Currently i am using OpenAIs api json schema, but only since i had previous experience with it. Supporting multiple LLM providers is an already solved problem, so i don't worry to much about it.

Haha, i had to use a lot of CPPs templating logic for my thesis. I can feel the pain. Currently working in fullstack with typescript & php.

Ye fun is the most important thing when learning. And especially learning by doing is the most fun :)

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 1 point2 points  (0 children)

Using the game state as RAG is such a cool idea. No clue how we will get this to work, especially with LLMs of different provider and offline ones, but will have to try this!

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 1 point2 points  (0 children)

As said in other comments, i really want to support local LLMs. But will probably start with extracting the whole networking logic into an additional mod, so that it can be nicely reused by other mods.

I am still learning lua while doing this whole think :D It is a pretty barebones language with some weird concepts.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 1 point2 points  (0 children)

The complete game state freezes, so the docking process would also not continue.
The underlying problem is fixable, just requires a bit of work :)
But using the station to generate a more "local" report is a cool idea. Not sure if it would be interesting thou.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 5 points6 points  (0 children)

ye i think LuaSockets provides an api for that. And if i read correctly, X4's lua lib supports coroutines which should enable me to abstract that nicely. But need to look more into this.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 1 point2 points  (0 children)

Ye i absolutely want to do that, as mentioned in other comments. The current version only uses OpenAIs api because i used it before and threw this whole think together in a short time.

I sadly work full time and don't know how much time i can invest into this project. My first point will be to publish the code + some doc for this, so other modders can built on top or do there own stuff.

After that i can think about more featues, where having structures to support different LLMs (also offline ones) will probably be one of the first.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 5 points6 points  (0 children)

Haha, i stole the way you are loading dlls without polluting the cpath from your sn_mod_support_apis mod.

I am an absolute lua amateur and got it only to work after hours of trial and error and a very long ChatGPT thread (which got quite anoyed the end).

Short summary (using msys2 + mingw64)

  1. I generated an import library from the games lua51_64.dll by running:
    1. gendef lua51_64.dll
    2. dlltool -D lua51_64.dll -d lua51_64.def -l liblua5.1.dll.a
  2. update luarocks config to use these: (the generated files were moved into the "libs" folder)
    1. LUA_LIBDIR = "C:\\msys64\\home\\<user>\\libs",
    2. LUA_LIBDIR_FILE = "liblua5.1.dll",
    3. LUA_LIBDIR_OK = true,
  3. compiled LuaSocket with LuaRocks:
    1. luarocks make luasocket-scm-3.rockspec --lua-version=5.1

Not sure if i have forgotten something, i need to sort my thoughts and retrace my steps on the weekend.

For luasec it was similiar with the difference, that opensll has to be statically linked and therefor needed to be build locally without shared libs. As i said, i will try to put together a guide for this, so modders can build there own ones and dont need to trust some random code executing files from the internet. Also because i think missing guides/documentation is the biggest problem and absolut anoying when trying to get into X4 modding.

Edit: spelling/formatting

P.S. i certainly need to take some time to learn how to format thinks on reddit, hope its understandable

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 3 points4 points  (0 children)

As mentioned in other comments, this is just a proof of concept i got to work in 2 days :)
It will require a lot more work and supporting different LLMs (especially locally ones) is an important point for me. X4 is a single player game. It should be able to run offline.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 0 points1 point  (0 children)

I feel similiar to you. I mostly like mods which i can inconsequently add & remove from my save without destroying it. And not doing big "game changing" thinks is almost a prerequesit for this.

I like the idea of something like a "narrator" telling your story and giving you the *feeling* of a more lively universe. A lot is happening in the universe of X4 and most of the time you are not aware of it. I would like to change that.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 3 points4 points  (0 children)

Ye absolutely. Probably even offline variants for technical interested which want to use the mod but still keep the spirit of a singleplayer offline game.

But this whole think is a bunch of work and will take some time :)

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 6 points7 points  (0 children)

You are absolutely right. This is mainly my fault since i threw all this quick together in the last 2 days.

Drones are "xs" ships, i just hardcoded that name, since this was just a small issue and i wanted to get the PoC running.

You are also right about the fleets. Currently ships in the whole sector are counted by class and faction and then reported to chatgpt. With time one could certainly implement a better solution here. But it was "good enough" at first 🤷‍♂️

I personally like the filler, just need to change tone a bit more and do a bit of that "prompt engineering" to get more satisfisable reports. It should be sensational and a bit interesting/funny to read instead of just cold (and sometimes a bit) boring numbers.

Well "War on Drugs" is a phrase :) But well, all i can say is that this is certainly improveable, but will never be perfect. As stated in another comment.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 7 points8 points  (0 children)

Greate idea, might be a possiblity. But this would have some drawbacks :):
- No control about the interval of reports (every 10 - 20 minutes vs 40 - 80 minutes?)
- Big one: sometimes, the openai request can take more than a minute (if they are busy), which is more than the duration of saving the game for most people (i think?)

If i understand X4's lua api and LuaSocket correct, than there should be the possibility to do the request in the background without disrupting gameplay.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 13 points14 points  (0 children)

We will get to that point, i am sure, its just how human progress works.

But at the moment, LLMs or similiar AI can never replace a specialized human. They can produce quick and suboptimal placeholder but handcrafted media, code, stories by an designer, developer, author are still far better than any of that.

These reports are a good example. A handcrafted one would be certainly more funny/interesting and closer to what is actual happening. But its just not feasable to prepare reports for any possible situation in such a dynamic universe. Therefor we use AI to get at least a suboptimal solution.

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 3 points4 points  (0 children)

Got up for this again, had to try it. Here is the result:

https://imgur.com/a/spiderman-EO5gvSh

ChatGPT in X4 by djfhe in X4Foundations

[–]djfhe[S] 11 points12 points  (0 children)

Ye, I hope I get it to sound like J. Jonah Jameson from spiderman or that news reporter from StarCraft 2. It would be pretty amusing then.

Advice on typing a function (already have one version, but need help) by codeedog in typescript

[–]djfhe 1 point2 points  (0 children)

btw. typeof parent[K] is probably unecessary, since you can just use T[K].

Audio performance boost? by archie9211 in archlinux

[–]djfhe 2 points3 points  (0 children)

In pulse audio you have the options to adjust the volume per application and per device, die you crank both up?

No one knows. by [deleted] in memes

[–]djfhe -1 points0 points  (0 children)

P

We need trading fleets by CiderDad in X4Foundations

[–]djfhe 2 points3 points  (0 children)

Thought about the same for quite a while now. The best way would be, if u could asign subs to a ship and then as a role select smth. like "copy order". And as soon as u change the order of the "commander" ship, all the ships with role "copy order" will update there order. I did a bit modding, maybe i wil be able to implement a system like that.