-
Notifications
You must be signed in to change notification settings - Fork 4
Open AI integrated #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open AI integrated #135
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||||||||||
| using System.Net.Http.Headers; | ||||||||||||||||||||||||||||||||||||
| using System.Text; | ||||||||||||||||||||||||||||||||||||
| using System.Text.Json; | ||||||||||||||||||||||||||||||||||||
| using Infrastructure.Jwt; | ||||||||||||||||||||||||||||||||||||
| using Infrastructure.Services.OpenAi.Custom.Models; | ||||||||||||||||||||||||||||||||||||
| using Microsoft.Extensions.Configuration; | ||||||||||||||||||||||||||||||||||||
| using Microsoft.Extensions.Logging; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| namespace Infrastructure.Services.OpenAi.Custom; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public class CustomOpenAiService : ICustomOpenAiService | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| private readonly IHttpClientFactory _httpClientFactory; | ||||||||||||||||||||||||||||||||||||
| private readonly IConfiguration _configuration; | ||||||||||||||||||||||||||||||||||||
| private readonly ILogger<CustomOpenAiService> _logger; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public CustomOpenAiService( | ||||||||||||||||||||||||||||||||||||
| IHttpClientFactory httpClientFactory, | ||||||||||||||||||||||||||||||||||||
| IConfiguration configuration, | ||||||||||||||||||||||||||||||||||||
| ILogger<CustomOpenAiService> logger) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| _httpClientFactory = httpClientFactory; | ||||||||||||||||||||||||||||||||||||
| _configuration = configuration; | ||||||||||||||||||||||||||||||||||||
| _logger = logger; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public string GetBearer() | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var secret = _configuration["OpenAiApiSecret"]; | ||||||||||||||||||||||||||||||||||||
| return new TechinterviewJwtTokenGenerator(secret).ToString(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public async Task<string> GetAnalysisAsync( | ||||||||||||||||||||||||||||||||||||
| OpenAiBodyReport report, | ||||||||||||||||||||||||||||||||||||
| CancellationToken cancellationToken = default) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var apiUrl = _configuration["OpenAiApiUrl"]; | ||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(apiUrl)) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| throw new InvalidOperationException("OpenAI API url is not set"); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var responseContent = string.Empty; | ||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| using var client = _httpClientFactory.CreateClient(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| client.BaseAddress = new Uri(apiUrl); | ||||||||||||||||||||||||||||||||||||
| var request = new HttpRequestMessage(HttpMethod.Post, apiUrl); | ||||||||||||||||||||||||||||||||||||
| request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", GetBearer()); | ||||||||||||||||||||||||||||||||||||
| request.Content = new StringContent( | ||||||||||||||||||||||||||||||||||||
| JsonSerializer.Serialize(report), | ||||||||||||||||||||||||||||||||||||
| Encoding.UTF8, | ||||||||||||||||||||||||||||||||||||
| "application/json"); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix HTTP client usage pattern. Setting using var client = _httpClientFactory.CreateClient();
- client.BaseAddress = new Uri(apiUrl);
- var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
+ var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", GetBearer());📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var response = await client.SendAsync(request, cancellationToken); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| responseContent = await response.Content.ReadAsStringAsync(cancellationToken); | ||||||||||||||||||||||||||||||||||||
| if (response.IsSuccessStatusCode) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| return responseContent; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| _logger.LogError( | ||||||||||||||||||||||||||||||||||||
| "Failed request to OpenAI {Url}. Status {Status}, Response {Response}", | ||||||||||||||||||||||||||||||||||||
| apiUrl, | ||||||||||||||||||||||||||||||||||||
| response.StatusCode, | ||||||||||||||||||||||||||||||||||||
| responseContent); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return string.Empty; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using a Result pattern instead of returning empty string on failure. Returning an empty string on failure makes it difficult for callers to distinguish between an empty successful response and a failure. Consider using a Result pattern or throwing exceptions. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| catch (Exception e) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| _logger.LogError( | ||||||||||||||||||||||||||||||||||||
| e, | ||||||||||||||||||||||||||||||||||||
| "Error while getting OpenAI response from {Url}. Message {Message}. Response {Response}", | ||||||||||||||||||||||||||||||||||||
| apiUrl, | ||||||||||||||||||||||||||||||||||||
| e.Message, | ||||||||||||||||||||||||||||||||||||
| responseContent); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return string.Empty; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using Infrastructure.Services.OpenAi.Custom.Models; | ||
|
|
||
| namespace Infrastructure.Services.OpenAi.Custom; | ||
|
|
||
| public interface ICustomOpenAiService | ||
| { | ||
| string GetBearer(); | ||
|
|
||
| Task<string> GetAnalysisAsync( | ||
| OpenAiBodyReport report, | ||
| CancellationToken cancellationToken = default); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Infrastructure.Services.OpenAi.Models; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Domain.Entities.Companies; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Infrastructure.Services.OpenAi.Models; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Infrastructure.Services.OpenAi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public interface IOpenAiService | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string GetBearer(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Task<OpenAiChatResult> AnalyzeCompanyAsync( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Company company, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string correlationId = null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CancellationToken cancellationToken = default); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Task<string> GetAnalysisAsync( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OpenAiBodyReport report, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Task<OpenAiChatResult> AnalyzeChatAsync( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string input, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string correlationId = null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CancellationToken cancellationToken = default); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing using statement for CancellationToken. The interface is missing using Domain.Entities.Companies;
using Infrastructure.Services.OpenAi.Models;
+using System.Threading;
+using System.Threading.Tasks;
namespace Infrastructure.Services.OpenAi;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Text.Json.Serialization; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Infrastructure.Services.OpenAi.Models; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public record ChatMessage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public ChatMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string role, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Role = role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Content = content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public ChatMessage() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unnecessary parameterless constructor. The parameterless constructor is redundant since records automatically provide one when properties use - public ChatMessage()
- {
- }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [JsonPropertyName("role")] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public string Role { get; set; } // "user", "assistant", or "system" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [JsonPropertyName("content")] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public string Content { get; set; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve immutability, validation, and documentation. The record has several design issues:
Apply this diff to improve the design: +/// <summary>
+/// Represents a chat message with role and content for OpenAI API communication.
+/// </summary>
public record ChatMessage
{
+ private static readonly HashSet<string> ValidRoles = new() { "user", "assistant", "system" };
+
public ChatMessage(
string role,
string content)
{
+ if (string.IsNullOrWhiteSpace(role))
+ throw new ArgumentException("Role cannot be null or empty.", nameof(role));
+ if (!ValidRoles.Contains(role))
+ throw new ArgumentException($"Invalid role '{role}'. Expected: {string.Join(", ", ValidRoles)}", nameof(role));
+ if (string.IsNullOrWhiteSpace(content))
+ throw new ArgumentException("Content cannot be null or empty.", nameof(content));
+
Role = role;
Content = content;
}
- public ChatMessage()
- {
- }
[JsonPropertyName("role")]
- public string Role { get; set; } // "user", "assistant", or "system"
+ public string Role { get; init; } = string.Empty; // "user", "assistant", or "system"
[JsonPropertyName("content")]
- public string Content { get; set; }
+ public string Content { get; init; } = string.Empty;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Infrastructure.Services.OpenAi.Models; | ||
|
|
||
| public record ChatRequest | ||
| { | ||
| [JsonPropertyName("model")] | ||
| public string Model { get; set; } | ||
|
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use For record types, properties should use - public string Model { get; set; }
+ public string Model { get; init; }
- public List<ChatMessage> Messages { get; set; }
+ public List<ChatMessage> Messages { get; init; }
- public double Temperature { get; set; } = 0.7;
+ public double Temperature { get; init; } = 0.7;Additionally, consider adding null-ability annotations: - public string Model { get; init; }
- public List<ChatMessage> Messages { get; init; }
+ public string Model { get; init; } = string.Empty;
+ public List<ChatMessage> Messages { get; init; } = new();Also applies to: 10-11, 13-14 🤖 Prompt for AI Agents |
||
|
|
||
| [JsonPropertyName("messages")] | ||
| public List<ChatMessage> Messages { get; set; } | ||
|
|
||
| [JsonPropertyName("temperature")] | ||
| public double Temperature { get; set; } = 0.7; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||||||||||||||||||||||||
| using System.Text.Json.Serialization; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| namespace Infrastructure.Services.OpenAi.Models; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public record ChatResponse | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| [JsonPropertyName("choices")] | ||||||||||||||||||||||||||||
| public List<Choice> Choices { get; set; } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve immutability and null safety for the data model. The record has several design concerns:
Apply this diff to improve the design: +/// <summary>
+/// Represents a chat response from OpenAI API containing multiple choices.
+/// </summary>
public record ChatResponse
{
[JsonPropertyName("choices")]
- public List<Choice> Choices { get; set; }
+ public IReadOnlyList<Choice> Choices { get; init; } = Array.Empty<Choice>();
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Infrastructure.Services.OpenAi.Models; | ||
|
|
||
| public record Choice | ||
| { | ||
| [JsonPropertyName("message")] | ||
| public ChatMessage Message { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||||||||
| using Domain.Entities.Companies; | ||||||||||||||||
|
|
||||||||||||||||
| namespace Infrastructure.Services.OpenAi.Models; | ||||||||||||||||
|
|
||||||||||||||||
| internal record CompanyAnalyzeRequest | ||||||||||||||||
| { | ||||||||||||||||
| public CompanyAnalyzeRequest( | ||||||||||||||||
| Company company) | ||||||||||||||||
| { | ||||||||||||||||
| Name = company.Name; | ||||||||||||||||
| Rating = company.Rating; | ||||||||||||||||
| RatingHistoryRecords = company.RatingHistory? | ||||||||||||||||
| .Select(history => new CompanyRatingHistoryItem(history)) | ||||||||||||||||
| .ToList(); | ||||||||||||||||
|
|
||||||||||||||||
| Reviews = company.Reviews | ||||||||||||||||
| .Select(x => new CompanyReviewData(x)) | ||||||||||||||||
| .ToList(); | ||||||||||||||||
|
Comment on lines
+12
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add consistent null checking for defensive programming. The code uses null-conditional operator for RatingHistoryRecords = company.RatingHistory?
.Select(history => new CompanyRatingHistoryItem(history))
.ToList();
- Reviews = company.Reviews
+ Reviews = company.Reviews?
.Select(x => new CompanyReviewData(x))
- .ToList();
+ .ToList() ?? new List<CompanyReviewData>();
🤖 Prompt for AI Agents |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public double Rating { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public string Name { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public List<CompanyRatingHistoryItem> RatingHistoryRecords { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public List<CompanyReviewData> Reviews { get; } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| internal record CompanyReviewData | ||||||||||||||||
| { | ||||||||||||||||
| public CompanyReviewData( | ||||||||||||||||
| CompanyReview review) | ||||||||||||||||
| { | ||||||||||||||||
| Pros = review.Pros; | ||||||||||||||||
| Cons = review.Cons; | ||||||||||||||||
| CultureAndValues = review.CultureAndValues; | ||||||||||||||||
| CodeQuality = review.CodeQuality; | ||||||||||||||||
| WorkLifeBalance = review.WorkLifeBalance; | ||||||||||||||||
| Management = review.Management; | ||||||||||||||||
| CompensationAndBenefits = review.CompensationAndBenefits; | ||||||||||||||||
| CareerOpportunities = review.CareerOpportunities; | ||||||||||||||||
| TotalRating = review.TotalRating; | ||||||||||||||||
| LikesCount = review.LikesCount; | ||||||||||||||||
| DislikesCount = review.DislikesCount; | ||||||||||||||||
| TotalRating = review.TotalRating; | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove duplicate TotalRating assignment.
TotalRating = review.TotalRating;
LikesCount = review.LikesCount;
DislikesCount = review.DislikesCount;
- TotalRating = review.TotalRating;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| public string Pros { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public string Cons { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int CultureAndValues { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int? CodeQuality { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int WorkLifeBalance { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int Management { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int CompensationAndBenefits { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int CareerOpportunities { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public double TotalRating { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int LikesCount { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public int DislikesCount { get; } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| internal record CompanyRatingHistoryItem | ||||||||||||||||
| { | ||||||||||||||||
| public CompanyRatingHistoryItem( | ||||||||||||||||
| CompanyRatingHistory history) | ||||||||||||||||
| { | ||||||||||||||||
| CreatedAt = history.CreatedAt; | ||||||||||||||||
| Rating = history.Rating; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public DateTime CreatedAt { get; } | ||||||||||||||||
|
|
||||||||||||||||
| public double Rating { get; } | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Infrastructure.Services.OpenAi.Models; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public record OpenAiChatResult | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static OpenAiChatResult Success(List<Choice> choices) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new OpenAiChatResult(true, choices); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static OpenAiChatResult Failure() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new OpenAiChatResult(false, new List<Choice>()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private OpenAiChatResult( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool isSuccess, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Choice> choices) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IsSuccess = isSuccess; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Choices = choices; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public bool IsSuccess { get; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public List<Choice> Choices { get; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAdd missing using statement and verify Choice dependency. The file is missing the +using System.Collections.Generic;
+
namespace Infrastructure.Services.OpenAi.Models;Let me verify the Choice type exists: 🏁 Script executed: #!/bin/bash
# Description: Check if Choice type is defined in the same namespace
# Expected: Find Choice type definition in Models namespace
rg -A 5 "class Choice|record Choice" --include="*.cs"Length of output: 497 🏁 Script executed: #!/bin/bash
# Description: Check for Choice type definition in C# files
rg -R -n -C5 -E 'record\s+Choice|class\s+Choice' --glob '*.cs'Length of output: 469 🏁 Script executed: #!/bin/bash
# Search for Choice type definitions across C# files
rg -n -C5 -E 'record\s+Choice|class\s+Choice' --glob '*.cs' .Length of output: 131 🏁 Script executed: #!/bin/bash
# Search for Choice type definitions in C# files
find . -type f -name '*.cs' -exec grep -nE 'class[[:space:]]+Choice|record[[:space:]]+Choice' {} +Length of output: 179 Add missing System.Collections.Generic using The Apply this diff: +using System.Collections.Generic;
namespace Infrastructure.Services.OpenAi.Models;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Cache or optimize JWT token generation.
Creating a new
TechinterviewJwtTokenGeneratorinstance on every call is inefficient. Consider caching the generator or the token with appropriate expiration.📝 Committable suggestion
🤖 Prompt for AI Agents