Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/bennyscash1_comprehensiveplayrightauto.json
T

1 line
13 KiB
JSON
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "bennyscash1/comprehensiveplayrightauto", "files": {"Infra/AiService/AiSystemService.cs": {"7b3bcfd677b96edc6c6642373787cf0f3dd65c89": {"t": 1785746208.9552548, "n": 6464, "h": "d59f23ea5c296418", "c": "using ComprehensivePlayrightAuto.Infra.OpenAi;\nusing Newtonsoft.Json;\nusing OpenAI.Chat;\nusing System.Text;\nusing System.Text.Json;\nusing static ComprehensivePlayrightAuto.Infra.OpenAi.AiSystemPrompts;\n\nnamespace SafeCash.Test.ApiTest.Integration.OpenAi\n{\n public class AiSystemService\n {\n #region OpenAiServiceRequest\n AiSystemPrompts aiSystemPrompts = new AiSystemPrompts();\n\n public async Task<string> OpenAiServiceRequest(string userPrompts, SystemPromptTypeEnum systemPrompt)\n {\n string model = AiSystemPrompts.openAiModel;\n string prePrompt = aiSystemPrompts.GetSystemPrompt(systemPrompt);\n\n string apiKey = Environment.GetEnvironmentVariable(\"OPENAI_API_KEY\") ?? throw new InvalidOperationException(\"API key is missing from environment variables.\");\n string apiResponce = \"An error occurred or no response was returned.\";\n //string combinedPrompt = $\"{prePrompt}\\n\\n{userPrompts}\";\n try\n {\n ChatClient client = new ChatClient(model, apiKey);\n\n var openAiRequest = new\n {\n model = model,\n messages = new[]\n {\n new { role = \"system\", content = prePrompt },\n new { role = \"user\", content = userPrompts }\n }\n };\n string jsonBody = JsonConvert.SerializeObject(openAiRequest, Formatting.Indented);\n\n UserChatMessage message = new UserChatMessage(jsonBody);\n ChatCompletion completion = await client.CompleteChatAsync(message);\n\n if (completion?.Content != null && completion.Content.Count > 0)\n {\n apiResponce = completion.Content[0].Text;\n\n }\n else\n {\n apiResponce = \"No valid content found in the response.\";\n }\n Console.WriteLine(\"after ai\");\n\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n }\n\n return apiResponce;\n }\n\n #endregion\n\n #region Grok ai request\n public async Task<string> GrokRequestService(string userMessage, SystemPromptTypeEnum aiRequest)\n {\n string grokUrl = \"https://api.x.ai/v1/chat/completions\";\n string apiGrokKey = Environment.GetEnvironmentVariable(\"GROK_API_KEY\") ?? throw new InvalidOperationException(\"API key is missing from environment variables.\");\n\n using (HttpClient client = new HttpClient())\n {\n string aiPrePromptType = aiSystemPrompts.GetSystemPrompt(aiRequest);\n\n client.DefaultRequestHeaders.Add(\"Authorization\", $\"Bearer {apiGrokKey}\");\n\n var requestBody = new\n {\n messages = new[]\n {\n new { role = \"system\", content = aiPrePromptType },\n new { role = \"user\", content = userMessage }\n },\n model = \"grok-3-mini-fast-latest\",\n stream = false,\n temperature = 0\n };\n\n var jsonContent = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, \"application/json\");\n HttpResponseMessage response = await client.PostAsync(grokUrl, jsonContent);\n\n if (response.IsSuccessStatusCode)\n {\n string jsonResponse = await response.Content.ReadAsStringAsync();\n\n // ✅ Extract only the \"content\" field from the response\n using JsonDocument doc = JsonDocument.Parse(jsonResponse);\n\n if (doc.RootElement.TryGetProperty(\"choices\", out JsonElement choicesArray) &&\n choicesArray.GetArrayLength() > 0 &&\n choicesArray[0].TryGetProperty(\"message\", out JsonElement message) &&\n message.TryGetProperty(\"content\", out JsonElement contentElement))\n {\n return contentElement.GetString() ?? \"No content available.\";\n }\n\n return \"Invalid response format.\";\n }\n else\n {\n return $\"Error: {response.StatusCode} - {response.ReasonPhrase}\";\n }\n }\n }\n #endregion\n\n #region Deep seek ai request\n private readonly HttpClient _httpClient = new HttpClient();\n\n public async Task<string> DeepSeekResponceAi(string userPrompts, SystemPromptTypeEnum aiRequest)\n {\n string apiUrl = \"https://api.deepseek.com/chat/completions\"; // Replace with actual API URL\n string bearerToken = \"sk-5706d7050b8c4bddb967ba236538d89d\"; // Replace with actual token\n string prePrompt = aiSystemPrompts.GetSystemPrompt(aiRequest);\n var requestBody = new\n {\n model = \"deepseek-chat\",\n messages = new[]\n {\n new { role = \"system\", content = prePrompt },\n new { role = \"user\", content = userPrompts }\n },\n stream = false\n };\n\n string jsonRequest = System.Text.Json.JsonSerializer.Serialize(requestBody);\n var content = new StringContent(jsonRequest, Encoding.UTF8, \"application/json\"); // ✅ \"Content-Type\" set correctly here\n\n var request = new HttpRequestMessage(HttpMethod.Post, apiUrl)\n {\n Content = content\n };\n\n request.Headers.Add(\"Authorization\", $\"Bearer {bearerToken}\"); // ✅ Correct place for Authorization\n // No need to add \"Content-Type\" again here\n\n HttpResponseMessage response = await _httpClient.SendAsync(request);\n string jsonResponse = await response.Content.ReadAsStringAsync();\n\n using JsonDocument doc = JsonDocument.Parse(jsonResponse);\n\n string? contentResponce = doc.RootElement\n .GetProperty(\"choices\")[0]\n .GetProperty(\"message\")\n .GetProperty(\"content\")\n .GetString();\n\n return contentResponce;\n }\n #endregion\n }\n}\n"}, "f435ed47aa838e60b131c98d2ecf2a55d5089636": {"t": 1785760632.8657718, "n": 6464, "h": "d59f23ea5c296418", "c": "using ComprehensivePlayrightAuto.Infra.OpenAi;\nusing Newtonsoft.Json;\nusing OpenAI.Chat;\nusing System.Text;\nusing System.Text.Json;\nusing static ComprehensivePlayrightAuto.Infra.OpenAi.AiSystemPrompts;\n\nnamespace SafeCash.Test.ApiTest.Integration.OpenAi\n{\n public class AiSystemService\n {\n #region OpenAiServiceRequest\n AiSystemPrompts aiSystemPrompts = new AiSystemPrompts();\n\n public async Task<string> OpenAiServiceRequest(string userPrompts, SystemPromptTypeEnum systemPrompt)\n {\n string model = AiSystemPrompts.openAiModel;\n string prePrompt = aiSystemPrompts.GetSystemPrompt(systemPrompt);\n\n string apiKey = Environment.GetEnvironmentVariable(\"OPENAI_API_KEY\") ?? throw new InvalidOperationException(\"API key is missing from environment variables.\");\n string apiResponce = \"An error occurred or no response was returned.\";\n //string combinedPrompt = $\"{prePrompt}\\n\\n{userPrompts}\";\n try\n {\n ChatClient client = new ChatClient(model, apiKey);\n\n var openAiRequest = new\n {\n model = model,\n messages = new[]\n {\n new { role = \"system\", content = prePrompt },\n new { role = \"user\", content = userPrompts }\n }\n };\n string jsonBody = JsonConvert.SerializeObject(openAiRequest, Formatting.Indented);\n\n UserChatMessage message = new UserChatMessage(jsonBody);\n ChatCompletion completion = await client.CompleteChatAsync(message);\n\n if (completion?.Content != null && completion.Content.Count > 0)\n {\n apiResponce = completion.Content[0].Text;\n\n }\n else\n {\n apiResponce = \"No valid content found in the response.\";\n }\n Console.WriteLine(\"after ai\");\n\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n }\n\n return apiResponce;\n }\n\n #endregion\n\n #region Grok ai request\n public async Task<string> GrokRequestService(string userMessage, SystemPromptTypeEnum aiRequest)\n {\n string grokUrl = \"https://api.x.ai/v1/chat/completions\";\n string apiGrokKey = Environment.GetEnvironmentVariable(\"GROK_API_KEY\") ?? throw new InvalidOperationException(\"API key is missing from environment variables.\");\n\n using (HttpClient client = new HttpClient())\n {\n string aiPrePromptType = aiSystemPrompts.GetSystemPrompt(aiRequest);\n\n client.DefaultRequestHeaders.Add(\"Authorization\", $\"Bearer {apiGrokKey}\");\n\n var requestBody = new\n {\n messages = new[]\n {\n new { role = \"system\", content = aiPrePromptType },\n new { role = \"user\", content = userMessage }\n },\n model = \"grok-3-mini-fast-latest\",\n stream = false,\n temperature = 0\n };\n\n var jsonContent = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, \"application/json\");\n HttpResponseMessage response = await client.PostAsync(grokUrl, jsonContent);\n\n if (response.IsSuccessStatusCode)\n {\n string jsonResponse = await response.Content.ReadAsStringAsync();\n\n // ✅ Extract only the \"content\" field from the response\n using JsonDocument doc = JsonDocument.Parse(jsonResponse);\n\n if (doc.RootElement.TryGetProperty(\"choices\", out JsonElement choicesArray) &&\n choicesArray.GetArrayLength() > 0 &&\n choicesArray[0].TryGetProperty(\"message\", out JsonElement message) &&\n message.TryGetProperty(\"content\", out JsonElement contentElement))\n {\n return contentElement.GetString() ?? \"No content available.\";\n }\n\n return \"Invalid response format.\";\n }\n else\n {\n return $\"Error: {response.StatusCode} - {response.ReasonPhrase}\";\n }\n }\n }\n #endregion\n\n #region Deep seek ai request\n private readonly HttpClient _httpClient = new HttpClient();\n\n public async Task<string> DeepSeekResponceAi(string userPrompts, SystemPromptTypeEnum aiRequest)\n {\n string apiUrl = \"https://api.deepseek.com/chat/completions\"; // Replace with actual API URL\n string bearerToken = \"sk-5706d7050b8c4bddb967ba236538d89d\"; // Replace with actual token\n string prePrompt = aiSystemPrompts.GetSystemPrompt(aiRequest);\n var requestBody = new\n {\n model = \"deepseek-chat\",\n messages = new[]\n {\n new { role = \"system\", content = prePrompt },\n new { role = \"user\", content = userPrompts }\n },\n stream = false\n };\n\n string jsonRequest = System.Text.Json.JsonSerializer.Serialize(requestBody);\n var content = new StringContent(jsonRequest, Encoding.UTF8, \"application/json\"); // ✅ \"Content-Type\" set correctly here\n\n var request = new HttpRequestMessage(HttpMethod.Post, apiUrl)\n {\n Content = content\n };\n\n request.Headers.Add(\"Authorization\", $\"Bearer {bearerToken}\"); // ✅ Correct place for Authorization\n // No need to add \"Content-Type\" again here\n\n HttpResponseMessage response = await _httpClient.SendAsync(request);\n string jsonResponse = await response.Content.ReadAsStringAsync();\n\n using JsonDocument doc = JsonDocument.Parse(jsonResponse);\n\n string? contentResponce = doc.RootElement\n .GetProperty(\"choices\")[0]\n .GetProperty(\"message\")\n .GetProperty(\"content\")\n .GetString();\n\n return contentResponce;\n }\n #endregion\n }\n}\n"}}}}