<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: StellarDev</title>
    <description>The latest articles on DEV Community by StellarDev (@one_shotonly_9983088d742).</description>
    <link>https://dev.to/one_shotonly_9983088d742</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4260047%2Fb0085b99-b29f-4fca-bd9f-68f04b658a12.png</url>
      <title>DEV Community: StellarDev</title>
      <link>https://dev.to/one_shotonly_9983088d742</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/one_shotonly_9983088d742"/>
    <language>en</language>
    <item>
      <title>Running a self-hosted AI for a Discord bot on a CPU-only VPS (and the thread trick that made it 70% faster)</title>
      <dc:creator>StellarDev</dc:creator>
      <pubDate>Mon, 23 Nov 2026 08:23:52 +0000</pubDate>
      <link>https://dev.to/one_shotonly_9983088d742/running-a-self-hosted-ai-for-a-discord-bot-on-a-cpu-only-vps-and-the-thread-trick-that-made-it-70-5ag5</link>
      <guid>https://dev.to/one_shotonly_9983088d742/running-a-self-hosted-ai-for-a-discord-bot-on-a-cpu-only-vps-and-the-thread-trick-that-made-it-70-5ag5</guid>
      <description>&lt;p&gt;I wanted my Discord bot, &lt;a href="https://stellarbot.xyz" rel="noopener noreferrer"&gt;Stellar&lt;/a&gt;, to answer questions with AI: a &lt;code&gt;/ask&lt;/code&gt; command, plus a first reply when someone opens a support ticket. I didn't want to pay per message or send people's questions to a third party. So the model runs on the same 6-core VPS as the bot. No GPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ollama&lt;/strong&gt; running &lt;strong&gt;Qwen 2.5 3B&lt;/strong&gt;, reachable only from the bot's Docker network, never from the internet.&lt;/li&gt;
&lt;li&gt;Capped at &lt;strong&gt;4 of the 6 cores&lt;/strong&gt; (systemd &lt;code&gt;CPUQuota=400%&lt;/code&gt;), so the bot itself stays fast.&lt;/li&gt;
&lt;li&gt;Answers &lt;strong&gt;stream into Discord&lt;/strong&gt; as they're written, editing one message every second. People see text within a couple of seconds even though a full answer takes 10–15 seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The thread trick
&lt;/h2&gt;

&lt;p&gt;Ollama starts one thread per core by default. With the CPU capped at 4 cores, 6 threads were fighting over 4 cores. Setting &lt;code&gt;num_thread&lt;/code&gt; to match the cap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;num_predict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_ctx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_thread&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;took generation from &lt;strong&gt;5.1 to 8.6 tokens a second&lt;/strong&gt;, without giving it any more CPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small models and other languages
&lt;/h2&gt;

&lt;p&gt;A 3B model answering Polish or Spanish directly gave vague or made-up answers, and its knowledge base (the bot's command list) is in English anyway. So questions go through three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The model names the language and translates the question to English.&lt;/li&gt;
&lt;li&gt;It answers in English, with the right facts from the command list.&lt;/li&gt;
&lt;li&gt;It translates the answer back.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In tickets, the English copy stays underneath so staff can read it. Polish answers went from useless to correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keeping it fair on one CPU
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One answer at a time, with a short queue.&lt;/li&gt;
&lt;li&gt;A 15-second cooldown per user and a daily cap per server.&lt;/li&gt;
&lt;li&gt;Nothing is stored: only the answer's length and how long it took are logged.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run a Discord server, Stellar is free: &lt;a href="https://stellarbot.xyz" rel="noopener noreferrer"&gt;https://stellarbot.xyz&lt;/a&gt;. Questions about the setup are welcome in the comments.&lt;/p&gt;

</description>
      <category>discord</category>
      <category>ai</category>
      <category>selfhosted</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
