Skip to content

Commit 3ffb8ab

Browse files
committed
Merge branch 'main' into quiz/finance_fix
2 parents 8201d18 + 9ede08d commit 3ffb8ab

44 files changed

Lines changed: 3838 additions & 1782 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88

99
# 📚 Stack Overview
1010

11-
- **React**: UI development
12-
- **Vite**: fast development and builds
13-
- **Yarn**: efficient package management
14-
- **Tailwind CSS && DaisyUI**: easy and flexible styling
15-
16-
# ⚙️ Setup Instructions
11+
- **Frontend**:
12+
- **React**: UI development
13+
- **Vite**: fast development and builds
14+
- **Yarn**: efficient package management
15+
- **Tailwind CSS && DaisyUI**: easy and flexible styling
16+
- **Backend**:
17+
- **C#/.NET**: Backend development
18+
- **Other**:
19+
- **Azure Hosting**
20+
- **Azure SQL Database**
21+
- **Azure AI**
22+
- **Azure Search Index**
23+
24+
# ⚙️ Requirement
1725

1826
1. **Install Node.js**
1927

@@ -58,15 +66,30 @@
5866
- `prettier-plugin-tailwindcss` specifically handles Tailwind CSS classes.
5967

6068
# 🔄 Running
69+
- Frontend host: `http://localhost:5173`
70+
- Backend host: `http://localhost:5252`
6171

62-
- Refresh package (ex. whenever you pull from github):
63-
`yarn` or `yarn install`
72+
- To init/refresh package from root (ex. whenever you pull from github):
73+
`yarn fresh`
6474

6575
- To run front-end from root:
6676
`cd front-end`
6777
`yarn dev`
6878

69-
# 🧪 Testing Front-End
79+
- To run back-end from root:
80+
`cd back-end`
81+
`dotnet run`
82+
83+
- To run dev from root:
84+
`yarn dev`
85+
86+
- To start from root:
87+
`yarn start`
88+
89+
- To build from root:
90+
`yarn build`
91+
92+
# 🧪 Testing Front-End
7093

7194
## Test Location
7295
All current front-endtests are located in the `front-end/cypress/e2e` directory

back-end/Controllers/ChatbotController.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ public ChatbotController(IConfiguration configuration)
3737

3838
_systemMessage = new SystemChatMessage(
3939
"""
40-
You are an AI dealer assistant that helps people find vehicle information that fit their wanted.
41-
Note: include vehicle information such as model, make, year, vin, fuel type, body type as a list description
40+
You are an AI dealer assistant that helps people find vehicle information that fits their preferences.
41+
If a customer makes an unreasonable or unrealistic request, politely inform them that you cannot fulfill it
42+
Otherwise, provide recoomendation cars include model, make, year, vin following this format.
43+
Example:
44+
1) Honda CRV 2016
45+
VIN: 123456789.
46+
2) Toyota Camry 2018
47+
VIN: 123456788.
4248
"""
4349
);
4450

@@ -81,8 +87,12 @@ public async Task<IActionResult> SendMessage([FromBody] ChatRequestModel request
8187
ChatMessageContext messageContext = AzureChatExtensions.GetMessageContext(completion);
8288
var chatContent = completion.Content[0].Text;
8389

84-
List<string> vins = [];
90+
List<Citation> citations = [];
91+
int carIndex = 1;
8592
string vinPattern = @"[A-HJ-NPR-Z0-9]{17}";
93+
94+
string content = chatContent.Substring(0, chatContent.IndexOf('1'));
95+
8696
if (messageContext.Citations != null)
8797
{
8898
foreach (var citation in messageContext.Citations)
@@ -92,7 +102,12 @@ public async Task<IActionResult> SendMessage([FromBody] ChatRequestModel request
92102
var matchCitation = Regex.Match(citation.Content, vinPattern);
93103
if (matchCitation.Success && chatContent.Contains(matchCitation.Value))
94104
{
95-
vins.Add(matchCitation.Value);
105+
string VIM = matchCitation.Value;
106+
int start = chatContent.IndexOf(carIndex + ")");
107+
int end = chatContent.IndexOf("VIN:", start);
108+
string description = chatContent[start..end].Trim();
109+
110+
citations.Add(new Citation { VIM = VIM, Description = description });
96111
}
97112
}
98113
}
@@ -101,15 +116,15 @@ public async Task<IActionResult> SendMessage([FromBody] ChatRequestModel request
101116
{
102117
Console.WriteLine("No Citations");
103118
}
104-
return Ok(new { ChatContent = chatContent, Citations = vins });
119+
return Ok(new { ChatContent = content, Citations = citations });
105120
}
106121

107122

108123
[HttpPost("query")]
109124
public async Task<IActionResult> SendQuery([FromBody] QueryRequest request)
110125
{
111126
var chatMessages = new List<ChatMessage> { _systemMessage };
112-
ChatMessage message = new UserChatMessage("Find me a VIN vehicle that best fit this description: " + request.Query);
127+
ChatMessage message = new UserChatMessage(request.Query);
113128

114129
chatMessages.Add(message);
115130

back-end/Controllers/VehicleController.cs

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,44 @@ public VehicleController(AppDbContext context)
2525
[HttpGet]
2626
public async Task<IActionResult> GetAllVehicle()
2727
{
28-
var vehicles = await _context.Vehicle.ToListAsync();
28+
var vehicles = await _context.Vehicle
29+
.Include(v => v.VehicleImages)
30+
.ToListAsync();
2931
// Console.WriteLine($"Found {vehicles.Count} vehicle.");
3032

3133
if (vehicles == null || vehicles.Count == 0)
3234
{
3335
return NotFound(new { Message = "No vehicle found." });
3436
}
3537

38+
var vehicleDtos = vehicles.Select(v => new
39+
{
40+
v.VehicleID,
41+
v.VIN,
42+
v.Model,
43+
v.Make,
44+
v.BodyType,
45+
v.Year,
46+
v.OriginalPrice,
47+
v.Price,
48+
v.Condition,
49+
v.FuelType,
50+
v.CO2Emissions,
51+
v.MPG,
52+
v.Mileage,
53+
v.Color,
54+
v.Feature,
55+
v.Description,
56+
v.IsAvailable,
57+
ImageUrls = v.VehicleImages.Select(vi => vi.Url).ToList() // Get image URLs for each vehicle
58+
}).ToList();
59+
3660
// foreach (var vehicle in vehicles)
3761
// {
3862
// Console.WriteLine($"VehicleID: {vehicle.VehicleID}, Make: {vehicle.Make}, Model: {vehicle.Model}, Price: {vehicle.Price}");
3963
// }
4064

41-
return Ok(vehicles);
65+
return Ok(vehicleDtos);
4266
}
4367

4468
[HttpGet("by-vins")]
@@ -52,6 +76,7 @@ public async Task<IActionResult> GetVehiclesByVins([FromQuery] string vins)
5276
var vinList = vins.Split(',').Select(v => v.Trim()).ToList();
5377

5478
var vehicles = await _context.Vehicle
79+
.Include(v => v.VehicleImages)
5580
.Where(v => vinList.Contains(v.VIN))
5681
.ToListAsync();
5782

@@ -60,7 +85,30 @@ public async Task<IActionResult> GetVehiclesByVins([FromQuery] string vins)
6085
return NotFound(new { Message = "No vehicles found with the provided VINs." });
6186
}
6287

63-
return Ok(vehicles);
88+
var vehicleDtos = vehicles.Select(v => new
89+
{
90+
v.VehicleID,
91+
v.VIN,
92+
v.Model,
93+
v.Make,
94+
v.BodyType,
95+
v.Year,
96+
v.OriginalPrice,
97+
v.Price,
98+
v.Condition,
99+
v.FuelType,
100+
v.CO2Emissions,
101+
v.MPG,
102+
v.Mileage,
103+
v.Color,
104+
v.Feature,
105+
v.Description,
106+
v.IsAvailable,
107+
v.DealerID,
108+
ImageUrls = v.VehicleImages.Select(vi => vi.Url).ToList() // Get image URLs for each vehicle
109+
}).ToList();
110+
111+
return Ok(vehicleDtos);
64112
}
65113

66114
[HttpGet("by-vin/{vin}")]
@@ -72,6 +120,7 @@ public async Task<IActionResult> GetVehicleByVin(string vin)
72120
}
73121

74122
var vehicle = await _context.Vehicle
123+
.Include(v => v.VehicleImages)
75124
.Where(v => v.VIN == vin)
76125
.FirstOrDefaultAsync();
77126

@@ -80,19 +129,68 @@ public async Task<IActionResult> GetVehicleByVin(string vin)
80129
return NotFound(new { Message = "No vehicle found with the provided VIN." });
81130
}
82131

83-
return Ok(vehicle);
132+
var vehicleDto = new
133+
{
134+
vehicle.VehicleID,
135+
vehicle.VIN,
136+
vehicle.Model,
137+
vehicle.Make,
138+
vehicle.BodyType,
139+
vehicle.Year,
140+
vehicle.OriginalPrice,
141+
vehicle.Price,
142+
vehicle.Condition,
143+
vehicle.FuelType,
144+
vehicle.CO2Emissions,
145+
vehicle.MPG,
146+
vehicle.Mileage,
147+
vehicle.Color,
148+
vehicle.Feature,
149+
vehicle.Description,
150+
vehicle.IsAvailable,
151+
ImageUrls = vehicle.VehicleImages.Select(vi => vi.Url).ToList() // Get image URLs for the single vehicle
152+
};
153+
154+
return Ok(vehicleDto);
84155
}
85156

86157
// GET: api/vehicle/{id}
87158
[HttpGet("{id:int}")]
88-
public IActionResult GetVehicleById(int id)
159+
public async Task<IActionResult> GetVehicleById(int id)
89160
{
90-
var vehicle = _context.Vehicle.FirstOrDefault(v => v.VehicleID == id); // _context.Vehicle
161+
var vehicle = await _context.Vehicle
162+
.Include(v => v.VehicleImages)
163+
.Where(v => v.VehicleID == id)
164+
.FirstOrDefaultAsync();
165+
91166
if (vehicle == null)
92167
{
93168
return NotFound(new { Message = "Vehicle not found." });
94169
}
95-
return Ok(vehicle);
170+
171+
var vehicleDto = new
172+
{
173+
vehicle.VehicleID,
174+
vehicle.VIN,
175+
vehicle.Model,
176+
vehicle.Make,
177+
vehicle.BodyType,
178+
vehicle.Year,
179+
vehicle.OriginalPrice,
180+
vehicle.Price,
181+
vehicle.Condition,
182+
vehicle.FuelType,
183+
vehicle.CO2Emissions,
184+
vehicle.MPG,
185+
vehicle.Mileage,
186+
vehicle.Color,
187+
vehicle.Feature,
188+
vehicle.Description,
189+
vehicle.IsAvailable,
190+
ImageUrls = vehicle.VehicleImages.Select(vi => vi.Url).ToList() // Get image URLs for the single vehicle
191+
};
192+
193+
return Ok(vehicleDto);
96194
}
97195

98196
// GET: api/vehicle/price/{vin}

0 commit comments

Comments
 (0)