using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using static AiAgent.Core.Constant.ProgramConstants; namespace AiAgent.Core.Infrastructure; public class QueryWithoutFileUploads { public async static Task QueryAI(string model, string promptFile, List inputDataFiles, string outputFile, bool appendToOutput = false) { var stopwatch = Stopwatch.StartNew(); var prompt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, promptFile)); Console.Write($"\nCalling AI with prompt from '{promptFile}' and input data from '{string.Join(";", inputDataFiles)}': "); // Create a prompt with the files attached for models I cannot pass files to directly var inputData = ""; if (inputDataFiles.Any()) { inputData += "\n\n\n"; string line = new('-', 80); string fileDelimiter = new('=', 80); inputData = $"\n\n{line}\nAttached Files\n{line}"; foreach (var inputDataFile in inputDataFiles) { string coreName = inputDataFile.Split('\\').Last(); if (File.Exists(inputDataFile) is false) throw new FileNotFoundException($"Input data file '{inputDataFile}' not found in '{AppDomain.CurrentDomain.BaseDirectory}'"); inputData += $"\n\n{fileDelimiter}\nStart of File: {coreName}\n{fileDelimiter}\n\n"; inputData += File.ReadAllText(inputDataFile); inputData += $"\n\n{fileDelimiter}\nEnd of File: {coreName}\n{fileDelimiter}\n\n\n\n"; } } string fullPromp = prompt + inputData; string fullPromptFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, promptFile.Replace("Input\\", "Archive\\") + " - Including Input Files.txt"); File.WriteAllText(fullPromptFile, fullPromp); var cleanModel = model.Split('/').Last(); // Now we can call the appropriate model var response = model switch { var m when m.Contains("gemini/") => await GeminiApiClient.Query(prompt, promptFile, model, inputDataFiles), var m when m.Contains("deepseek/") => await DeepseekApiClient.QueryDeepseekApiAsyncQuery(fullPromp, promptFile, cleanModel), var m when m.Contains("grok/") => await GrokClient.Query(fullPromp), _ => throw new NotSupportedException($"Model '{model}' is not supported.") }; var outputFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, outputFile); if (appendToOutput) File.AppendAllText(outputFilePath, "\n\n" + response); else File.WriteAllText(outputFilePath, response); if (File.Exists(QueryLog) is false) await File.AppendAllTextAsync(QueryLog, $"Date Time,Model,Prompt File,Response Length,Ellapsed Seconds,Ellapsed Minutes\n"); await File.AppendAllTextAsync(QueryLog, $"{DateTime.Now},\"{model}\",\"{promptFile}\",{response.Length},{stopwatch.Elapsed.TotalSeconds},{stopwatch.Elapsed.TotalMinutes:F3}\n"); Console.Write($", Completed"); return response; } }