Skip to content

Commit 8ce21d3

Browse files
committed
feat: Enhance AI configuration and service with timeout settings
- Added TimeoutSeconds property to AISettings for configurable timeout duration. - Implemented GetTimeoutSeconds method to retrieve timeout from configuration with a default of 120 seconds. - Updated AIConfiguration to utilize the new timeout setting in AI service calls. - Refactored ChatService to use the new AI agent framework and handle timeouts appropriately. - Introduced rate limiting for chat and weather endpoints to manage request load. - Updated various unit tests to accommodate changes in AISettings and ensure proper functionality. - Removed obsolete AIConfiguration file from ApiService as logic has been centralized in Abstractions. - Added initial database migration files for Conversations and Messages tables. - Updated package references for improved stability and performance.
1 parent db2a133 commit 8ce21d3

24 files changed

Lines changed: 560 additions & 106 deletions

src/BuildWithAspire.Abstractions/AIConfiguration.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ public enum AIProvider
1212
AzureAIFoundry
1313
}
1414

15-
public record AISettings(AIProvider Provider, string DeploymentName, string Model);
15+
public record AISettings(AIProvider Provider, string DeploymentName, string Model, int TimeoutSeconds);
1616

1717
public static AISettings GetSettings(IConfiguration configuration)
1818
{
1919
var provider = GetProvider(configuration);
2020
var deploymentName = GetDeploymentName(configuration);
2121
var model = GetModel(configuration, provider);
22+
var timeoutSeconds = GetTimeoutSeconds(configuration);
2223

23-
return new AISettings(provider, deploymentName, model);
24+
return new AISettings(provider, deploymentName, model, timeoutSeconds);
2425
}
2526

2627
public static AIProvider GetProvider(IConfiguration configuration)
@@ -67,4 +68,14 @@ public static string GetModel(IConfiguration configuration, AIProvider? provider
6768
};
6869
return model;
6970
}
71+
72+
public static int GetTimeoutSeconds(IConfiguration configuration)
73+
{
74+
var timeoutString = configuration["AI:TimeoutSeconds"];
75+
if (int.TryParse(timeoutString, out var timeout) && timeout > 0)
76+
{
77+
return timeout;
78+
}
79+
return 120; // Default 2 minutes
80+
}
7081
}

src/BuildWithAspire.Abstractions/BuildWithAspire.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
w <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
9+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
1010
</ItemGroup>
1111
</Project>

src/BuildWithAspire.ApiService/BuildWithAspire.ApiService.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
<PackageReference Include="Microsoft.Extensions.AI" Version="9.9.1" />
2525
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.9.1-preview.1.25474.6" />
2626
<PackageReference Include="Microsoft.AI.Foundry.Local" Version="0.3.0" />
27-
<PackageReference Include="Scalar.AspNetCore" Version="2.8.8" />
27+
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.251002.1" />
28+
<PackageReference Include="Scalar.AspNetCore" Version="2.8.10" />
2829
<PackageReference Include="System.Text.Json" Version="9.0.9" />
29-
<PackageReference Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.65.0" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

src/BuildWithAspire.ApiService/Configuration/AIConfiguration.cs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/BuildWithAspire.ApiService/Data/Migrations/20251001123636_InitialCreate.Designer.cs

Lines changed: 102 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace BuildWithAspire.ApiService.Data.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class InitialCreate : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "Conversations",
16+
columns: table => new
17+
{
18+
Id = table.Column<Guid>(type: "uuid", nullable: false),
19+
Name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
20+
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
21+
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP")
22+
},
23+
constraints: table =>
24+
{
25+
table.PrimaryKey("PK_Conversations", x => x.Id);
26+
});
27+
28+
migrationBuilder.CreateTable(
29+
name: "Messages",
30+
columns: table => new
31+
{
32+
Id = table.Column<Guid>(type: "uuid", nullable: false),
33+
ConversationId = table.Column<Guid>(type: "uuid", nullable: false),
34+
Role = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
35+
Content = table.Column<string>(type: "text", nullable: false),
36+
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP")
37+
},
38+
constraints: table =>
39+
{
40+
table.PrimaryKey("PK_Messages", x => x.Id);
41+
table.ForeignKey(
42+
name: "FK_Messages_Conversations_ConversationId",
43+
column: x => x.ConversationId,
44+
principalTable: "Conversations",
45+
principalColumn: "Id",
46+
onDelete: ReferentialAction.Cascade);
47+
});
48+
49+
migrationBuilder.CreateIndex(
50+
name: "IX_Messages_ConversationId",
51+
table: "Messages",
52+
column: "ConversationId");
53+
}
54+
55+
/// <inheritdoc />
56+
protected override void Down(MigrationBuilder migrationBuilder)
57+
{
58+
migrationBuilder.DropTable(
59+
name: "Messages");
60+
61+
migrationBuilder.DropTable(
62+
name: "Conversations");
63+
}
64+
}
65+
}

src/BuildWithAspire.ApiService/Data/Migrations/20251001124029_AddValidationAnnotations.Designer.cs

Lines changed: 102 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace BuildWithAspire.ApiService.Data.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class AddValidationAnnotations : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
14+
}
15+
16+
/// <inheritdoc />
17+
protected override void Down(MigrationBuilder migrationBuilder)
18+
{
19+
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)