Implement the core application server as an ASP.NET web host with: - SignalR ChatHub for real-time client communication - Session management with token estimation for context windowing - Extensible tool system with attribute-based tool discovery - Chat stream update builder for streaming AI responses - App configuration with appsettings for development and production
30 lines
816 B
C#
30 lines
816 B
C#
using System.Reflection;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace Luna.Core.Tools;
|
|
|
|
public interface IToolbox
|
|
{
|
|
public string Name { get; }
|
|
|
|
public sealed IEnumerable<AITool> GetTools()
|
|
{
|
|
var type = GetType();
|
|
|
|
List<(ToolAttribute Attribute, MethodInfo Method)> tools = [];
|
|
foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
var attribute = method.GetCustomAttribute<ToolAttribute>();
|
|
if (attribute is null) continue;
|
|
|
|
tools.Add((attribute, method));
|
|
}
|
|
|
|
return tools.Select(tool => AIFunctionFactory.Create(
|
|
tool.Method,
|
|
this,
|
|
$"{this.Name}/{tool.Attribute.Name}",
|
|
tool.Attribute.Description
|
|
));
|
|
}
|
|
} |