(ctx context.Context, client *cloudquery_api.ClientWithResponses, teamName string, resumeConversation bool)
| 174 | } |
| 175 | |
| 176 | func aiCmdInner(ctx context.Context, client *cloudquery_api.ClientWithResponses, teamName string, resumeConversation bool) error { |
| 177 | aiMuted.Println(`Your conversation with the AI may be recorded for quality assurance purposes. If you prefer not to use AI-assisted setup, run cloudquery init --disable-ai.`) |
| 178 | fmt.Println() |
| 179 | aiSuccess.Println("🤖 CloudQuery AI Assistant") |
| 180 | fmt.Println("I'm here to help you set up CloudQuery syncs!") |
| 181 | fmt.Println("Type 'exit' or 'quit' to end the conversation.") |
| 182 | fmt.Println() |
| 183 | if resumeConversation { |
| 184 | fmt.Println("Your conversation has been resumed. You can now generate the config or ask questions about your sync.") |
| 185 | } else { |
| 186 | fmt.Println("What are you trying to build with CloudQuery?") |
| 187 | } |
| 188 | fmt.Println() |
| 189 | |
| 190 | scanner := bufio.NewScanner(os.Stdin) |
| 191 | |
| 192 | for { |
| 193 | fmt.Print(aiInfo.Sprint("You: ")) |
| 194 | if !scanner.Scan() { |
| 195 | break |
| 196 | } |
| 197 | if err := scanner.Err(); err != nil { |
| 198 | return err |
| 199 | } |
| 200 | |
| 201 | userInput := strings.TrimSpace(scanner.Text()) |
| 202 | if userInput == "" { |
| 203 | continue |
| 204 | } |
| 205 | |
| 206 | // Check for exit commands |
| 207 | if strings.ToLower(userInput) == "exit" || strings.ToLower(userInput) == "quit" { |
| 208 | break |
| 209 | } |
| 210 | |
| 211 | // Show spinner while waiting for API response |
| 212 | stop := startSpinner(ctx, generalMessages) |
| 213 | |
| 214 | response, err := api.Chat(ctx, client, teamName, &userInput, &[]api.FunctionCallOutput{}) |
| 215 | stop() // Stop the spinner |
| 216 | |
| 217 | if err != nil { |
| 218 | return fmt.Errorf("failed to chat: %w", err) |
| 219 | } |
| 220 | for response.FunctionCall != nil { |
| 221 | switch *response.FunctionCall { |
| 222 | case "create_spec_file": |
| 223 | err := createSpecFile(response.FunctionCallArguments["filename_without_extension"].(string), response.FunctionCallArguments["content"].(string)) |
| 224 | if err != nil { |
| 225 | return fmt.Errorf("failed to create spec file: %w", err) |
| 226 | } |
| 227 | |
| 228 | // Show spinner while waiting for API response after creating spec file |
| 229 | stop := startSpinner(ctx, specFileMessages) |
| 230 | |
| 231 | response, err = api.Chat(ctx, client, teamName, lo.ToPtr(""), &[]api.FunctionCallOutput{ |
| 232 | { |
| 233 | Name: "create_spec_file", |
no test coverage detected