MCPcopy Create free account
hub / github.com/diillson/chatcli / handleRetryLastChunk

Method handleRetryLastChunk

cli/cli_file_processing.go:666–715  ·  view source on GitHub ↗

Novo método para reprocessar o último chunk que falhou

(ctx context.Context)

Source from the content-addressed store, hash-verified

664
665// Novo método para reprocessar o último chunk que falhou
666func (cli *ChatCLI) handleRetryLastChunk(ctx context.Context) bool {
667 if cli.lastFailedChunk == nil || len(cli.failedChunks) == 0 {
668 fmt.Println(i18n.T("chunk.no_failed_to_retry"))
669 return false
670 }
671
672 lastFailedIndex := len(cli.failedChunks) - 1
673 chunk := cli.failedChunks[lastFailedIndex]
674 cli.failedChunks = cli.failedChunks[:lastFailedIndex]
675
676 fmt.Println(i18n.T("chunk.retrying_last_failed", chunk.Index, chunk.Total))
677
678 progressInfo := fmt.Sprintf(i18n.T("chunk.retry_header", chunk.Index, chunk.Total)+"\n"+
679 "=============================\n"+
680 i18n.T("chunk.retry_status_retrying")+"\n"+
681 i18n.T("chunk.progress_pending", len(cli.fileChunks))+"\n"+
682 i18n.T("chunk.retry_status_other_failed", len(cli.failedChunks))+"\n"+
683 "=============================\n\n",
684 chunk.Index, chunk.Total, len(cli.fileChunks), len(cli.failedChunks))
685
686 prompt := i18n.T("chunk.retry_prompt", chunk.Index, chunk.Total)
687
688 cli.history = append(cli.history, models.Message{Role: "user", Content: prompt + "\n\n" + progressInfo + chunk.Content})
689 cli.animation.ShowThinkingAnimation(cli.Client.GetModelName())
690 ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
691 defer cancel()
692 aiResponse, err := cli.Client.SendPrompt(ctx, prompt+"\n\n"+chunk.Content, cli.history, 0)
693 cli.animation.StopThinkingAnimation()
694
695 if err != nil {
696 cli.logger.Error("Erro ao reprocessar chunk com a LLM", zap.Int("chunkIndex", chunk.Index), zap.Error(err))
697 cli.failedChunks = append(cli.failedChunks, chunk)
698 fmt.Println(i18n.T("chunk.retry_error", chunk.Index, chunk.Total, err.Error()))
699 fmt.Println(i18n.T("chunk.retry_remains_failed"))
700 return false
701 }
702
703 cli.history = append(cli.history, models.Message{Role: "assistant", Content: aiResponse})
704 renderedResponse := cli.renderMarkdown(aiResponse)
705 cli.typewriterEffect(fmt.Sprintf("\n%s:\n%s\n", cli.Client.GetModelName(), renderedResponse), 2*time.Millisecond)
706
707 if len(cli.failedChunks) > 0 {
708 cli.lastFailedChunk = &cli.failedChunks[len(cli.failedChunks)-1]
709 } else {
710 cli.lastFailedChunk = nil
711 }
712 fmt.Println(i18n.T("chunk.retry_success"))
713 cli.printChunkStatus()
714 return false
715}
716
717// Método para reprocessar todos os chunks com falha
718func (cli *ChatCLI) handleRetryAllChunks() bool {

Callers 1

buildRoutesMethod · 0.80

Calls 9

renderMarkdownMethod · 0.95
typewriterEffectMethod · 0.95
printChunkStatusMethod · 0.95
TFunction · 0.92
ShowThinkingAnimationMethod · 0.80
StopThinkingAnimationMethod · 0.80
GetModelNameMethod · 0.65
SendPromptMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected