Files
ai-code-assistant/cmd/chunks/chunks.go
Michael Powers 25f8cae8cb Code Cleanup and Quality of Life
Checks to make sure repo is indexed before generating code.
Don't generate tests for changes to tests.
Remove unused code.
Fix bootstrapping issue with langchaingo tables.
2025-04-20 08:31:26 -04:00

60 lines
1.3 KiB
Go

package chunks
import (
"ai-code-assistant/pkg/database"
"ai-code-assistant/pkg/llm"
"context"
"github.com/urfave/cli/v3"
"log/slog"
)
func Command() *cli.Command {
return &cli.Command{
Name: "chunks",
Usage: "this command tries to find relevant chunks of code in a git repository for a given query",
Action: (&chunks{}).run,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Usage: "path to git repository",
Required: true,
},
&cli.StringFlag{
Name: "query",
Usage: "query to search for",
Required: true,
},
&cli.IntFlag{
Name: "docs",
Usage: "number of docs to get",
Value: 10,
},
},
}
}
type chunks struct {
}
func (c *chunks) run(ctx context.Context, cmd *cli.Command) error {
db := database.FromContext(ctx)
llmRef := llm.FromContext(ctx)
repoID, _, err := db.UpsertRepo(ctx, cmd.String("repo"))
if err != nil {
return err
}
relDocs := llm.NewGetRelevantDocs(db, llmRef, repoID, int(cmd.Int("docs")))
chunks, err := relDocs.GetRelevantFileChunks(ctx, cmd.String("query"))
if err != nil {
return err
}
for _, chunk := range chunks {
slog.Info("found relevant chunk", "name", chunk.Name, "start", chunk.Start, "end", chunk.End, "score", chunk.Score, "id", chunk.ChunkID)
}
return nil
}