Defining complex functions
Earlier, we saw how we could define prompt functions that passed a textual prompt to an LLM and returned the output from that system.
It’s also possible to define functions that don’t involve LLMs at all and instead invoke a C# method.
Creating functions from methods
We’ll demonstrate these more complex functions by defining a function that calls a simple C# method:
KernelFunction timeFunc = kernel.CreateFunctionFromMethod( () => DateTime.Now.ToShortTimeString(), "GetCurrentTime", "Retrieves the current time in the local time zone.");
This creates a timeFunc
KernelFunction
that can be invoked later.
Note how the first parameter of CreateFunctionFromMethod
takes in a lambda expression. In this case, the expression takes in zero parameters and returns the current time as a short time string.
We also provide the function’s name as GetCurrentTime...