- /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
- /// var prompt = "You are a helpful assistant that will answer any question you are asked.";
- /// var chat = new Chat(client, prompt);
+ /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
+ /// var chat = new Chat(client);
+ ///
+ /// // Sending a message to the chat
+ /// chat.SendMessage("Hello, how are you?");
///
///
+ /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
+ /// var systemPrompt = "You are an expert assistant specializing in data science.";
+ /// var chat = new Chat(client, systemPrompt);
+ ///
+ /// // Sending a message to the chat
+ /// chat.SendMessage("Can you explain neural networks?");
+ ///
+ ///
+ /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
+ /// var chat = new Chat(client);
+ /// var tools = new List { new Tool() }; // Example tools
+ /// var images = new List { ConvertImageToBase64("path-to-image.jpg") };
+ /// await foreach (var response in chat.SendAsync(
+ /// "Tell me about recent advancements in AI.",
+ /// tools: tools,
+ /// imagesAsBase64: images,
+ /// format: "json",
+ /// cancellationToken: CancellationToken.None))
+ /// {
+ /// Console.WriteLine(response);
+ /// }
+ ///
+ ///
+ /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
+ /// var chat = new Chat(client);
+ /// var role = new ChatRole("assistant");
+ /// var responseStream = chat.SendAsAsync(role, "How can I assist you today?");
+ /// await foreach (var response in responseStream)
+ /// {
+ /// Console.WriteLine(response); // Streams and prints the response from the server
+ /// }
+ ///
+ ///
+ /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
+ /// var chat = new Chat(client);
+ /// var role = new ChatRole("user");
+ /// var message = "What's the weather like today?";
+ /// var images = new List<IEnumerable<byte>> { File.ReadAllBytes("exampleImage.jpg") };
+ /// await foreach (var response in chat.SendAsAsync(role, message, images, CancellationToken.None))
+ /// {
+ /// Console.WriteLine(response);
+ /// }
+ ///
+ ///
+ /// var client = new OllamaApiClient("http://localhost:11434", "llama3.2-vision:latest");
+ /// var chat = new Chat(client)
+ /// {
+ /// Model = "llama3.2-vision:latest"
+ /// };
+ /// // Sending a message as a user role and processing the response
+ /// await foreach (var response in chat.SendAsAsync(ChatRole.User, "Describe the image", null))
+ /// {
+ /// Console.WriteLine(response);
+ /// }
+ ///
+ ///
+ /// var chat = new Chat(client);
+ /// var role = new ChatRole("assistant");
+ /// var tools = new List<Tool>();
+ /// var images = new List<string> { "base64EncodedImageData" };
+ /// await foreach (var response in chat.SendAsAsync(role, "Generate a summary for the attached image", tools, images))
+ /// {
+ /// Console.WriteLine($"Received response: {response}");
+ /// }
+ ///
+ ///
+ /// List<int> myList = new List<int> { 1, 2, 3 };
+ /// IEnumerable<int>? additionalItems = new List<int> { 4, 5, 6 };
+ /// myList.AddRangeIfNotNull(additionalItems);
+ /// // myList now contains { 1, 2, 3, 4, 5, 6 }
+ /// IEnumerable<int>? nullItems = null;
+ /// myList.AddRangeIfNotNull(nullItems);
+ /// // myList remains unchanged { 1, 2, 3, 4, 5, 6 }
+ ///
+ ///
+ /// List<string> fruits = new List<string> { "apple", "banana", "cherry" };
+ /// fruits.ForEachItem(fruit => Console.WriteLine(fruit));
+ /// // Output:
+ /// // apple
+ /// // banana
+ /// // cherry
+ /// IEnumerable<int> numbers = new List<int> { 1, 2, 3 };
+ /// numbers.ForEachItem(number => Console.WriteLine(number * 2));
+ /// // Output:
+ /// // 2
+ /// // 4
+ /// // 6
+ ///
+ /// +/// This static class contains various string constants that represent API endpoints. These constants are used primarily +/// in API client implementations for making requests to specific functionality provided by the backend API. +///
+///+/// MIME types are used to specify the format of data being sent or received in HTTP requests. +///
+///
+ /// var builder = new MessageBuilder();
+ /// var chunk = new ChatResponseStream
+ /// {
+ /// Message = new Message
+ /// {
+ /// Content = "Hello, World!",
+ /// Role = ChatRole.User,
+ /// Images = new[] { "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAGUlEQVR4nGJpfnqXARtgwio6aCUAAQAA///KcwJYgRBQbAAAAABJRU5ErkJggg==" },
+ /// ToolCalls = new List<Message.ToolCall>()
+ /// }
+ /// };
+ /// builder.Append(chunk);
+ /// var resultMessage = builder.ToMessage();
+ /// Console.WriteLine(resultMessage.Content); // Output: Hello, World!
+ ///
+ ///
+ /// var builder = new MessageBuilder();
+ /// builder.Role = ChatRole.Assistant;
+ /// // Append content (this would typically be done with Append method)
+ /// builder.Append(new ChatResponseStream
+ /// {
+ /// Message = new Message
+ /// {
+ /// Content = "Generated content from assistant."
+ /// }
+ /// });
+ /// // Convert to a Message object
+ /// var finalMessage = builder.ToMessage();
+ /// Console.WriteLine(finalMessage.Content); // Output: Generated content from assistant.
+ /// Console.WriteLine(finalMessage.Role); // Output: Assistant
+ ///
+ /// The
+ /// var messageBuilder = new MessageBuilder();
+ /// var chunk = new ChatResponseStream
+ /// {
+ /// Message = new Message
+ /// {
+ /// Content = "What can I help you with?",
+ /// Role = ChatRole.Assistant
+ /// }
+ /// };
+ /// messageBuilder.Append(chunk);
+ /// Console.WriteLine(messageBuilder.Role); // Output: Assistant
+ ///
+ /// This property contains a read-only collection of image file paths or URIs associated with the message content.
+ /// The
+ /// var builder = new MessageBuilder();
+ /// var chunk = new ChatResponseStream
+ /// {
+ /// Message = new Message
+ /// {
+ /// Content = "Here is an example image:",
+ /// Role = ChatRole.Assistant,
+ /// Images = new[] { "example_image.png" } // Note: Images are base64 encoded, this is just an example
+ /// }
+ /// };
+ /// builder.Append(chunk);
+ /// var resultMessage = builder.ToMessage();
+ /// Console.WriteLine(string.Join(", ", resultMessage.Images)); // Output: example_image.png
+ ///
+ /// The
+ /// var messageBuilder = new MessageBuilder();
+ /// var toolCall = new Message.ToolCall
+ /// {
+ /// Function = new Message.Function()
+ /// };
+ /// var chunk = new ChatResponseStream
+ /// {
+ /// Message = new Message
+ /// {
+ /// Content = "Triggered a tool call",
+ /// ToolCalls = new[] { toolCall }
+ /// }
+ /// };
+ /// messageBuilder.Append(chunk);
+ /// Console.WriteLine(messageBuilder.ToolCalls.Count); // Output: 1
+ ///
+ /// This property is useful for verifying whether the builder contains meaningful data before processing further,
+ /// such as converting it to a
+ /// var messageBuilder = new MessageBuilder();
+ /// Console.WriteLine(messageBuilder.HasValue); // Output: False
+ /// // Append a new chunk of content
+ /// messageBuilder.Append(new ChatResponseStream
+ /// {
+ /// Message = new Message
+ /// {
+ /// Content = "Hello, how can I assist you?",
+ /// Role = ChatRole.Assistant
+ /// }
+ /// });
+ /// Console.WriteLine(messageBuilder.HasValue); // Output: True
+ ///
+ ///