This project is an ASP.NET Core web API that integrates with Ollama for AI-powered chat, including function calling capabilities. The API allows the AI model to call custom C# functions (such as getting weather or location) and supports OpenAPI documentation and output caching for better performance.
- AI Chat Integration: Connects to an Ollama server and uses a configurable chat model.
- Function Calling: The AI can invoke C# functions to provide dynamic responses.
- OpenAPI Support: Automatically generates API documentation.
- Output Caching: Improves performance for frequent queries.
- .NET 9.0 SDK installed
- Ollama installed and running locally (default:
http://localhost:11434) - At least one chat model pulled to Ollama (e.g.,
llama3.2)
git clone cd OllamaWithExtensionAndFunctionCalling
Edit appsettings.json to match your Ollama setup:
ollama pull llama3.2
dotnet run
The API will be available at http://localhost:5000 (or another port if configured).
Send a message to the AI and receive a response. The AI can call built-in functions for weather and location.
Request body:
"Hello, what's the weather in my location?"
Response:
{ "response": "It's sunny in Vienna, Austria" }
Redirects to the Scalar API reference.
- OpenAPI/Swagger:
/openapi.json - Scalar API reference:
/scalar/v1
The AI can call these C# functions:
- GetWeather: Returns a random weather status.
- GetLocation: Returns a fixed location ("Vienna, Austria").
- GetWeatherAndLocation: Combines weather and location.
Output caching is enabled for frequent queries, with a default expiration of 5 minutes.
This project is for educational and demonstration purposes.
Feel free to modify this README to fit your specific needs!