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

Method sendOutputToAI

cli/cli_commands.go:216–257  ·  view source on GitHub ↗

sendOutputToAI envia o output do comando para a IA com o contexto adicional

(output string, aiContext string)

Source from the content-addressed store, hash-verified

214
215// sendOutputToAI envia o output do comando para a IA com o contexto adicional
216func (cli *ChatCLI) sendOutputToAI(output string, aiContext string) {
217 fmt.Println(i18n.T("command.sending_to_ai"))
218
219 safeOutput := utils.SanitizeSensitiveText(output)
220 safeContext := utils.SanitizeSensitiveText(aiContext)
221
222 // Adicionar o output do comando ao histórico como mensagem do usuário
223 cli.history = append(cli.history, models.Message{
224 Role: "user",
225 Content: fmt.Sprintf("Saída do comando:\n%s\n\nContexto: %s", safeOutput, safeContext),
226 })
227 // Exibir mensagem "Pensando..." com animação
228 cli.animation.ShowThinkingAnimation(cli.Client.GetModelName())
229
230 //Criar um contexto com timeout
231 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
232 defer cancel()
233
234 //Enviar o output e o contexto para a IA
235 aiResponse, err := cli.Client.SendPrompt(ctx, fmt.Sprintf("Saída do comando:\n%s\n\nContexto: %s", safeOutput, safeContext), cli.history, 0)
236
237 //parar a animação
238 cli.animation.StopThinkingAnimation()
239
240 if err != nil {
241 cli.logger.Error("Erro do LLM", zap.Error(err))
242 fmt.Println(i18n.T("command.error.processing_request"))
243 return
244 }
245
246 // Adicionar a resposta da IA ao histórico
247 cli.history = append(cli.history, models.Message{
248 Role: "assistant",
249 Content: aiResponse,
250 })
251
252 // Renderizar a resposta da IA
253 renderResponse := cli.renderMarkdown(aiResponse)
254
255 // Exibir a resposta da IA com efeito de digitação
256 cli.typewriterEffect(fmt.Sprintf("\n%s:\n%s\n", cli.Client.GetModelName(), renderResponse), 2*time.Millisecond)
257}

Callers 1

executeDirectCommandMethod · 0.95

Calls 9

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

Tested by

no test coverage detected