{"id":17527159,"url":"https://github.com/tryAGI/Ollama","last_synced_at":"2025-03-06T06:31:50.558Z","repository":{"id":239102851,"uuid":"798503976","full_name":"tryAGI/Ollama","owner":"tryAGI","description":"Ollama SDK for .NET","archived":false,"fork":false,"pushed_at":"2024-10-16T18:03:10.000Z","size":571,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-18T10:19:28.339Z","etag":null,"topics":["ai","api","csharp","dotnet","langchain","langchain-dotnet","llm","local","net6","net8","netstandard20","ollama","openapi","openapigenerator","rag","rest","sdk"],"latest_commit_sha":null,"homepage":"https://tryagi.github.io/Ollama/","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/tryAGI.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},"funding":{"github":"HavenDV","patreon":"havendv","ko_fi":"havendv","custom":["https://www.paypal.me/havendv","https://www.buymeacoffee.com/havendv","https://donate.stripe.com/00gfZ19zkeKLh1eaEE","https://www.upwork.com/freelancers/~017b1ad6f6af9cc189"]}},"created_at":"2024-05-09T23:01:23.000Z","updated_at":"2024-10-16T18:03:13.000Z","dependencies_parsed_at":"2024-05-11T04:27:05.503Z","dependency_job_id":"6cc2f7d5-9d88-4847-9db5-940cd5af8ec2","html_url":"https://github.com/tryAGI/Ollama","commit_stats":null,"previous_names":["tryagi/ollama"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FOllama","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FOllama/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FOllama/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tryAGI%2FOllama/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tryAGI","download_url":"https://codeload.github.com/tryAGI/Ollama/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242161976,"owners_count":20081978,"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":["ai","api","csharp","dotnet","langchain","langchain-dotnet","llm","local","net6","net8","netstandard20","ollama","openapi","openapigenerator","rag","rest","sdk"],"created_at":"2024-10-20T15:08:09.213Z","updated_at":"2025-03-06T06:31:50.546Z","avatar_url":"https://github.com/tryAGI.png","language":"C#","funding_links":["https://github.com/sponsors/HavenDV","https://patreon.com/havendv","https://ko-fi.com/havendv","https://www.paypal.me/havendv","https://www.buymeacoffee.com/havendv","https://donate.stripe.com/00gfZ19zkeKLh1eaEE","https://www.upwork.com/freelancers/~017b1ad6f6af9cc189"],"categories":["Libraries","A01_文本生成_文本对话"],"sub_categories":["大语言对话模型及数据"],"readme":"# Ollama SDK for .NET 🦙\n\n[![Nuget package](https://img.shields.io/nuget/vpre/Ollama)](https://www.nuget.org/packages/Ollama/)\n[![dotnet](https://github.com/tryAGI/Ollama/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/tryAGI/Ollama/actions/workflows/dotnet.yml)\n[![License: MIT](https://img.shields.io/github/license/tryAGI/Ollama)](https://github.com/tryAGI/Ollama/blob/main/LICENSE.txt)\n[![Discord](https://img.shields.io/discord/1115206893015662663?label=Discord\u0026logo=discord\u0026logoColor=white\u0026color=d82679)](https://discord.gg/Ca2xhfBf3v)\n\n## Features 🔥\n- Fully generated C# SDK based on [OpenAPI specification](https://github.com/davidmigloz/langchain_dart/blob/main/packages/ollama_dart/oas/ollama-curated.yaml) using [OpenApiGenerator](https://github.com/HavenDV/OpenApiGenerator)\n- Automatic releases of new preview versions if there was an update to the OpenAPI specification\n- Source generator to define tools natively through C# interfaces\n- All modern .NET features - nullability, trimming, NativeAOT, etc.\n- Support .Net Framework/.Net Standard 2.0\n- Support for all Ollama API endpoints including chats, embeddings, listing models, pulling and creating new models, and more.\n\n## Usage\n\n### Initializing\n\n```csharp\nusing var ollama = new OllamaApiClient();\n// or if you have a custom server\n// using var ollama = new OllamaApiClient(baseUri: new Uri(\"http://10.10.5.85:11434/api\")\n\nvar models = await ollama.Models.ListModelsAsync();\n\n// Pulling a model and reporting progress\nawait foreach (var response in ollama.PullModelAsync(\"all-minilm\", stream: true))\n{\n    Console.WriteLine($\"{response.Status}. Progress: {response.Completed}/{response.Total}\");\n}\n// or just pull the model and wait for it to finish\nawait ollama.Models.PullModelAsync(\"all-minilm\").EnsureSuccessAsync();\n\n// Generating an embedding\nvar embedding = await ollama.Embeddings.GenerateEmbeddingAsync(\n    model: \"all-minilm\",\n    prompt: \"hello\");\n\n// Streaming a completion directly into the console\n// keep reusing the context to keep the chat topic going\nIList\u003clong\u003e? context = null;\nvar enumerable = ollama.Completions.GenerateCompletionAsync(\"llama3.2\", \"answer 5 random words\");\nawait foreach (var response in enumerable)\n{\n    Console.WriteLine($\"\u003e {response.Response}\");\n    \n    context = response.Context;\n}\n\nvar lastResponse = await ollama.Completions.GenerateCompletionAsync(\"llama3.2\", \"answer 123\", stream: false, context: context).WaitAsync();\nConsole.WriteLine(lastResponse.Response);\n\nvar chat = ollama.Chat(\"mistral\");\nwhile (true)\n{\n    var message = await chat.SendAsync(\"answer 123\");\n    \n    Console.WriteLine(message.Content);\n    \n    var newMessage = Console.ReadLine();\n    await chat.Send(newMessage);\n}\n```\n\n### Tools\n```csharp\nusing var ollama = new OllamaApiClient();\nvar chat = ollama.Chat(\n    model: \"llama3.2\",\n    systemMessage: \"You are a helpful weather assistant.\",\n    autoCallTools: true);\n\nvar service = new WeatherService();\nchat.AddToolService(service.AsTools().AsOllamaTools(), service.AsCalls());\n\ntry\n{\n    _ = await chat.SendAsync(\"What is the current temperature in Dubai, UAE in Celsius?\");\n}\nfinally\n{\n    Console.WriteLine(chat.PrintMessages());\n}\n```\n```\n\u003e System:\nYou are a helpful weather assistant.\n\u003e User:\nWhat is the current temperature in Dubai, UAE in Celsius?\n\u003e Assistant:\nTool calls:\nGetCurrentWeather({\"location\":\"Dubai, UAE\",\"unit\":\"celsius\"})\n\u003e Tool:\n{\"location\":\"Dubai, UAE\",\"temperature\":22,\"unit\":\"celsius\",\"description\":\"Sunny\"}\n\u003e Assistant:\nThe current temperature in Dubai, UAE is 22°C.\n```\n```csharp\nusing CSharpToJsonSchema;\n\npublic enum Unit\n{\n    Celsius,\n    Fahrenheit,\n}\n\npublic class Weather\n{\n    public string Location { get; set; } = string.Empty;\n    public double Temperature { get; set; }\n    public Unit Unit { get; set; }\n    public string Description { get; set; } = string.Empty;\n}\n\n[GenerateJsonSchema]\npublic interface IWeatherFunctions\n{\n    [Description(\"Get the current weather in a given location\")]\n    public Task\u003cWeather\u003e GetCurrentWeatherAsync(\n        [Description(\"The city and state, e.g. San Francisco, CA\")] string location,\n        Unit unit = Unit.Celsius,\n        CancellationToken cancellationToken = default);\n}\n\npublic class WeatherService : IWeatherFunctions\n{\n    public Task\u003cWeather\u003e GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)\n    {\n        return Task.FromResult(new Weather\n        {\n            Location = location,\n            Temperature = 22.0,\n            Unit = unit,\n            Description = \"Sunny\",\n        });\n    }\n}\n```\n\n## Credits\n\nIcon and name were reused from the amazing [Ollama project](https://github.com/jmorganca/ollama).  \nThe project was forked from [this repository](https://github.com/awaescher/OllamaSharp), \nafter which automatic code generation was applied based on [this OpenAPI specification](https://github.com/davidmigloz/langchain_dart/blob/main/packages/ollama_dart/oas/ollama-curated.yaml) \n(in the future it will be replaced by the official one, if one appears)\n\n## Support\n\nPriority place for bugs: https://github.com/tryAGI/Ollama/issues  \nPriority place for ideas and general questions: https://github.com/tryAGI/Ollama/discussions  \nDiscord: https://discord.gg/Ca2xhfBf3v  \n\n## Acknowledgments\n\n![JetBrains logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png)\n\nThis project is supported by JetBrains through the [Open Source Support Program](https://jb.gg/OpenSourceSupport).\n\n![CodeRabbit logo](https://opengraph.githubassets.com/1c51002d7d0bbe0c4fd72ff8f2e58192702f73a7037102f77e4dbb98ac00ea8f/marketplace/coderabbitai)\n\nThis project is supported by CodeRabbit through the [Open Source Support Program](https://github.com/marketplace/coderabbitai).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtryAGI%2FOllama","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FtryAGI%2FOllama","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtryAGI%2FOllama/lists"}