-
Notifications
You must be signed in to change notification settings - Fork 27
/
PluginProgramTranslator.cs
54 lines (46 loc) · 1.66 KB
/
PluginProgramTranslator.cs
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
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.TypeChat;
/// <summary>
/// Program translator that translates user requests into programs that call APIs defined by Microsoft Semantic Kernel Plugins
/// </summary>
public class PluginProgramTranslator
{
Kernel _kernel;
ProgramTranslator _translator;
PluginApi _pluginApi;
SchemaText _pluginSchema;
/// <summary>
/// Create a new translator that will produce programs that can call all skills and
/// plugins registered with the given semantic kernel
/// </summary>
/// <param name="kernel"></param>
/// <param name="model"></param>
public PluginProgramTranslator(Kernel kernel, ModelInfo model)
{
_kernel = kernel;
_pluginApi = new PluginApi(_kernel);
_pluginSchema = _pluginApi.TypeInfo.ExportSchema(_pluginApi.TypeName);
_translator = new ProgramTranslator(
_kernel.ChatLanguageModel(model),
new ProgramValidator(new PluginProgramValidator(_pluginApi.TypeInfo)),
_pluginSchema
);
}
/// <summary>
/// Translator being used
/// </summary>
public ProgramTranslator Translator => _translator;
/// <summary>
/// Kernel this translator is working with
/// </summary>
public Kernel Kernel => _kernel;
/// <summary>
/// The "API" formed by the various plugins registered with the kernel
/// </summary>
public PluginApi Api => _pluginApi;
public SchemaText Schema => _pluginSchema;
public Task<Program> TranslateAsync(string input, CancellationToken cancelToken)
{
return _translator.TranslateAsync(input, cancelToken);
}
}