Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created May 29, 2025 17:22
Show Gist options
  • Save elbruno/d87c7f48a0c2715913f56c95736709d2 to your computer and use it in GitHub Desktop.
Save elbruno/d87c7f48a0c2715913f56c95736709d2 to your computer and use it in GitHub Desktop.
alttextgenimage-run.cs
#:package [email protected]
using OllamaSharp;
// set up the client
var uri = new Uri("http://localhost:11434");
var ollama = new OllamaApiClient(uri);
ollama.SelectedModel = "gemma3";
var chat = new Chat(ollama);
// read the image
byte[] imageBytes = File.ReadAllBytes(args[0]);
var imageBytesEnumerable = new List<IEnumerable<byte>> { imageBytes };
// generate alt text0
var message = "Generate a complete alt text description for the attached image.";
await foreach (var answerToken in chat.SendAsync(message: message, imagesAsBytes: imageBytesEnumerable))
Console.Write(answerToken);
// done
Console.WriteLine($">> Ollama done");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment