Simple .NET 9 chat client/api example that demonstrates how to use the Ollama Chat API.
- Set up persistent volume local folders and update docker-compose.ymlwith folder locations first.
- docker-compose up -dto pull and start- Ollamaand- Redisdocker containers.
- docker exec -it ollama ollama pull llama3to pull the- llama3model into the- Ollamacontainer (this will take a while).
- If using VS Code RUN AND DEBUG > Launch Debug > Run
- Switching between emulator and Ollama AI Chat Client is done in appSettings.development.json
  "ChatSettings": {
    "UseEmulator": true,
    "EmulatorResponseTime": 10000 // milliseconds
  }
- I am using Redisto store chat history, and this has been 'abused' to manage the chat history.
- The ChatServiceshould ideally be implemented as a scalable background microservice. I am usingDotNet Channelfor background process management because this is a monolithic example.
- Throttling/request scaling has not been implemented as I am using a non-distributed Chat API (Ollamain this case), so if you throw multiple requests atOllamawhile it is still trying to figure things out, you will run into issues.
- Redishas been configured (in code) to invalidate conversations after 15 mins.
- Plenty more that can be done. This is not production code, but a simple example to demonstrate how to use the OllamaChat API.
- ChatClientEmulatoris a simple- IChatClientreplacement so we can bypass requests to- Ollama. It is there to ease development.
- docker exec -it ollamma bashto enter the container.`
- You are not confined to llama3. You can pull other models as well, such as DeepSeek-R1, Phi-4, Mistral, Gemma 3, and more. Visithttps://ollama.ai/modelsfor more information.