-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathILLMProvider.cs
More file actions
92 lines (81 loc) · 2.62 KB
/
ILLMProvider.cs
File metadata and controls
92 lines (81 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace YAOLlm;
/// <summary>
/// Interface for LLM provider implementations
/// </summary>
public interface ILLMProvider : IDisposable
{
/// <summary>
/// Provider name (e.g., "gemini", "openrouter", "ollama")
/// </summary>
string Name { get; }
/// <summary>
/// Current model identifier
/// </summary>
string Model { get; }
/// <summary>
/// Whether this provider supports custom web search tool
/// (Some providers like Gemini have built-in grounding and don't need our tool)
/// </summary>
bool SupportsWebSearch { get; }
/// <summary>
/// Stream a conversation response from the LLM chunk by chunk
/// </summary>
/// <param name="history">Conversation history</param>
/// <param name="image">Optional image data (PNG/JPEG bytes)</param>
/// <param name="tools">Optional tool definitions for function calling</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Async enumerable of response text chunks</returns>
IAsyncEnumerable<string> StreamAsync(
List<ChatMessage> history,
byte[]? image = null,
List<ToolDefinition>? tools = null,
CancellationToken cancellationToken = default);
/// <summary>
/// Called when the provider status changes (e.g., "searching", "processing")
/// </summary>
event Action<string?>? OnStatusChange;
}
/// <summary>
/// Definition of a tool/function that the LLM can call
/// </summary>
public class ToolDefinition
{
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public object? Parameters { get; set; }
public ToolDefinition(string name, string description, object? parameters = null)
{
Name = name;
Description = description;
Parameters = parameters;
}
}
/// <summary>
/// Represents a tool call request from the LLM
/// </summary>
public class ToolCall
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public Dictionary<string, object?> Arguments { get; set; } = new();
}
/// <summary>
/// Result of executing a tool
/// </summary>
public class ToolResult
{
public string ToolCallId { get; set; }
public string Content { get; set; }
public bool IsError { get; set; }
public ToolResult(string toolCallId, string content, bool isError = false)
{
ToolCallId = toolCallId;
Content = content;
IsError = isError;
}
}