-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
157 lines (131 loc) · 8.95 KB
/
Program.cs
File metadata and controls
157 lines (131 loc) · 8.95 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using BuildXLChatBot;
using BuildXLChatBot.Plugins;
using Kernel = Microsoft.SemanticKernel.Kernel;
#pragma warning disable SKEXP0003, SKEXP0011, SKEXP0052, SKEXP0055 // Experimental
namespace BuildXLChatBot;
public class Program
{
private const string AssistantContext =
@"You are an AI assistant that can help with BuildXL tasks.
If you don't know how to carry out the task, simply say 'I don't know'.";
private const string SystemBackground =
@"Microsoft Build Accelerator (or, BuildXL) is an open source, cross platform, distributed build engine created by the 1ES team. It utilizes an observation-based sandbox to ensure correctness of caching and distribution. It runs in CloudBuild, Azure DevOps, and on dev machines. It supports running on Windows and Linux.
BuildXL has also been proven to scale to large codebases (e.g., Windows/Office repositories) where builds can consist of millions of processes with terabytes of outputs. BuildXL relies on runtime file-access monitoring for correct caching and distribution.
Documentation: https://github.com/microsoft/BuildXL/blob/main/Documentation/INDEX.md
The BuildXL tool has many arguments or command-line options that can be used to perform or control builds.
The following is a list of BuildXL command-line options or arguments. Each option is followed by a brief description of the option separated by '=>':
- /qualifier:<qualifier_value> => Qualifiers for controlling the build flavor (short form: /q).
EXAMPLE: /qualifier:debug => Builds the debug flavor.
- /property:<key>=<value> => Specifies a build property, in key=value format, that overrides an allowed environment variable (short form: /p).
EXAMPLE: /property:FOO=BAR => Overrides the environment variable FOO with the value BAR.
- /logProcesses => Log all processes, including nested child processes, launched during the build for each executed process pip.
- /logProcessData => Log process execution times and IO counts and transfers. This option requires /logProcesses to be enabled.
- /logObservedFileAccesses => Log observed file accessess for each executed process pip.
- /logProcessDetouringStatus => Log the detouring status for each executed process pip.
- /cacheMiss => Enable on-the-fly cache miss analysis during the execute phase.
EXAMPLE:
* /cacheMiss => Use the local FingerprintStore for comparison.
* /cacheMiss:[changeset1:changeset2:changeset3] => Compare the build to a remote FingerprintStore identified by changeset1, changeset2, and changeset3.
- /maxProc:<number> => Specifies the maximum number of processes that BuildXL will launch at one time.
EXAMPLE: /maxProc:10 => Specifies the maximum number of processes to be 10.
- /maxProcMultiplier:<number> => Specifies the multiplier for /maxProc.
EXAMPLE: /maxProcMultiplier:2 => Specifies the multiplier for /maxProc to be 2.
- /enableLinuxPTraceSandbox => Enables the ptrace sandbox on Linux when a statically linked binary is detected.
- /pipProperty:[PipId:[PropertyAndValue]] => Sets execution behaviors for a pip identified by PipId. PropertyAndValue can be a name or a <key>=<value> pair. Supported properties are 'PipFingerprintSalt' and 'EnableVerboseProcessLogging'.
EXAMPLES:
* /pipProperty:Pip123[PipFingerprintingSalt=Foo] => set 'Foo' fingerprint salt to pip Pip123
* /pipProperty:Pip123[PipFingerprintingSalt=*] => set random fingerprint salt to pip Pip123
* /pipProperty:Pip123[EnableVerboseProcessLogging] => set verbose process logging to pip Pip123
- /filter:<filter_expression> => Filter build according to filter expression <filter_expression> (short form: /f). Filter expressions consists of filter types that can be combined with the negation '~', 'and', and 'or' operators.
Types of filters:
* id => Filters by a pip's id or pip's semi-stable hash.
* tag => Filters by a tag.
* output => Filters pips by the output files they create. The value may be: 'path' to match a file, 'path\'. to match files within a directory, 'path\*' to match files in a directory and recursive directories, or '*\fileName' to match files with a specific name no matter where they are. 'path' may be an absolute or relative path. 'fileName' must be a fileName and may not contain any directory separator characters.
* input => Filters by an input to a pip. The value may be: 'path' to match a file, 'path\'. to match files within a directory, 'path\*' to match files in a directory and recursive directories, or '*\fileName' to match files with a specific name no matter where they are. 'path' may be an absolute or relative path. 'fileName' must be a fileName and may not contain any directory separator characters.
* value => Filters by value name.
EXAMPLES:
* /f:id='123456' => Selects the pip with the id or semi-stable hash '123456' and its dependencies.
* /f:tag='test' => Selects all pips marked with the 'test' tag, including their dependencies.
* /f:output='out\bin\release\foo.exe' => Selects all pips who will produce the output 'out\bin\release\foo.exe' and their dependencies.
* /f:output='out\bin\release\*' => Selects all pips who will produce outputs in 'out\bin\release' folder, including their dependencies.
* /f:input='src\utilities\foo.cpp' => Selects all pips who will consume the file 'src\utilities\foo.cpp', including their dependencies.
* /f:input='src\utilities\*' => Selects all pips who will consume inputs from 'src\utilities' folder, including their dependencies.
* /f:value='Foo' => Selects all pips with a value named 'Foo', including their dependencies.
EXAMPLES of filter expressions with negation and combination are as follows:
* /f:~(tag='test') => Selects all pips not marked with the 'test' tag, including their dependencies
* /f:(tag='foo'and~(tag='test')) => Selects all pips marked with tag 'foo' and not marked with tag 'test', including their dependencies
* /f:(tag='foo'or(tag='test')) => Selects all pips marked with tag 'foo' or marked with tag 'test', including their dependencies
* /f:(output='out\bin\release\*'and(input='src\utilities\foo.cpp')) => Selects all pips that produce outputs in 'out\bin\release' folder and consume the file 'src\utilities\foo.cpp', including their dependencies
";
public static async Task Main(string[] args)
{
Console.OutputEncoding = Encoding.Unicode;
if (!Settings.TryReadFromEnvironment(out Settings? settings, out string? error))
{
Console.WriteLine($"Error reading settings: {error}");
return;
}
Console.WriteLine($"UseOpenAI: {settings.UseOpenAI}");
Console.WriteLine($"Model: {settings.Model}");
Kernel kernel = CreateKernel(settings);
IChatCompletionService ai = kernel.GetRequiredService<IChatCompletionService>();
var chat = new ChatHistory(AssistantContext + Environment.NewLine + SystemBackground);
var builder = new StringBuilder();
var openAIPromptExecutionSettings = new OpenAIPromptExecutionSettings()
{
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};
Console.WriteLine("🤖 : Your command is my wish, sir! (or type 'exit' to quit)");
// Q&A loop
while (true)
{
Console.Write("😎 : ");
string userMessage = Console.ReadLine()!;
if (string.Equals("exit", userMessage.Trim(), StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("🤖 : Goodbye!");
break;
}
chat.AddUserMessage(userMessage);
builder.Clear();
bool first = true;
await foreach (var message in ai.GetStreamingChatMessageContentsAsync(
chat,
executionSettings: openAIPromptExecutionSettings,
kernel: kernel))
{
if (first)
{
Console.WriteLine("🤖 :");
first = false;
}
Console.Write(message);
builder.Append(message.Content);
}
Console.WriteLine();
chat.AddAssistantMessage(builder.ToString());
}
}
private static Kernel CreateKernel(Settings settings)
{
IKernelBuilder builder = Kernel.CreateBuilder();
if (settings.UseOpenAI)
{
builder.AddOpenAIChatCompletion(settings.Model, settings.ApiKey, settings.OrgId);
}
else
{
builder.AddAzureOpenAIChatCompletion(settings.Model, settings.EndPoint, settings.ApiKey);
}
builder.Services.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Trace));
builder.Plugins.AddFromType<CBPlugin>();
return builder.Build();
}
}