{"repo": "andran20/ai-playground", "files": {"AiPlayground.BusinessLogic/AIProcessing/Processors/DeepseekProcessor.cs": {"50f6135722de1208928656aa4cdb316632dec2f3": {"t": 1785745820.1349843, "n": 3613, "h": "4538f4e6face4a8e", "c": "using AiPlayground.BusinessLogic.AIProcessing.Models.DeepSeek;\nusing AiPlayground.BusinessLogic.Services;\nusing AiPlayground.DataAccess.Entities;\nusing System.Diagnostics;\nusing System.Net.Http.Headers;\nusing System.Text.Json;\n\n\nnamespace AiPlayground.BusinessLogic.AIProcessing.Processors\n{\n public class DeepseekProcessor : IAIProcessor\n {\n private readonly RatingService _ratingService;\n public DeepseekProcessor(RatingService ratingService)\n {\n _ratingService = ratingService;\n }\n public async Task ProcessAsync(Prompt prompt, Model model, float temperature)\n {\n var apiKey = Environment.GetEnvironmentVariable(\"DEEPSEEK_API_KEY\");\n if (string.IsNullOrEmpty(apiKey))\n {\n throw new Exception(\"Deepseek API key is not set.\");\n }\n var requestURL = \"https://api.deepseek.com/chat/completions\";\n var client = new HttpClient();\n\n client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(\"Bearer\", apiKey);\n\n var content = new DeepSeekRequest\n {\n Model = model.Name,\n Messages =\n [\n new DeepSeekMessage\n {\n Role = \"system\",\n Content = prompt.SystemMessage\n },\n new DeepSeekMessage\n {\n\n Role = \"user\",\n Content = prompt.UserMessage\n }\n ],\n Temperature = temperature,\n Stream = false,\n };\n\n var jsonContent = JsonSerializer.Serialize(content, new JsonSerializerOptions\n {\n PropertyNamingPolicy = JsonNamingPolicy.CamelCase\n });\n\n var httpContent = new StringContent(jsonContent, System.Text.Encoding.UTF8, \"application/json\");\n\n try\n {\n var stopwatch = new Stopwatch();\n stopwatch.Start();\n\n var response = await client.PostAsync(requestURL, httpContent);\n\n stopwatch.Stop();\n var elapsed_time = stopwatch.Elapsed.TotalSeconds;\n\n var responseContent = await response.Content.ReadAsStringAsync();\n var deepSeekResponse = JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions {\n PropertyNamingPolicy = JsonNamingPolicy.CamelCase \n });\n\n\n if (deepSeekResponse != null)\n {\n var final_rating = await _ratingService.CalculateFinalRatingAsync(prompt.ExpectedResult, deepSeekResponse.Choices.First().Message.Content, elapsed_time,prompt.SystemMessage);\n Debug.WriteLine($\"Final rating is {final_rating}\");\n\n return new Run\n {\n ModelId = model.Id,\n PromptId = prompt.Id,\n ActualResponse = deepSeekResponse.Choices.First().Message.Content,\n Temperature = temperature,\n Rating = final_rating,\n UserRating = 0\n };\n }\n else\n { throw new Exception(\"DeepSeek response is null\"); }\n }\n catch (Exception ex)\n {\n throw new Exception($\"Error processing deepseek request: {ex.Message}\");\n }\n\n }\n }\n}\n"}, "77fab638b71e5bfb99144b7d9b3bc3a8820af276": {"t": 1785756804.4801922, "n": 3607, "h": "cb72d7136eb57e69", "c": "using AiPlayground.BusinessLogic.AIProcessing.Models.DeepSeek;\nusing AiPlayground.BusinessLogic.Services;\nusing AiPlayground.DataAccess.Entities;\nusing System.Diagnostics;\nusing System.Net.Http.Headers;\nusing System.Text.Json;\n\n\nnamespace AiPlayground.BusinessLogic.AIProcessing.Processors\n{\n public class DeepseekProcessor : IAIProcessor\n {\n private readonly RatingService _ratingService;\n public DeepseekProcessor(RatingService ratingService)\n {\n _ratingService = ratingService;\n }\n public async Task ProcessAsync(Prompt prompt, Model model, float temperature)\n {\n var apiKey = Environment.GetEnvironmentVariable(\"DEEPSEEK_API_KEY\");\n if (string.IsNullOrEmpty(apiKey))\n {\n throw new Exception(\"Deepseek API key is not set.\");\n }\n var requestURL = \"https://api.deepseek.com/chat/completions\";\n var client = new HttpClient();\n\n client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(\"Bearer\", apiKey);\n\n var content = new DeepSeekRequest\n {\n Model = model.Name,\n Messages =\n [\n new DeepSeekMessage\n {\n Role = \"system\",\n Content = prompt.SystemMsg\n },\n new DeepSeekMessage\n {\n\n Role = \"user\",\n Content = prompt.UserMessage\n }\n ],\n Temperature = temperature,\n Stream = false,\n };\n\n var jsonContent = JsonSerializer.Serialize(content, new JsonSerializerOptions\n {\n PropertyNamingPolicy = JsonNamingPolicy.CamelCase\n });\n\n var httpContent = new StringContent(jsonContent, System.Text.Encoding.UTF8, \"application/json\");\n\n try\n {\n var stopwatch = new Stopwatch();\n stopwatch.Start();\n\n var response = await client.PostAsync(requestURL, httpContent);\n\n stopwatch.Stop();\n var elapsed_time = stopwatch.Elapsed.TotalSeconds;\n\n var responseContent = await response.Content.ReadAsStringAsync();\n var deepSeekResponse = JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions {\n PropertyNamingPolicy = JsonNamingPolicy.CamelCase \n });\n\n\n if (deepSeekResponse != null)\n {\n var final_rating = await _ratingService.CalculateFinalRatingAsync(prompt.ExpectedResponse, deepSeekResponse.Choices.First().Message.Content, elapsed_time,prompt.SystemMsg);\n Debug.WriteLine($\"Final rating is {final_rating}\");\n\n return new Run\n {\n ModelId = model.Id,\n PromptId = prompt.Id,\n ActualResponse = deepSeekResponse.Choices.First().Message.Content,\n Temperature = temperature,\n Rating = final_rating,\n UserRating = 0\n };\n }\n else\n { throw new Exception(\"DeepSeek response is null\"); }\n }\n catch (Exception ex)\n {\n throw new Exception($\"Error processing deepseek request: {ex.Message}\");\n }\n\n }\n }\n}\n"}}}}