This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
89 lines (70 loc) · 2.05 KB
/
Program.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
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
using OllamaApiConsole;
using OllamaApiConsole.Demos;
using OllamaSharp;
using Spectre.Console;
Console.ResetColor();
AnsiConsole.Write(new Rule("OllamaSharp Api Console").LeftJustified());
AnsiConsole.WriteLine();
OllamaApiClient? ollama = null;
var connected = false;
do
{
AnsiConsole.MarkupLine($"Enter the Ollama [{OllamaConsole.AccentTextColor}]machine name[/] or [{OllamaConsole.AccentTextColor}]endpoint url[/]");
var url = OllamaConsole.ReadInput();
if (string.IsNullOrWhiteSpace(url))
url = "http://localhost:11434";
if (!url.StartsWith("http"))
url = "http://" + url;
if (url.IndexOf(':', 5) < 0)
url += ":11434";
var uri = new Uri(url);
Console.WriteLine($"Connecting to {uri} ...");
try
{
ollama = new OllamaApiClient(url);
connected = await ollama.IsRunning();
var models = await ollama.ListLocalModels();
if (!models.Any())
AnsiConsole.MarkupLineInterpolated($"[{OllamaConsole.WarningTextColor}]Your Ollama instance does not provide any models :([/]");
}
catch (Exception ex)
{
AnsiConsole.MarkupLineInterpolated($"[{OllamaConsole.ErrorTextColor}]{Markup.Escape(ex.Message)}[/]");
AnsiConsole.WriteLine();
}
} while (!connected);
string demo;
do
{
AnsiConsole.Clear();
demo = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.PageSize(10)
.Title("What demo do you want to run?")
.AddChoices("Chat", "Image chat", "Tool chat", "Model manager", "Exit"));
AnsiConsole.Clear();
try
{
switch (demo)
{
case "Chat":
await new ChatConsole(ollama!).Run();
break;
case "Image chat":
await new ImageChatConsole(ollama!).Run();
break;
case "Tool chat":
await new ToolConsole(ollama!).Run();
break;
case "Model manager":
await new ModelManagerConsole(ollama!).Run();
break;
}
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"An error occurred. Press [{OllamaConsole.AccentTextColor}]Return[/] to start over.");
AnsiConsole.MarkupLineInterpolated($"[{OllamaConsole.ErrorTextColor}]{Markup.Escape(ex.Message)}[/]");
Console.ReadLine();
}
} while (demo != "Exit");