Skip to content

Instantly share code, notes, and snippets.

public sealed class ValidationPipeline
{
private readonly IEnumerable<IValidationStep> _steps;
public ValidationPipeline(IEnumerable<IValidationStep> steps)
{
_steps = steps;
}
public async Task<ValidationResult> ValidateAsync(IFormFile file, CancellationToken token)
public sealed class ContentTypeValidationStep : IValidationStep
{
private readonly SupportedContentTypes _supportedContentTypes;
private readonly ILogger _logger;
public ContentTypeValidationStep(SupportedContentTypes supportedContentTypes, ILogger logger)
{
_supportedContentTypes = supportedContentTypes;
_logger = logger;
}
public interface IValidationStep
{
Task<ValidationResult> ValidateAsync(IFormFile file, CancellationToken token);
}
var agent = new ChatCompletionAgent
{
Name = "TravelAgent",
Description = "A travel agent that helps users find good travel locations",
Instructions = "Help users to find the perfect holiday location.",
Kernel = kernel
};
var chatHistory = new List<ChatMessage>();
// Minimal API for chat
app.MapPost("/api/chat", async (HttpContext context) =>
{
//Use the IChatClient instance from Semantic Kernel
var chatClient=kernel.GetRequiredService<IChatClient>();
var requestBody = await context.Request.ReadFromJsonAsync<ChatRequest>();
if (requestBody == null || string.IsNullOrWhiteSpace(requestBody.Message))
{
var kernelBuilder = Kernel.CreateBuilder();
// Add your IChatClient
var chatClient = new OllamaApiClient("http://localhost:11434");
chatClient.SelectedModel = "llama3.1:latest";
kernelBuilder.Services.AddChatClient(sp =>
{
var client = new ChatClientBuilder(chatClient)
.UseFunctionInvocation()
internal class PrimeService
{
public bool IsPrime(int possiblePrimeNumber)
{
if (possiblePrimeNumber <= 1)
return false;
for (int i = 2; i <= (int)Math.Sqrt(possiblePrimeNumber); i++)
{
if (possiblePrimeNumber % i == 0)
internal class prime_Service
{
public bool isPrime(int possible_prime_number)
{
if (possible_prime_numbe <= 1)
return false;
for (int i = 2; i <= (int)Math.Sqrt(possible_prime_numbe); i++)
{
if (possible_prime_numbe % i == 0)
public bool IsPrime(int num)
{
if (num <= 1)
return false;
for (int i = 2; i <= (int)Math.Sqrt(num); i++)
{
if (num % i == 0)
return false;
}
return true;
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True