Skip to main content

Overview

Chapi Assistant integrates AI capabilities powered by Microsoft.Extensions.AI to provide intelligent assistance throughout your development workflow. Get AI-generated commit messages, SQL queries, and conversational help.
AI features use the IChatClient interface from Microsoft.Extensions.AI, supporting multiple AI providers including Gemini.

AI-Generated Commit Messages

Automatic Commit Messages from Diff

Generate meaningful commit messages based on your code changes:
var result = await generateCommitMessageUseCase.ExecuteAsync(
    diffContent: gitDiffOutput
);

if (result.IsSuccess)
{
    string message = result.Value;
    // Example: "Add customer validation and update repository interface"
}
Generate a commit message from staged changes:
// 1. Get the diff of staged changes
var diff = await gitRepository.GetStagedDiffAsync(projectPath);

// 2. Generate commit message
var result = await generateCommitMessageUseCase.ExecuteAsync(diff);

if (result.IsSuccess)
{
    // 3. Use the generated message
    var commitRequest = new CommitRequest
    {
        ProjectPath = projectPath,
        Message = result.Value,
        Files = stagedFiles
    };

    await commitChangesUseCase.ExecuteAsync(commitRequest);
}

How It Works

1

Analyze Diff

The AI analyzes the git diff to understand what changed.
2

Identify Intent

Determines the purpose: feature, fix, refactor, docs, etc.
3

Generate Message

Creates a concise, conventional commit message.
4

Return Result

Returns the message trimmed and ready to use.
Generated messages follow conventional commit format and best practices.

SQL Query Generation

Generate SQL from Natural Language

Create SQL queries by describing what you need:
var result = await generateSqlQueryUseCase.ExecuteAsync(
    description: "Get all active customers who made purchases in the last 30 days",
    schema: customerSchema,
    netParams: "@Days int = 30"
);

if (result.IsSuccess)
{
    string sqlQuery = result.Value;
    // Generated SQL ready to use
}
Generate a simple query:
var result = await generateSqlQueryUseCase.ExecuteAsync(
    description: "Select all customers ordered by name"
);

// Output:
// SELECT * FROM Customers ORDER BY Name;

Parameters

description
string
required
Natural language description of the SQL query you need.
schema
string
Database schema information (table and column names) for context.
netParams
string
.NET parameter definitions to include in the query.

Error Handling

if (!result.IsSuccess)
{
    switch (result.Error)
    {
        case "La descripción de la consulta no puede estar vacía":
            // Empty description
            break;
        case "No se pudo generar la consulta SQL":
            // AI generation failed
            break;
        default:
            // Other errors (network, AI service, etc.)
            Console.WriteLine($"Error: {result.Error}");
            break;
    }
}

Interactive Chat Assistant

Conversational AI Help

Get contextual help and answers during development:
var result = await sendChatMessageUseCase.ExecuteAsync(
    userMessage: "How do I implement repository pattern in this project?",
    context: projectStructureInfo
);

if (result.IsSuccess)
{
    string response = result.Value;
    Console.WriteLine(response);
}
Ask questions without additional context:
var result = await sendChatMessageUseCase.ExecuteAsync(
    userMessage: "What is dependency injection?"
);

if (result.IsSuccess)
{
    Console.WriteLine(result.Value);
}

Use Cases for Chat

Architecture Questions

Ask about design patterns, project structure, and architectural decisions.

Code Explanation

Understand complex code, libraries, or framework features.

Best Practices

Learn recommended approaches for specific scenarios.

Debugging Help

Get assistance troubleshooting errors and exceptions.

API Guidance

Learn how to use libraries, NuGet packages, or APIs.

Refactoring Advice

Get suggestions for improving code quality and structure.

AI Provider Configuration

Chapi uses Microsoft.Extensions.AI abstraction, supporting multiple providers:
// Example: Configured in DI container
services.AddSingleton<IChatClient>(sp => 
    new GeminiChatClient(apiKey, modelName)
);

// All AI use cases use the same abstraction
services.AddScoped<GenerateCommitMessageUseCase>();
services.AddScoped<GenerateSqlQueryUseCase>();
services.AddScoped<SendChatMessageUseCase>();
The implementation uses prompts from GetPrompt helper class for consistent, optimized results.

Prompt Engineering

Chapi uses specialized prompts for each AI feature:
GetPrompt.GitCommit(diffContent)
Optimized to:
  • Analyze code changes semantically
  • Use conventional commit format
  • Keep messages concise
  • Focus on “why” not “what”
GetPrompt.GenerateSqlCall(description, schema, netParams)
Designed to:
  • Understand natural language queries
  • Use provided schema accurately
  • Include .NET parameters correctly
  • Generate optimized, readable SQL
Chat messages use direct user input with optional context injection:
var prompt = context != null 
    ? $"{context}\n\nUsuario: {userMessage}"
    : userMessage;

Error Handling & Validation

var result = await generateCommitMessageUseCase.ExecuteAsync(diff);

if (!result.IsSuccess)
{
    // "No hay cambios para generar mensaje"
    // "No se pudo generar el mensaje de commit"
    // "Error generando mensaje: {exception}"
    HandleError(result.Error);
}

Best Practices

  • Stage meaningful, related changes together
  • Review and edit generated messages as needed
  • Use when diff is clear and focused
  • Combine small commits into logical units before generating
  • Provide clear, specific descriptions
  • Include schema information for complex queries
  • Review generated SQL before execution
  • Test queries on sample data first
  • Use for learning and prototyping, validate for production
  • Provide relevant context for better responses
  • Ask specific questions
  • Include code snippets when discussing implementation
  • Break complex questions into smaller parts
  • Verify suggestions before implementing
  • AI operations require network calls (may take 1-5 seconds)
  • Cache or reuse results when appropriate
  • Handle errors gracefully for offline scenarios
  • Consider rate limits from AI providers

Response Quality

Expected quality:
  • ✅ Follows conventional commit format
  • ✅ Concise (50-72 characters typically)
  • ✅ Describes purpose, not implementation
  • ✅ Uses imperative mood
Example outputs:
  • “Add customer validation to registration form”
  • “Fix null reference in order processing”
  • “Refactor repository pattern implementation”

Git Management

Use AI-generated commit messages in your Git workflow

Code Generation

Combine AI assistance with automated code generation

Build docs developers (and LLMs) love