Skip to content

Adds LanguageModelRateLimitingPlugin. Closes #1309 #1324

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

Merged
merged 4 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DevProxy.Abstractions/LanguageModel/OpenAIModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace DevProxy.Abstractions.LanguageModel;

public abstract class OpenAIRequest
public class OpenAIRequest
{
[JsonPropertyName("frequency_penalty")]
public long? FrequencyPenalty { get; set; }
Expand All @@ -22,7 +22,7 @@ public abstract class OpenAIRequest
public double? TopP { get; set; }
}

public abstract class OpenAIResponse : ILanguageModelCompletionResponse
public class OpenAIResponse : ILanguageModelCompletionResponse
{
public long Created { get; set; }
public OpenAIError? Error { get; set; }
Expand All @@ -37,12 +37,12 @@ public abstract class OpenAIResponse : ILanguageModelCompletionResponse
public string? RequestUrl { get; set; }

public string? ErrorMessage => Error?.Message;
public abstract string? Response { get; }
public virtual string? Response { get; }

public OpenAIResponse ConvertToOpenAIResponse() => this;
}

public abstract class OpenAIResponse<TChoice> : OpenAIResponse
public class OpenAIResponse<TChoice> : OpenAIResponse
{
public IEnumerable<TChoice>? Choices { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
}
Loading