BioGTK  6.5.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
BioGTK.AI Class Reference
Inheritance diagram for BioGTK.AI:

Classes

class  OllamaChatService
 

Public Member Functions

record ChatMessage ([property:JsonPropertyName("role")] string Role, [property:JsonPropertyName("content")] string Content)
 
record ChatRequest ([property:JsonPropertyName("model")] string Model, [property:JsonPropertyName("messages")] IReadOnlyList< ChatMessage > Messages, [property:JsonPropertyName("temperature")] double? Temperature=null, [property:JsonPropertyName("max_tokens")] int? MaxTokens=null)
 
record ChatChoice ([property:JsonPropertyName("message")] ChatMessage Message, [property:JsonPropertyName("index")] int Index, [property:JsonPropertyName("finish_reason")] string FinishReason)
 
record ChatResponse ([property:JsonPropertyName("id")] string Id, [property:JsonPropertyName("object")] string Object, [property:JsonPropertyName("created")] long Created, [property:JsonPropertyName("model")] string Model, [property:JsonPropertyName("choices")] IReadOnlyList< ChatChoice > Choices)
 
async Task StartAsync (string args, CancellationToken uiCancel=default)
 

Static Public Member Functions

static AI Create ()
 

Static Public Attributes

static bool onTab = false
 
static bool useBioformats = true
 
static bool headless = false
 
static bool resultInNewTab = false
 

Protected Member Functions

 AI (Builder builder, IntPtr handle)
 Specialised constructor for use only by derived class.
 
void SetupHandlers ()
 Sets up the handlers.
 

Detailed Description

Definition at line 29 of file AI.cs.

Constructor & Destructor Documentation

◆ AI()

BioGTK.AI.AI ( Builder builder,
IntPtr handle )
protected

Specialised constructor for use only by derived class.

Parameters
builderThe builder.
handleThe handle.

Definition at line 68 of file AI.cs.

68 : base(handle)
69 {
70 _builder = builder;
71 builder.Autoconnect(this);
73 App.ApplyStyles(this);
74 this.ShowAll();
75 }
void SetupHandlers()
Sets up the handlers.
Definition AI.cs:213

Member Function Documentation

◆ Create()

static AI BioGTK.AI.Create ( )
static

Create a new AI object using the Glade file "BioGTK.Glade.AI.glade"

Returns
A new instance of the AI class.

Definition at line 59 of file AI.cs.

60 {
61 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/Glade/AI.glade", FileMode.Open));
62 return new AI(builder, builder.GetObject("aiConsole").Handle);
63 }
AI(Builder builder, IntPtr handle)
Specialised constructor for use only by derived class.
Definition AI.cs:68

◆ SetupHandlers()

void BioGTK.AI.SetupHandlers ( )
protected

Sets up the handlers.

Definition at line 213 of file AI.cs.

214 {
215 sendBut.ButtonPressEvent += SendBut_ButtonPressEvent;
216 }

◆ StartAsync()

async Task BioGTK.AI.StartAsync ( string args,
CancellationToken uiCancel = default )

Definition at line 180 of file AI.cs.

181 {
182
183 try
184 {
185 var ollama = new OllamaChatService(client);
186 string assistantReply = await ollama.GetResponseAsync(
187 systemPrompt: "You are a C# programmer",
188 userPrompt: args,
189 cancellationToken: uiCancel);
190
191 TextIter tr = textBox.Buffer.StartIter;
192 textBox.Buffer.Insert(ref tr, assistantReply);
193 }
194 catch (TimeoutException tex)
195 {
196 Console.WriteLine($"⌛ Timeout: {tex.Message}");
197 }
198 catch (HttpRequestException hrex)
199 {
200 Console.WriteLine($"❌ Server error: {hrex.Message}");
201 }
202 catch (OperationCanceledException) when (uiCancel.IsCancellationRequested)
203 {
204 Console.WriteLine("⚪ Request cancelled by the user.");
205 }
206 catch (Exception ex)
207 {
208 Console.WriteLine($"❌ Unexpected error: {ex.Message}");
209 }
210 }

Member Data Documentation

◆ headless

bool BioGTK.AI.headless = false
static

Definition at line 41 of file AI.cs.

◆ onTab

bool BioGTK.AI.onTab = false
static

Definition at line 39 of file AI.cs.

◆ resultInNewTab

bool BioGTK.AI.resultInNewTab = false
static

Definition at line 42 of file AI.cs.

◆ useBioformats

bool BioGTK.AI.useBioformats = true
static

Definition at line 40 of file AI.cs.


The documentation for this class was generated from the following file: