[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10761":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":43,"readmeContent":44,"aiSummary":45,"trendingCount":16,"starSnapshotCount":16,"syncStatus":46,"lastSyncTime":47,"discoverSource":48},10761,"LLMUnity","undreamai\u002FLLMUnity","undreamai","Create characters in Unity with LLMs!","https:\u002F\u002Fundream.ai",null,"C#",1637,183,24,23,0,6,27,4,60.49,"Apache License 2.0",false,"main",true,[26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],"ai","character","chat","chatbot","conversational-ai","dialogue","game-development","gamedev","generative-ai","llama","llama-cpp","llm","npc","rag","unity","unity2d","unity3d","2026-06-12 04:00:52","\n\u003Cp align=\"center\">\n\u003Cpicture>\n  \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\".github\u002Flogo_white.png\">\n  \u003Csource media=\"(prefers-color-scheme: light)\" srcset=\".github\u002Flogo.png\">\n  \u003Cimg src=\".github\u002Flogo.png\" height=\"150\"\u002F>\n\u003C\u002Fpicture>\n\u003C\u002Fp>\n\n\u003Ch3 align=\"center\">Create characters in Unity with LLMs!\u003C\u002Fh3>\n\n[![License: Apache](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-Apache_2.0-yellow.svg)](https:\u002F\u002Fopensource.org\u002Flicense\u002Fapache-2-0)\n\u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002FRwXKQb6zdv\">\u003Cimg src=\"https:\u002F\u002Fdiscordapp.com\u002Fapi\u002Fguilds\u002F1194779009284841552\u002Fwidget.png?style=shield\"\u002F>\u003C\u002Fa>\n[![Reddit](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FReddit-%23FF4500.svg?style=flat&logo=Reddit&logoColor=white)](https:\u002F\u002Fwww.reddit.com\u002Fuser\u002FUndreamAI)\n[![LinkedIn](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLinkedIn-blue?style=flat&logo=linkedin&labelColor=blue)](https:\u002F\u002Fwww.linkedin.com\u002Fcompany\u002Fundreamai)\n[![Asset Store](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FAsset%20Store-black.svg?style=flat&logo=unity)](https:\u002F\u002Fassetstore.unity.com\u002Fpackages\u002Fslug\u002F273604)\n[![GitHub Repo stars](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fundreamai\u002FLLMUnity?style=flat&logo=github&color=f5f5f5)](https:\u002F\u002Fgithub.com\u002Fundreamai\u002FLLMUnity)\n[![Documentation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDocs-white.svg?logo=data:image\u002Fpng;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwEAYAAAAHkiXEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+\u002FAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAATqSURBVHic7ZtbiE1RGMc349K4M5EwklwjzUhJCMmTJPJAYjQXJJcH8+Blkry4lPJA8aAoJbekDLmUS6E8SHJL5AW5JPf77eHv93C22Wfttc\u002Fee+0zc\u002F4vv+bMXvusvfZa3\u002Fq+b33H80oqqaSSSmqrKnPdgXjUvbvYq5f4+7f486eb\u002FrRajRsn7t4tPngg\u002Fvol\u002Fvkj\u002FvghXr0q7tghzpyZ\u002F\u002F79+on79omXLombNondukXrd9GoSxdx8mSxqUm8eVNkgAvl0aPioEFip07i6dP52z15Ig4fbvVY2VVFhbhokXjrlogJiWvAg\u002FjwoXjqVO73+leUny9eiFVV5mfMlLDRBw+KX76ISQ+0LZ8\u002FF00v4uJFsWPHFh83O+rdWzx3TnQ9wCZ+\u002FSqyl5iux1RmTu3aiYcPi64H1pasALypoOv4\u002F8SJXraEbXc9kLbECxo2TKyuFj9\u002Fzt9u+XIvG8LWv3wpuh5QW86f3\u002FJznT+fv93s2S23C1Z72wbhtH692LdvMvdPSgzkhAkiJhT16ZO\u002FPRPOmcr+Rda4aa5nclTeuZP7PDgRpr1g40bPrQYOFF0PYKHEC+raVVy8OFy7R49EArvURU4mrUAqaTY0iB8\u002F2rXD+XCm5mbR9QAWylevorV7\u002FVpkL0ld06eLpkiyWPj9u93179+LpFZwZ1PXtGnitWui64GMStPmG7SH1NSIJBNHjvTSFZvRvHlise0N9JcBtW1\u002F44Y4dqx45IjnU0JxAGLpklPx+9VZFwPp\u002F9v\u002FeZDGjxcZh7dv4+mXtch+up7Rca+MsJvxiRNi6nvBhg25HWprZMaPGeOlqxEjxGKz+XGRTAAmyJnq6sR370TXA2NLW+8HNjZ62dLOnaLrAQ1r2zmqPH482n0mTfJCKmEvCJHUooNZE\u002F369Elct06kqiKsONRfulTEFDsX8QDlIa5nup9374pE8IiZHPY+ly+LZE\u002F37\u002FcM6mC6IB6Vl4urV6fzfUG6d0\u002Fcsyf37wsXRFInaM4ckTjGdPg+apTYs6dI3RIWwH\u002F\u002F1DV1qkiuxNY2FzrTd+2y6y8z2HQU6efZs+KBAyJZ4v+V0h6ArlwROaQP0uPH4ooV4sqV8Xz\u002F4MF211M2wwoOq1mzRAq5Pnywa5+4KDHE9mI7ly0TO3fOvZ6\u002FeZCoKwB32HS0SMFV1DNtImBKHYstBROoQ4fEQk2RaS+qrxejmj5M7NatIhWARS82xUJfAKahzFcdPnq0GLYgy7Rnbd8e6rGKRyzpuNzPBQty709RcNSZf\u002FKkuHCh2GpMDyKbGNcLYE+YMkVks336NFx7XhTZ3szXiBaqtWvFuAOxM2dEZiyH8UErgc8JLNun7E0aFffSI7RP6owZmz9kSO73HjsmXr8ukppYsybSYyQvBp5QfOjQ3M9tRR496pGgLf1JtLlzRZJzlFzGp4SWDnUxFCrdvy+uWiWa3DJe3N69oj8uSEq8CER88uaNOGBAOv2ILGY69TBBJoM8O0t72zaRoztXBzlLlrT8XARW\u002FIQq82JTMv3mKmv0\u002F9CC4mJMYPwrMSETxAyurRUxQVmXP1fEid7mzeK3b+n2Jzb16CFu2SIWmtNJiriVxANsyq0uoCJfTk4G9y4t24\u002FbSQ0rTkP6gVTG3mz\u002F\u002FuKMGSK\u002FucId5Xe9lZUi5eMMLGUgz56J5Hxu3xZ50Xg3RMIltVn9BRja26PYsBHgAAAAAElFTkSuQmCC)](https:\u002F\u002Fundream.ai\u002FLLMUnity)\n\nLLM for Unity enables seamless integration of Large Language Models (LLMs) within the Unity engine.\u003Cbr>\nIt allows to create intelligent AI characters that players can interact with for an immersive experience.\u003Cbr>\nThe package includes a Retrieval-Augmented Generation (RAG) system for semantic search across your data, which can be used to enhance the character's knowledge.\u003Cbr>\n\nThe LLM backend, [LlamaLib](https:\u002F\u002Fgithub.com\u002Fundreamai\u002FLlamaLib), is built on top of the awesome [llama.cpp](https:\u002F\u002Fgithub.com\u002Fggerganov\u002Fllama.cpp) library and  provided as a standalone C++\u002FC# library.\n\n\u003Csub>\n\u003Ca href=\"#at-a-glance\" style=\"color: black\">At a glance\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#how-to-help\" style=color: black>How to help\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#games--projects-using-llm-for-unity\" style=color: black>Games \u002F Projects using LLM for Unity\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#setup\" style=color: black>Setup\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#quick-start\" style=color: black>Quick start\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#advanced-usage\" style=color: black>Advanced usage\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#semantic-search-with-a-rag-system\" style=color: black>RAG\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#llm-model-management\" style=color: black>LLM model management\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#examples\" style=color: black>Examples\u003C\u002Fa>&nbsp;&nbsp;•&nbsp;\n\u003Ca href=\"#license\" style=color: black>License\u003C\u002Fa>\n\u003C\u002Fsub>\n\n## At a glance\n- 💻 Runs anywhere: PC, mobile or VR!\n- ⚡ Blazing fast inference on CPU and GPU (Nvidia, AMD, Apple Metal)\n- 🏠 Runs locally without internet access. No data ever leave your game!\n- 📡 Supports remote server setup\n- 🤗 Supports all major LLM models\n- 🔍 Advanced RAG System (ANN search)\n- 🔧 Easy to setup, call with a single line of code\n- 💰 Free to use for both personal and commercial purposes\n\n🧪 Tested on Unity: 2021 LTS, 2022 LTS, 2023, Unity 6\u003Cbr>\n🚦 [Upcoming Releases](https:\u002F\u002Fgithub.com\u002Forgs\u002Fundreamai\u002Fprojects\u002F2\u002Fviews\u002F10)\n\n\n### Business inquiries\nFor business inquiries you can reach out at hello@undream.ai.\n\n## How to help\n- [⭐ Star](https:\u002F\u002Fgithub.com\u002Fundreamai\u002FLLMUnity) the repo, leave a [review](https:\u002F\u002Fassetstore.unity.com\u002Fpackages\u002Fslug\u002F273604) and spread the word about the project!\n- Join us at [Discord](https:\u002F\u002Fdiscord.gg\u002FRwXKQb6zdv) and say hi.\n- [Contribute](CONTRIBUTING.md) by submitting feature requests, bugs or even your own PR.\n- [![](https:\u002F\u002Fimg.shields.io\u002Fstatic\u002Fv1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https:\u002F\u002Fgithub.com\u002Fsponsors\u002Famakropoulos) this work or buy me a [![Ko-fi](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FKo--fi-FF5E5B?logo=ko-fi&logoColor=white)](https:\u002F\u002Fko-fi.com\u002Famakropoulos) to allow even cooler features!\n\n\n## Games \u002F Projects using LLM for Unity\n- [Verbal Verdict](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F2778780\u002FVerbal_Verdict\u002F)\n- [I, Chatbot: AISYLUM](https:\u002F\u002Fstore.epicgames.com\u002Fde\u002Fp\u002Fi-chatbot-aisylum-83b2b5)\n- [Nameless Souls of the Void](https:\u002F\u002Funicorninteractive.itch.io\u002Fnameless-souls-of-the-void)\n- [Murder in Aisle 4](https:\u002F\u002Froadedlich.itch.io\u002Fmurder-in-aisle-4)\n- [Finicky Food Delivery AI](https:\u002F\u002Fhelixngc7293.itch.io\u002Ffinicky-food-delivery-ai)\n- [AI Emotional Girlfriend](https:\u002F\u002Fwhynames.itch.io\u002Faiemotionalgirlfriend)\n- [Case Closed](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F2532160\u002FCase_Closed)\n- [MaiMai AI Agent System](https:\u002F\u002Fgithub.com\u002FIhateCreatingUserNames2\u002FMaiMai)\n- [Claria Chat](https:\u002F\u002Fplay.google.com\u002Fstore\u002Fapps\u002Fdetails?id=com.ProLink.ClariaChat)\n- [Endless Casual Drive](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F2928500\u002FEndless_Casual_Drive\u002F)\n- [Dating App Simulator](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F3415680\u002FDating_App_Simulator\u002F)\n- [Virtual Reality Mock Interview](https:\u002F\u002Fvrmi.vercel.app\u002F)\n- [Velesio AI server](https:\u002F\u002Fgithub.com\u002FVelesio\u002FVelesio-AIServer)\n- [Dungeon Chat](https:\u002F\u002Fwww.meta.com\u002Fexperiences\u002Fdungeonchat\u002F8527310950709276\u002F)\n- [Tomonaka Desk](https:\u002F\u002Fjoycatdev.itch.io\u002Ftomonaka-desk)\n- [Digital Humans](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F3089280\u002FDigital_Humans\u002F)\n- [CakeMix](https:\u002F\u002Fripenedpeach.itch.io\u002Fcakemix)\n- [HeyWaifu](https:\u002F\u002Fsquirclegames.itch.io\u002Fhey-waifu-ai)\n- [Love and Lie](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F3886140\u002FLove_and_Lie\u002F)\n- [Psycho Simulator](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F1244620\u002FPsycho_Simulator\u002F)\n- [False Flame](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F4427250\u002FFalse_Flame\u002F)\n- [CielChan: Anime Desktop AI Companion](https:\u002F\u002Fstore.steampowered.com\u002Fapp\u002F4529510\u002FCielChan_Anime_Desktop_AI_Companion\u002F)\n\nContact hello@undream.ai to add your project!\n\n## Setup\n_Method 1: Install using the asset store_\n- Open the [LLM for Unity](https:\u002F\u002Fassetstore.unity.com\u002Fpackages\u002Fslug\u002F273604) asset page and click `Add to My Assets`\n- Open the Package Manager in Unity: `Window > Package Manager`\n- Select the `Packages: My Assets` option from the drop-down\n- Select the `LLM for Unity` package, click `Download` and then `Import`\n\n_Method 2: Install using the GitHub repo:_\n- Open the Package Manager in Unity: `Window > Package Manager`\n- Click the `+` button and select `Add package from git URL`\n- Use the repository URL `https:\u002F\u002Fgithub.com\u002Fundreamai\u002FLLMUnity.git` and click `Add`\n\n## Quick start\n\u003Cimg height=\"300\" src=\".github\u002Fcharacter.png\"\u002F>\n\n#### 1. Setup the LLM\n\nFirst you will setup the LLM for your game:\n- Create an empty GameObject.\u003Cbr>In the GameObject Inspector click `Add Component` and select the `LLM` script.\n- Download one of the default models with the `Download Model` button (~GBs).\u003Cbr>Or load your own .gguf model with the `Load model` button (see [LLM model management](#llm-model-management)).\n\n#### 2. Create an AI Character\nThen you can setup each of your characters as follows:\n- Create an empty GameObject for the character.\u003Cbr>In the GameObject Inspector click `Add Component` and select the `LLMAgent` script.\n- Define the role of your AI in the `System Prompt`.\n- (Optional) Select the LLM constructed above in the `LLM` field if you have more than one LLM GameObjects.\n\n#### 3. Use in Your Script\nIn your script you can then use it as follows:\n``` c#\nusing LLMUnity;\n\npublic class MyScript {\n  public LLMAgent llmAgent;\n  \n  void HandleReply(string replySoFar){\n    \u002F\u002F do something with the reply from the model as it is being produced\n    Debug.Log(replySoFar);\n  }\n  \n  void Game(){\n    \u002F\u002F handle the response as it is being produced\n    ...\n    _ = llmAgent.Chat(\"Hello bot!\", HandleReply);\n    ...\n  }\n  \n  async void GameAsync(){\n    \u002F\u002F or handle the entire response in one go\n    ...\n    string reply = await llmAgent.Chat(\"Hello bot!\");\n    Debug.Log(reply);\n    ...\n  }\n}\n```\nYou can also specify a function to call when the model reply has been completed:\n``` c#\n  void ReplyCompleted(){\n    \u002F\u002F do something when the reply from the model is complete\n    Debug.Log(\"The AI has finished replying\");\n  }\n  \n  void Game(){\n    \u002F\u002F your game function\n    ...\n    _ = llmAgent.Chat(\"Hello bot!\", HandleReply, ReplyCompleted);\n    ...\n  }\n```\n\nTo stop the chat without waiting for its completion you can use:\n``` c#\n    llmAgent.CancelRequests();\n```\n\n- Finally, in the Inspector of the GameObject of your script, select the LLMAgent GameObject created above as the llmAgent property.\n\nThat's it! Your AI character is ready to chat! ✨\n\n## Advanced usage\n\n\u003Cdetails>\n\u003Csummary>Build a mobile app\u003C\u002Fsummary>\n\nFor mobile apps you can use models with up to 1-2 billion parameters (\"Tiny models\" in the LLM model manager).\u003Cbr>\nLarger models will typically not work due to the limited mobile hardware.\n\n**iOS**\niOS can be built with the default player settings.\n\n**Android**\nOn Android you need to specify the `IL2CPP` scripting backend and the `ARM64` as the target architecture in the player settings.\u003Cbr>\nThese settings can be accessed from the `Edit > Project Settings` menu within the `Player > Other Settings` section.\u003Cbr>\n\u003Cimg width=\"400\" src=\".github\u002Fandroid.png\">\n\nSince mobile app sizes are typically small, you can download the LLM model the first time the app launches.\nThis functionality is enabled with the `Download on Build` option.\nIn your project you can wait until the model download is complete with:\n``` c#\nawait LLM.WaitUntilModelSetup();\n```\nYou can also receive calls the download progress during the model download:\n``` c#\nawait LLM.WaitUntilModelSetup(SetProgress);\n\nvoid SetProgress(float progress){\n  string progressPercent = ((int)(progress * 100)).ToString() + \"%\";\n  Debug.Log($\"Download progress: {progressPercent}\");\n}\n```\nThis is useful to present e.g. a progress bar.\nThe [MobileDemo](Samples~\u002FMobileDemo) demonstrates an example application for Android \u002F iOS.\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Restrict the output of the LLM \u002F Function calling \u002F Grammar\u003C\u002Fsummary>\n\nTo restrict the output of the LLM you can use a grammar, read more [here](https:\u002F\u002Fgithub.com\u002Fggerganov\u002Fllama.cpp\u002Ftree\u002Fmaster\u002Fgrammars).\u003Cbr>\nThe grammar can edited directly in the `Grammar` field of the LLMAgent or saved in a gbnf \u002F json schema file and loaded with the `Load Grammar` button (Advanced options).\u003Cbr>\nFor instance to receive replies in json format you can use the [json.gbnf](https:\u002F\u002Fgithub.com\u002Fggerganov\u002Fllama.cpp\u002Fblob\u002Fb4218\u002Fgrammars\u002Fjson.gbnf) grammar.\u003Cbr>\n\nAlternatively you can set the grammar directly in your script:\n``` c#\nllmAgent.grammar = \"your grammar here\";\n```\n\nFor function calling you can define similarly a grammar that allows only the function names as output, and then call the respective function.\u003Cbr>\nYou can look into the [FunctionCalling](Samples~\u002FFunctionCalling) sample for an example implementation.\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Access \u002F Save \u002F Load your chat history\u003C\u002Fsummary>\nThe chat history of a `LLMAgent` is retained in the `chat` variable that is a list of `ChatMessage` objects.\u003Cbr>\nThe ChatMessage is a class that defines the `role` of the message and the `content`.\u003Cbr>\nThe list contains alternating messages with the player prompt and the AI reply.\u003Cbr>\nYou can modify the chat history and then set it to your LLMAgent GameObject:\n``` c#\nList\u003CChatMessage> newChat = new List\u003CChatMessage>();\n...\nllmAgent.chat = newChat;\n```\n\nTo add new messages you can do:\n``` c#\n_ = llmAgent.AddUserMessage(\"your user message\");\n_ = llmAgent.AddAssistantMessage(\"your assistant reply\");\n```\n\nTo automatically save \u002F load your chat history, you can specify the `Save` parameter of the LLMAgent to the filename (or relative path) of your choice.\nThe chat history is saved in the [persistentDataPath folder of Unity](https:\u002F\u002Fdocs.unity3d.com\u002FScriptReference\u002FApplication-persistentDataPath.html) as a json object.\n\nTo manually save your chat history, you can use:\n``` c#\n    _ = llmAgent.SaveHistory();\n```\nand to load the history:\n``` c#\n    _ = llmAgent.Loadistory();\n```\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Process the prompt at the beginning of your app for faster initial processing time\u003C\u002Fsummary>\n\n``` c#\n  void WarmupCompleted(){\n    \u002F\u002F do something when the warmup is complete\n    Debug.Log(\"The AI is nice and ready\");\n  }\n\n  void Game(){\n    \u002F\u002F your game function\n    ...\n    _ = llmAgent.Warmup(WarmupCompleted);\n    ...\n  }\n```\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Decide whether or not to add the message to the chat\u002Fprompt history\u003C\u002Fsummary>\n\n  The last argument of the `Chat` function is a boolean that specifies whether to add the message to the history (default: true):\n``` c#\n  void Game(){\n    \u002F\u002F your game function\n    ...\n    string message = \"Hello bot!\";\n    _ = llmAgent.Chat(message, HandleReply, ReplyCompleted, false);\n    ...\n  }\n```\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Use pure text completion\u003C\u002Fsummary>\n\n``` c#\n  void Game(){\n    \u002F\u002F your game function\n    ...\n    string message = \"The cat is away\";\n    _ = llmAgent.Completion(message, HandleReply, ReplyCompleted);\n    ...\n  }\n```\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Add a LLM \u002F LLMAgent component programmatically\u003C\u002Fsummary>\n\n``` c#\nusing UnityEngine;\nusing LLMUnity;\n\npublic class MyScript : MonoBehaviour\n{\n    LLM llm;\n    LLMAgent llmAgent;\n\n    async void Start()\n    {\n        \u002F\u002F disable gameObject so that theAwake is not called immediately\n        gameObject.SetActive(false);\n\n        \u002F\u002F Add an LLM object\n        llm = gameObject.AddComponent\u003CLLM>();\n        \u002F\u002F set the model using the filename of the model.\n        \u002F\u002F The model needs to be added to the LLM model manager (see LLM model management) by loading or downloading it.\n        \u002F\u002F Otherwise the model file can be copied directly inside the StreamingAssets folder.\n        llm.model = \"Qwen3-4B-Q4_K_M.gguf\";\n        \u002F\u002F optional: you can also set loras in a similar fashion and set their weights (if needed)\n        llm.AddLora(\"my-lora.gguf\");\n        llm.AddLora(\"my-lora-2.gguf\", 0.5f);\n        \u002F\u002F optional: set number of threads\n        llm.numThreads = -1;\n        \u002F\u002F optional: enable GPU by setting the number of model layers to offload to it\n        llm.numGPULayers = 10;\n\n        \u002F\u002F Add an LLMAgent object\n        llmAgent = gameObject.AddComponent\u003CLLMAgent>();\n        \u002F\u002F set the LLM object that handles the model\n        llmAgent.llm = llm;\n        \u002F\u002F set the character prompt\n        llmAgent.systemPrompt = \"A chat between a curious human and an artificial intelligence assistant.\";\n        \u002F\u002F set the AI and player name\n        llmAgent.assistantRole = \"AI\";\n        llmAgent.userRole = \"Human\";\n        \u002F\u002F optional: set a save path\n        llmAgent.save = \"AICharacter1.json\";\n        \u002F\u002F optional: set a grammar\n        llmAgent.grammar = \"your grammar here\";\n\n        \u002F\u002F re-enable gameObject\n        gameObject.SetActive(true);\n    }\n}\n```\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Use a remote server\u003C\u002Fsummary>\n\nYou can use a remote server to carry out the processing and implement characters that interact with it.\n\n**Create the server**\u003Cbr>\nTo create the server:\n- Create a project with a GameObject using the `LLM` script as described above\n- Enable the `Remote` option of the `LLM` and optionally configure the server port and API key\n- Enable 'Allow Downloads Over HTTP' in the project settings\n- Build and run to start the server\n\nAlternatively you can use a server binary for easier deployment:\n- Run the above scene from the Editor and copy the command from the Debug messages (starting with \"Deploy server command:\")\n- Download and extract the [LlamaLib binaries](https:\u002F\u002Fgithub.com\u002Fundreamai\u002FLlamaLib\u002Freleases\u002Fdownload\u002Fv2.0.0\u002FLlamaLib-v2.0.0.zip)\n- From command line change directory to the `servers` folder selected and start the server by running the command copied from above.\n\n**Create the characters**\u003Cbr>\nCreate a second project with the game characters using the `LLMAgent` script as described above.\nEnable the `Remote` option and configure the host with the IP address (starting with \"http:\u002F\u002F\") and port \u002F API key of the server.\n\n\u003C\u002Fdetails>\n\u003Cdetails>\n\u003Csummary>Compute embeddings using a LLM\u003C\u002Fsummary>\n\nThe `Embeddings` function can be used to obtain the emdeddings of a phrase:\n``` c#\n    List\u003Cfloat> embeddings = await llmAgent.Embeddings(\"hi, how are you?\");\n```\n\n\u003C\u002Fdetails>\n\nA \u003Cb>detailed documentation\u003C\u002Fb> on function level can be found here:\n\u003Ca href=\"https:\u002F\u002Fundream.ai\u002FLLMUnity\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDocumentation-white.svg?logo=data:image\u002Fpng;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwEAYAAAAHkiXEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+\u002FAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAATqSURBVHic7ZtbiE1RGMc349K4M5EwklwjzUhJCMmTJPJAYjQXJJcH8+Blkry4lPJA8aAoJbekDLmUS6E8SHJL5AW5JPf77eHv93C22Wfttc\u002Fee+0zc\u002F4vv+bMXvusvfZa3\u002Fq+b33H80oqqaSSSmqrKnPdgXjUvbvYq5f4+7f486eb\u002FrRajRsn7t4tPngg\u002Fvol\u002Fvkj\u002FvghXr0q7tghzpyZ\u002F\u002F79+on79omXLombNondukXrd9GoSxdx8mSxqUm8eVNkgAvl0aPioEFip07i6dP52z15Ig4fbvVY2VVFhbhokXjrlogJiWvAg\u002FjwoXjqVO73+leUny9eiFVV5mfMlLDRBw+KX76ISQ+0LZ8\u002FF00v4uJFsWPHFh83O+rdWzx3TnQ9wCZ+\u002FSqyl5iux1RmTu3aiYcPi64H1pasALypoOv4\u002F8SJXraEbXc9kLbECxo2TKyuFj9\u002Fzt9u+XIvG8LWv3wpuh5QW86f3\u002FJznT+fv93s2S23C1Z72wbhtH692LdvMvdPSgzkhAkiJhT16ZO\u002FPRPOmcr+Rda4aa5nclTeuZP7PDgRpr1g40bPrQYOFF0PYKHEC+raVVy8OFy7R49EArvURU4mrUAqaTY0iB8\u002F2rXD+XCm5mbR9QAWylevorV7\u002FVpkL0ld06eLpkiyWPj9u93179+LpFZwZ1PXtGnitWui64GMStPmG7SH1NSIJBNHjvTSFZvRvHlise0N9JcBtW1\u002F44Y4dqx45IjnU0JxAGLpklPx+9VZFwPp\u002F9v\u002FeZDGjxcZh7dv4+mXtch+up7Rca+MsJvxiRNi6nvBhg25HWprZMaPGeOlqxEjxGKz+XGRTAAmyJnq6sR370TXA2NLW+8HNjZ62dLOnaLrAQ1r2zmqPH482n0mTfJCKmEvCJHUooNZE\u002F369Elct06kqiKsONRfulTEFDsX8QDlIa5nup9374pE8IiZHPY+ly+LZE\u002F37\u002FcM6mC6IB6Vl4urV6fzfUG6d0\u002Fcsyf37wsXRFInaM4ckTjGdPg+apTYs6dI3RIWwH\u002F\u002F1DV1qkiuxNY2FzrTd+2y6y8z2HQU6efZs+KBAyJZ4v+V0h6ArlwROaQP0uPH4ooV4sqV8Xz\u002F4MF211M2wwoOq1mzRAq5Pnywa5+4KDHE9mI7ly0TO3fOvZ6\u002FeZCoKwB32HS0SMFV1DNtImBKHYstBROoQ4fEQk2RaS+qrxejmj5M7NatIhWARS82xUJfAKahzFcdPnq0GLYgy7Rnbd8e6rGKRyzpuNzPBQty709RcNSZf\u002FKkuHCh2GpMDyKbGNcLYE+YMkVks336NFx7XhTZ3szXiBaqtWvFuAOxM2dEZiyH8UErgc8JLNun7E0aFffSI7RP6owZmz9kSO73HjsmXr8ukppYsybSYyQvBp5QfOjQ3M9tRR496pGgLf1JtLlzRZJzlFzGp4SWDnUxFCrdvy+uWiWa3DJe3N69oj8uSEq8CER88uaNOGBAOv2ILGY69TBBJoM8O0t72zaRoztXBzlLlrT8XARW\u002FIQq82JTMv3mKmv0\u002F9CC4mJMYPwrMSETxAyurRUxQVmXP1fEid7mzeK3b+n2Jzb16CFu2SIWmtNJiriVxANsyq0uoCJfTk4G9y4t24\u002FbSQ0rTkP6gVTG3mz\u002F\u002FuKMGSK\u002FucId5Xe9lZUi5eMMLGUgz56J5Hxu3xZ50Xg3RMIltVn9BRja26PYsBHgAAAAAElFTkSuQmCC\"\u002F>\u003C\u002Fa>\n\n## Semantic search with a RAG system\nLLM for Unity implements a super-fast similarity search functionality with a Retrieval-Augmented Generation (RAG) system.\u003Cbr>\nIt is based on the LLM embeddings, and the Approximate Nearest Neighbors (ANN) search from the [usearch](https:\u002F\u002Fgithub.com\u002Funum-cloud\u002Fusearch) library.\u003Cbr>\nSemantic search works as follows.\n\n**Building the data** You provide text inputs (a phrase, paragraph, document) to add to the data.\u003Cbr>\nEach input is split into chunks (optional) and encoded into embeddings with a LLM.\n\n**Searching** You can then search for a query text input. \u003Cbr>\nThe input is again encoded and the most similar text inputs or chunks in the data are retrieved.\n\nTo use semantic serch:\n- create a GameObject for the LLM as described above. Download one of the provided RAG models or load your own (good options can be found at the [MTEB leaderboard](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fmteb\u002Fleaderboard)).\n- create an empty GameObject. In the GameObject Inspector click `Add Component` and select the `RAG` script.\n- In the Search Type dropdown of the RAG select your preferred search method. `SimpleSearch` is a simple brute-force search, while`DBSearch` is a fast ANN method that should be preferred in most cases.\n- In the Chunking Type dropdown of the RAG you can select a method for splitting the inputs into chunks. This is useful to have a more consistent meaning within each data part. Chunking methods for splitting according to tokens, words and sentences are provided.\n\nAlternatively, you can create the RAG from code (where llm is your LLM):\n``` c#\n  RAG rag = gameObject.AddComponent\u003CRAG>();\n  rag.Init(SearchMethods.DBSearch, ChunkingMethods.SentenceSplitter, llm);\n```\n\nIn your script you can then use it as follows :unicorn::\n``` c#\nusing LLMUnity;\n\npublic class MyScript : MonoBehaviour\n{\n  RAG rag;\n\n  async void Game(){\n    ...\n    string[] inputs = new string[]{\n      \"Hi! I'm a search system.\",\n      \"the weather is nice. I like it.\",\n      \"I'm a RAG system\"\n    };\n    \u002F\u002F add the inputs to the RAG\n    foreach (string input in inputs) await rag.Add(input);\n    \u002F\u002F get the 2 most similar inputs and their distance (dissimilarity) to the search query\n    (string[] results, float[] distances) = await rag.Search(\"hello!\", 2);\n    \u002F\u002F to get the most similar text parts (chunks), instead of full input, you can enable the returnChunks option\n    rag.ReturnChunks(true);\n    (results, distances) = await rag.Search(\"hello!\", 2);\n    ...\n  }\n}\n```\n\nYou can also add \u002F search text inputs for groups of data e.g. for a specific character or scene:\n``` c#\n    \u002F\u002F add the inputs to the RAG for a group of data e.g. an orc character\n    foreach (string input in inputs) await rag.Add(input, \"orc\");\n    \u002F\u002F get the 2 most similar inputs for the group of data e.g. the orc character\n    (string[] results, float[] distances) = await rag.Search(\"how do you feel?\", 2, \"orc\");\n...\n\nYou can save the RAG state (stored in the `Assets\u002FStreamingAssets` folder):\n``` c#\nrag.Save(\"rag.zip\");\n```\nand load it from disk:\n``` c#\nawait rag.Load(\"rag.zip\");\n```\n\nYou can use the RAG to feed relevant data to the LLM based on a user message:\n``` c#\n  string message = \"How is the weather?\";\n  (string[] similarPhrases, float[] distances) = await rag.Search(message, 3);\n\n  string prompt = \"Answer the user query based on the provided data.\\n\\n\";\n  prompt += $\"User query: {message}\\n\\n\";\n  prompt += $\"Data:\\n\";\n  foreach (string similarPhrase in similarPhrases) prompt += $\"\\n- {similarPhrase}\";\n\n  _ = llmAgent.Chat(prompt, HandleReply, ReplyCompleted);\n```\n\nThe `RAG` sample includes an example RAG implementation as well as an example RAG-LLM integration.\n\nThat's all :sparkles:!\n\n## LLM model management\nLLM for Unity includes a built-in model manager for easy model handling.\u003Cbr>\nThe model manager allows to load or download LLMs and can be found as part of the LLM GameObject:\u003Cbr>\n\u003Cimg width=\"360\" src=\".github\u002FLLM_manager.png\">\n\nYou can download models with the `Download model` button.\u003Cbr>\nLLM for Unity includes different state of the art models built-in for different model sizes, quantised with the Q4_K_M method.\u003Cbr>\nAlternative models can be downloaded from [HuggingFace](https:\u002F\u002Fhuggingface.co\u002Fmodels?library=gguf&sort=downloads) in .gguf format.\u003Cbr>\nYou can download a model locally and load it with the `Load model` button, or copy the URL in the `Download model > Custom URL` field to directly download it.\u003Cbr>\nIf a HuggingFace model does not provide a gguf file, it can be converted to gguf with this [online converter](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fggml-org\u002Fgguf-my-repo).\u003Cbr>\n\n\u003Cbr>\n\u003Cbr>\nModels added in the model manager are copied to the game during the building process.\u003Cbr>\nYou can omit a model by deselecting the \"Build\" checkbox.\u003Cbr>\nTo remove the model (but not delete it from disk) you can click the bin button.\u003Cbr>\nThe path and URL of models can be diplayed in the expanded view of the model manager with the `>>` button:\u003Cbr>\n\u003Cimg width=\"600\" src=\".github\u002FLLM_manager_expanded.png\">\n\nYou can create lighter builds by selecting the `Download on Build` option.\u003Cbr>\nThe models will be downloaded the first time the game starts instead of bundled in the build.\u003Cbr>\nIf you have loaded a model locally you need to set its URL through the expanded view, otherwise it will be copied in the build.\u003Cbr>\n\n❕ Before using any model make sure you **check their license** ❕\n\n## Examples\nThe [Samples~](Samples~) folder contains several examples of interaction 🤖:\n- [SimpleInteraction](Samples~\u002FSimpleInteraction): Simple interaction with an AI character\n- [MultipleCharacters](Samples~\u002FMultipleCharacters): Simple interaction using multiple AI characters\n- [FunctionCalling](Samples~\u002FFunctionCalling): Function calling sample with structured output from the LLM\n- [RAG](Samples~\u002FRAG): Semantic search using a Retrieval Augmented Generation (RAG) system. Includes example using a RAG to feed information to a LLM\n- [MobileDemo](Samples~\u002FMobileDemo): Example mobile app for Android \u002F iOS with an initial screen displaying the model download progress\n- [ChatBot](Samples~\u002FChatBot): Interaction between a player and a AI with a UI similar to a messaging app (see image below)\n- [KnowledgeBaseGame](Samples~\u002FKnowledgeBaseGame): Simple detective game using a knowledge base to provide information to the LLM based on [google\u002Fmysteryofthreebots](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmysteryofthreebots)\n  \n\u003Cimg width=\"400\" src=\".github\u002Fdemo.gif\">\n\nTo install a sample:\n- Open the Package Manager: `Window > Package Manager`\n- Select the `LLM for Unity` Package. From the `Samples` Tab, click `Import` next to the sample you want to install.\n\nThe samples can be run with the `Scene.unity` scene they contain inside their folder.\u003Cbr>\nIn the scene, select the `LLM` GameObject and specify the LLM of your choice (see [LLM model management](#llm-model-management)).\u003Cbr>\nSave the scene, run and enjoy!\n\n## License\nThe license of LLM for Unity is Apache 2.0 ([LICENSE.md](LICENSE.md)) and uses third-party software with MIT and Apache licenses.\nSome models included in the asset define their own license terms, please review them before using each model.\nThird-party licenses can be found in the ([Third Party Notices.md](\u003CThird Party Notices.md>)).\n","LLMUnity 是一个利用大型语言模型（LLMs）在 Unity 游戏引擎中创建角色的项目。它通过 C# 编程语言实现，支持生成具有对话能力的游戏角色或 NPC，能够进行自然流畅的对话交流，增强游戏互动性和沉浸感。该项目基于先进的生成式 AI 技术，如 LLaMA 和 LLaMA-CCP，为开发者提供了一种便捷的方式将智能对话系统集成到 2D 或 3D 游戏开发中。适用于需要提升游戏角色智能化水平的各种游戏场景，尤其是那些强调故事叙述和玩家交互体验的游戏。",2,"2026-06-11 03:30:03","top_topic"]