-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (54 loc) · 1.92 KB
/
Copy pathProgram.cs
File metadata and controls
68 lines (54 loc) · 1.92 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
using System.CommandLine;
using System.Text;
namespace Noema;
internal static class Program
{
internal static string? model;
private static async Task<int> Main (string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
int parseErr = ParseArguments(args);
if (parseErr != 0)
{
Console.WriteLine("Error while parsing arguments. ERRCODE:" + parseErr);
return parseErr;
}
if (model == null)
{
Console.WriteLine("No model was provided with --model");
Console.WriteLine("Please enter the model to use:");
model = Console.ReadLine();
if (string.IsNullOrWhiteSpace(model))
{
Console.WriteLine("No model was provided.");
return 1;
}
}
OllamaClient ollama = new(model);
using CancellationTokenSource cancellationTokenSource = new();
if (!await ollama.IsRunningAsync(cancellationTokenSource.Token))
{
Console.WriteLine("Ollama is not running or cannot be reached.");
return 1;
}
if (!await ollama.IsModelAvailableAsync(cancellationTokenSource.Token))
{
Console.WriteLine($"Model '{model}' is not installed in Ollama.");
return 1;
}
Console.WriteLine($"Using Ollama model '{model}'.");
ChatInterface chatInterface = new();
return await chatInterface.Chat(ollama);
}
private static int ParseArguments (string[] args)
{
Option<string> modelOption = new("--model");
RootCommand rootCommand = new("An experimental creative AI that uses random personas to increase diversity");
rootCommand.Options.Add(modelOption);
rootCommand.SetAction(parseResult =>
{
model = parseResult.GetValue(modelOption);
});
return rootCommand.Parse(args).Invoke();
}
}