RimWorld

RimWorld

Rimtalk
 This topic has been pinned, so it's probably important
Cyboran 7 Sep @ 2:52pm
An Attempted Guide for using a seperate machine on LAN for RimTalk
So as Juicy mentioned in the mod's comments, we were recommended to make use of a reverse proxy or a SSH Tunnel. Both should work, but this guide is specifically for using Caddy Server with reverse proxy to achieve my desired result.

That being, pointing RimTalk to a different machine on the same network to offload the resources used by LM Studio or other apps. Now, as you might know, Juicy informed us that the unsecure connection error given when we try to do that without any other setup is due to Rimworld/Unity's integrated coding for security.

Let's move onto the guide itself. As a reminder, this is only for Caddy Server with a reverse proxy. I'm not sure how to do the others, I did a lot of this with the help of ChatGPT but I also feel like it requires a bit of technical know how as well. Anyhoo, without further ado...

  1. Download Caddy Server - https://caddyserver.com/docs/install

    I believe it goes without saying but make sure you choose the appropriate file for your operating system and requirements. If I recall, I used windows amd 64 or something similar.

  2. Place this file in a folder somewhere you want. Keep the file path of where you place it on hand.

  3. Put this folder path into your Environment Variables under Path, you may need to google this. But my method is to type sysdm.cpl into the Start Menu, then go to the Advanced tab, click on Environmental Variables. A new window will open, all you need to worry about is Path. Click on Path, then Edit. This'll bring up a new window with a list of file paths in here. Put the path to where your caddy.exe is stored.

    This will now enable you to use caddy in command prompt or powershell.

  4. Create a new file in the same folder where your caddy.exe is located. This doesn't need any extensions so in my example, I named mine RimTalk and for reference, it is not RimTalk.txt or any other format, it doesn't have an extension.

  5. Open this file using notepad, then paste the following:

    :8080 { reverse_proxy 127.0.0.1:1234 { header_up Authorization "Bearer lm-studio" header_up Content-Type "application/json" } log { output file C:\CaddyServer\access.log format console } } https://[SERVER-IP]:8443 { reverse_proxy 127.0.0.1:1234 { header_up Authorization "Bearer lm-studio" header_up Content-Type "application/json" } tls internal log { output file C:\CaddyServer\access.log format console } }

    Now I'm not sure if ALL of that is required so if someone with more experience and knowledge wants to correct me, then please, by all means! This is just what worked for me.

    Replace the port numbers 8080 and 8443 in the above code block to your preferred ports that you want to connect to on the machine you're playing Rimworld on. The SERVER-IP is your machine that's hosting the local LLM models, so change that with the LAN IP of that machine.

    Once done, that part - https://[SERVER-IP]:8443 - is what you'll put into RimTalk for the Base URL. Follow Juicy's instructions for the rest to do with RimTalk.

  6. Once you're done the above, it's time to get into command prompt and powershell.

    cd [FILE-PATH] .\caddy run --config RimTalk --adapter caddyfile

    These are the commands used to run the reverse proxy. Remember that [FILE-PATH] is where you put your caddy.exe and the config file (Mine is called RimTalk). You can run it now in powershell if you like. But we're not done yet, because we now have to deal with cert issues.

    %APPDATA%\Caddy\pki\authorities\local\root.crt

    Above is the file path for the root.crt used by Caddy, you'll want to grab it and bring it over to the Rimworld machine.

    You'll want to open an elevated powershell on the Rimworld machine (right-click on powershell and hit Run as Administrator) then enter the following commands:

    Import-Certificate -FilePath "C:\Users\[USER-NAME]\Downloads\root.crt" -CertStoreLocation Cert:\LocalMachine\Root Import-Certificate -FilePath "C:\Users\[USER-NAME]\Downloads\root.crt" -CertStoreLocation Cert:\CurrentUser\Root

    Replacing [USER-NAME] with your actual username. This is assuming you downloaded the earlier root.crt to the Downloads folder, if it is in a different folder, then please change the file-path accordingly.

    Whew. That was a lot of technical stuff we just did. Are we done now? Not quite... Because there's some settings that I did have to change in LM Studio as well. But this was the step where I was able to start seeing successful API requests by RimTalk and LM Studio responding to them with both on two seperate machines.

  7. So first things first. This assumes you're using LM Studio, I am not familar with the other methods but I hope what I have to say guides you in the appropriate direction.

    In LM Studio, ensure that you're in the Power User or Developer format (look at the bottom for something that says "User Power User Developer"), once you've made sure of that, on the left of the window, navigate to the red folder icon, it'll say "My Models" when you mouse over it.

    Go to your chosen model, then click on the cog icon to bring up its settings. Navigate to the Prompt tab. Once there, you'll see Prompt Template and below that Template (Jinja) and Manual. We want Template (Jinja) to be selected, it should already be selected by default. Replace the content in the box just below it with the following:

    {%- set nl = '\n' -%} {# Begin of text token if defined #} {%- if bos_token is defined and bos_token %}{{ bos_token }}{% endif %} {# Render every message exactly as sent by the client #} {%- for m in messages %} <|start_header_id|>{{ m.role | default("user") }}<|end_header_id|>{{ nl }} {%- if m.content is string -%} {{ m.content }}{{ nl }} {%- else -%} {# content can be a list of parts; concatenate text parts #} {{ m.content | selectattr("type","equalto","text") | map(attribute="text") | join("") }}{{ nl }} {%- endif -%} <|eot_id|> {%- endfor %} {# Signal LM to produce the assistant reply #} <|start_header_id|>assistant<|end_header_id|>{{ nl }}

    This ensures that it receives the proper format from RimTalk.

    We're almost done!

  8. Now we can head to the green command prompt button on the left. If you haven't already, ensure that the settings button by the status has Enable CORS turned on. This is another thing I'm not entirely sure if it's needed but I didn't change it once it worked. Again, if anyone with more knowledge and experience than I has any feedback to give, please do so!

    You can now load your model here and click the status to start the local server. On the right side of the window, navigate to Inference, scroll down to Structured Output, enable it and paste the following:

    { "$schema": "http://json-schema.org/draft-07/schema#", "title": "RimTalkDialogue", "type": "array", "minItems": 1, "items": { "type": "object", "required": [ "name", "text" ], "properties": { "name": { "type": "string", "minLength": 1, "maxLength": 64 }, "text": { "type": "string", "minLength": 1, "maxLength": 180 } } } }

    This ensures that LM Studio sends the proper format to RimTalk so it can read it.

... And that's it! Hopefully by this point, you should be hosting your local LLM with LM Studio on your seperate machine, and connecting to it via RimTalk on your main machine.

As mentioned earlier, if anyone with more knowledge, experience and understanding wants to give feedback and improvements, please do let me know in the comments here!

Thank you for taking the time to read this and I do hope it helps you enjoy the immersiveness of your colony!
Last edited by Cyboran; 7 Sep @ 2:54pm
< >
Showing 1-1 of 1 comments
Juicy  [developer] 7 Sep @ 3:34pm 
Thanks for the detailed guide! Pinned for visibility.
< >
Showing 1-1 of 1 comments
Per page: 1530 50