forked from dotnet/dev-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageModelRateLimitingCustomResponseLoader.cs
More file actions
40 lines (35 loc) · 1.43 KB
/
Copy pathLanguageModelRateLimitingCustomResponseLoader.cs
File metadata and controls
40 lines (35 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using DevProxy.Abstractions.Utils;
using DevProxy.Abstractions.Proxy;
using DevProxy.Abstractions.Plugins;
using Microsoft.Extensions.Logging;
using System.Text.Json;
using DevProxy.Abstractions.Models;
namespace DevProxy.Plugins.Behavior;
internal sealed class LanguageModelRateLimitingCustomResponseLoader(
HttpClient httpClient,
ILogger<LanguageModelRateLimitingCustomResponseLoader> logger,
LanguageModelRateLimitConfiguration configuration,
IProxyConfiguration proxyConfiguration) :
BaseLoader(httpClient, logger, proxyConfiguration)
{
private readonly LanguageModelRateLimitConfiguration _configuration = configuration;
protected override string FilePath => _configuration.CustomResponseFile;
protected override void LoadData(string fileContents)
{
try
{
var response = JsonSerializer.Deserialize<MockResponseResponse>(fileContents, ProxyUtils.JsonSerializerOptions);
if (response is not null)
{
_configuration.CustomResponse = response;
}
}
catch (Exception ex)
{
Logger.LogError(ex, "An error has occurred while reading {ConfigurationFile}:", _configuration.CustomResponseFile);
}
}
}