Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tool usage with source generators #171

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

awaescher
Copy link
Owner

@awaescher awaescher commented Jan 15, 2025

This pull request introduces a source generator that can generate Ollama tools from simple method implementations. Usage can be found in the ToolConsole demo:

/// <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}.";
  • use object[] as tools instead of Tool[] in web requests to prevent dependencies
    see Metadata and return description for the tools #143
  • introduce a source generator that generates the code for tools (meta data and implementation)
    • allow static tool implementation as shown above for demos and simple calculations
    • allow non-static tool implementations with arguments and injected services
    • allow definition of tool meta data only (maybe with interfaces?)
    • make arguments required unless they are optional
    • automatic execution of requested tools by the tool calls provided by the LLM
    • backpropagation of the tool results (as message with role "Tool") to the LLM
    • use code enums for available values like "enum": ["celsius", "fahrenheit"] (see Unit in the code above)
      • error handling for enum values from the LLM that cannot get parsed
    • parse meta data such as method and parameter names from XML summaries like in the code above
      • C#
      • F#?
      • Visual Basic?
    • build a separate NuGet package for the source generator

@awaescher awaescher self-assigned this Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant