Skip to content

Latest commit

 

History

History
118 lines (83 loc) · 3.11 KB

File metadata and controls

118 lines (83 loc) · 3.11 KB

Ollama Unity C# License Last commit Tag Top lang

🦙 SimpleOllamaUnity — Unity Extension

Listed in Ollama Community Integrations

Listed in ai-gamedev-tools

 

Communicate with local LLMs in Unity using Ollama — in just two lines of code.


🚀 Overview

SimpleOllamaUnity is an Unity extension that lets you communicate with Ollama in just two lines of code! It also works at runtime, so you can use it in your games!

You can easily configure the following for a quick start:

  • 🤖 Model
  • 📃 System prompt
  • 🌐 Ollama URI
  • 👀 Reasoning (optional — can be disabled)

📦 Installation

  1. Download the latest .unitypackage file from the Releases page.
  2. Drag & drop it into your Unity project window.
  3. Unity will automatically compile the editor extension.

No additional setup required.

The Plugins folder includes several .dll files required for integration.


💻 Usage

var ollama = new Ollama(new OllamaConfig(
    modelName: "qwen2.5:3b",
    systemPrompt: "Your answer mustn't be more than 10 words"
    ));

var response = await ollama.SendMessage(new OllamaRequest(
    userPrompt: "When was GitHub created?"
));

Yes, that’s it — only two lines of code! 🎉

 

To use a custom server URI:

var ollama = new Ollama(new OllamaConfig(
    modelName: "qwen2.5:3b",
    systemPrompt: "Your answer mustn't be more than 10 words",
    uri: "http://my-custom-server.local:3000/api/process"
)); 

 

You can also remove reasoning from models that can do it:

var response = await ollama.SendMessage(new OllamaRequest(
    userPrompt: "When was GitHub created?",
    clearThinking: true
));

This will remove all reasoning (from <think> to </think>).

   

🧪 Full Example:

using UnityEngine;
using HardCodeDev.SimpleOllamaUnity;

public class Test : MonoBehaviour
{
    private async void Start()
    {
        var ollama = new OllamaBase(new OllamaConfig(
            modelName: "qwen2.5:3b",
            systemPrompt: "Your answer mustn't be more than 10 words"
        ));

        var response = await ollama.SendMessage(new OllamaRequest(
            userPrompt: "When was GitHub created?"
        ));

        Debug.Log(response); // Prints LLM response to the console
    }
}

📄 License

This project is licensed under the MIT License.
See the LICENSE file for full terms.