Skip to content

Release 5.1.1

Choose a tag to compare

@github-actions github-actions released this 21 Feb 16:22
99ce812
  • Improved tool usage with source generators #171 (preview)

Note

This is a preview feature. See #171 for more details.

All that's required to use tools with OllamaSharp is decorating static methods with the [OllamaTool] attribute. OllamaSharp will automatically generate the required code that describes the tool's metadata and invokes the method automatically if requested by the LLM.

It's highly recommended to write a complete summary including the arguments as the summary is used to describe the method and its arguments to the LLM.

/// <summary>
/// Gets the current weather for a given location.
/// </summary>
/// <param name="location">The location or city to get the weather for</param>
/// <param name="unit">The unit to measure the temperature in</param>
/// <returns>The weather for the given location</returns>
[OllamaTool]
public static string GetWeather(string location, Unit unit) => $"It's cold at only 6° {unit} in {location}.";

You can find the generated code for the tools under the Dependencies node in your project:

image