{"id":23177291,"url":"https://github.com/haoming02/ollama-unity","last_synced_at":"2025-08-18T11:32:38.828Z","repository":{"id":238411209,"uuid":"796495197","full_name":"Haoming02/ollama-unity","owner":"Haoming02","description":"Ollama API bindings for Unity","archived":false,"fork":false,"pushed_at":"2024-06-20T06:16:55.000Z","size":60,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T18:14:16.094Z","etag":null,"topics":["ollama","ollama-api","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Haoming02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T03:54:52.000Z","updated_at":"2024-06-20T16:27:12.000Z","dependencies_parsed_at":"2024-05-10T04:21:59.341Z","dependency_job_id":"1f23a65c-0e12-4280-8fa9-32987d833ece","html_url":"https://github.com/Haoming02/ollama-unity","commit_stats":null,"previous_names":["haoming02/ollama-unity"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haoming02%2Follama-unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haoming02%2Follama-unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haoming02%2Follama-unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Haoming02%2Follama-unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Haoming02","download_url":"https://codeload.github.com/Haoming02/ollama-unity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230227316,"owners_count":18193289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ollama","ollama-api","unity"],"created_at":"2024-12-18T06:32:46.362Z","updated_at":"2025-08-18T11:32:38.819Z","avatar_url":"https://github.com/Haoming02.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\u003ch1 align=\"center\"\u003e\n\u003csub\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/151674099\" width=64 height=64\u003e\u003c/sub\u003e\n\u003csup\u003e for \u003c/sup\u003e\n\u003csub\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/426196\" width=64 height=64\u003e\u003c/sub\u003e\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\nA series of C# functions wrapping the \u003ca href=\"https://github.com/ollama/ollama/blob/main/docs/api.md\"\u003eollama APIs\u003c/a\u003e, mainly for the \u003ca href=\"https://unity.com/\"\u003eUnityEngine\u003c/a\u003e\n\u003c/p\u003e\n\n## Prerequisite\nBoth the **developer** and the **user**'s systems need to have a working ollama setup already:\n\n1. Download and Install [ollama](https://ollama.com/)\n2. Pull a model of choice from the [Library](https://ollama.com/library)\n    - Recommend `gemma3:4b` for general conversation\n        ```bash\n        ollama pull gemma3:4b\n        ```\n    - Recommend `gemma3:1b` for device with limited memory\n        ```bash\n        ollama pull gemma3:1b\n        ```\n    - Recommend `deepseek-r1:7b` if \"reasoning\" is needed\n        ```bash\n        ollama pull deepseek-r1:7b\n        ```\n    - Recommend `nomic-embed-text` for generating embeddings *(vectors)*\n        ```bash\n        ollama pull nomic-embed-text\n        ```\n    - Recommend `qwen3:4b` for tool calling\n        ```bash\n        ollama pull qwen3:4b\n        ```\n\nIn **Unity**, you need the `Newtonsoft.Json` package:\n\n1. Unity Editor\n2. Window\n3. Package Manager\n4. Add package by name\n5. Name:\n    ```\n    com.unity.nuget.newtonsoft-json\n    ```\n6. Add\n\nThen, simply download and install the `.unitypackage` from [Releases](https://github.com/Haoming02/ollama-unity/releases)\n\n\u003cbr\u003e\n\n## Features\nThe following functions are available under the **Ollama** `static` class; all functions are [asynchronous](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/async)\n\n- **List()**\n    - Return an array of `Model`, representing all locally available models\n    - The `Model` class follows the official [specs](https://github.com/ollama/ollama/blob/main/docs/api.md#list-local-models)\n\n\u003e [!TIP]\n\u003e You can use the `families` attribute to determine if a model is multimodal (see **[\\#2608](https://github.com/ollama/ollama/issues/2608)**)\n\n#### Generate\n\n- **Generate()**\n    - The most basic function that returns a response when given a model and a prompt\n    - You can also pass a `Texture2D` when using a model with vision capability\n- **GenerateStream()**\n    - The streaming variant that returns each word as soon as it's ready\n    - Requires a `callback` to handle the chunks\n- **GenerateJson()**\n    - Return the response in the specified `class` / `struct` format\n\n\u003e [!IMPORTANT]\n\u003e You need to manually tell the model to use a JSON format in the prompt\n\n#### Chat\n\n- **Chat()**\n    - Same as `Generate()`, but now with the memory of prior chat history, thus allowing you to further ask about previous conversations\n    - Requires either `InitChat()` or `LoadChatHistory()` to be called first\n    - **Example:**\n        ```\n                  \"Tell me a joke\" \u003c\u003c\n        \u003e\u003e ...\n                \"Explain the joke\" \u003c\u003c\n        \u003e\u003e ...\n        ```\n- **ChatStream()**\n    - Same as above\n- **InitChat()**\n    - Initialize / Reset the chat history\n    - `historyLimit`: The number of messages to keep in memory\n- **SaveChatHistory()**\n    - Save the current chat history to the specified path\n- **LoadChatHistory()**\n    - Load the chat history from the specified path\n    - Calls `InitChat()` automatically instead if the file does not exist\n- **ChatWithTool()**\n    - A special variant where you can additionally provide a list of `Tools`\n    - The LLM will return which function(s) to call, along with the corresponding arguments\n    - Though, you still need to manually parse and call the function yourself, unless you want to do some `Reflection` shenanigans...\n\n#### RAG\n\n\u003e **R**etrieval **A**ugmented **G**eneration\n\n- **Ask()**\n    - Ask a question based on given context\n    - Requires both `InitRAG()` and `AppendData()` to be called first\n- **InitRAG()**\n    - Initialize the database\n    - Requires a model to generate embeddings\n        - Can use a different model from the one used in `Ask()`\n\n\u003e [!IMPORTANT]\n\u003e Not all models can generate embeddings\n\n- **AppendData()**\n    - Add a context *(**eg.** a document)* to retrieve from\n\n\u003cbr\u003e\n\n## Demos\n5 demo scenes showcasing various features are included:\n\n- **Generate Demo**\n    - `List()`\n    - `Generate()`\n    - `GenerateJson()`\n\n- **Chat Demo**\n    - `InitChat()`\n    - `ChatStream()`\n\n- **RAG Demo**\n    - `InitRAG()`\n    - `AppendData()`\n    - `Ask()`\n\n- **Image Demo**\n    - `Generate()` with `Texture2D`\n\n- **Tool Demo**\n    - `ChatWithTool()`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaoming02%2Follama-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaoming02%2Follama-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaoming02%2Follama-unity/lists"}