Method ImportFunctions
- Namespace
- LMKit.FunctionCalling
- Assembly
- LM-Kit.NET.dll
ImportFunctions<T>()
Registers all methods in the specified type T that are marked with the LMFunctionAttribute.
public void ImportFunctions<T>()
Type Parameters
TThe type whose methods will be registered.
Examples
using LMKit.Model;
using LMKit.FunctionCalling;
using LMKit.Agents.Tools;
using System;
using System.ComponentModel;
public class WeatherService
{
[LMFunction("GetWeather", "Gets weather for a city")]
public string GetWeather([Description("City name")] string city)
{
return $"Weather in {city}: Sunny, 72F";
}
}
LM model = LM.LoadFromModelID("llama-3.2-1b");
using var functionCall = new SingleFunctionCall(model);
// Import functions from the WeatherService class
functionCall.ImportFunctions<WeatherService>();
var result = functionCall.Submit("What's the weather in Paris?");
Console.WriteLine(result.Result);
Exceptions
- ArgumentException
Thrown when:
- No methods in the specified type are marked with the LMFunctionAttribute.
- An instance of the type
Tis already registered.
ImportFunctions(object)
Registers all methods in the specified object instance that are marked with the LMFunctionAttribute.
public void ImportFunctions(object instance)
Parameters
instanceobjectThe object instance whose methods will be registered.
Exceptions
- ArgumentNullException
Thrown when the provided instance is null.
- ArgumentException
Thrown when:
- No methods in the provided instance are marked with the LMFunctionAttribute.
- The instance or its type is already registered.
- An LM-Kit function with the same name already exists.