Skip to content
Merged
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
22 changes: 16 additions & 6 deletions DevProxy.Plugins/Behavior/LanguageModelFailurePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public override async Task BeforeRequestAsync(ProxyRequestArgs e, CancellationTo
return;
}

if (!OpenAIRequest.TryGetCompletionLikeRequest(request.BodyString, Logger, out var openAiRequest))
Logger.LogDebug("Request encoding: {Encoding}", request.Encoding?.EncodingName ?? "null");
var originalBody = System.Text.Encoding.UTF8.GetString(request.Body);
Logger.LogDebug("Original request body:\n{Body}", originalBody);
Comment thread
waldekmastykarz marked this conversation as resolved.

if (!OpenAIRequest.TryGetCompletionLikeRequest(originalBody, Logger, out var openAiRequest))
Comment thread
waldekmastykarz marked this conversation as resolved.
{
Logger.LogRequest("Skipping non-OpenAI request", MessageType.Skipped, new LoggingContext(e.Session));
return;
Expand All @@ -91,15 +95,17 @@ public override async Task BeforeRequestAsync(ProxyRequestArgs e, CancellationTo
completionRequest.Prompt += "\n\n" + faultPrompt;
Logger.LogDebug("Modified completion request prompt: {Prompt}", completionRequest.Prompt);
Logger.LogRequest($"Simulating fault {faultName}", MessageType.Chaos, new LoggingContext(e.Session));
e.Session.SetRequestBodyString(JsonSerializer.Serialize(completionRequest, ProxyUtils.JsonSerializerOptions));
var modifiedBody = JsonSerializer.Serialize(completionRequest, ProxyUtils.JsonSerializerOptions);
Logger.LogDebug("Modified request body:\n{Body}", modifiedBody);
e.Session.SetRequestBodyString(modifiedBody);
Comment thread
waldekmastykarz marked this conversation as resolved.
}
else if (openAiRequest is OpenAIChatCompletionRequest chatRequest)
{
var messages = new List<OpenAIChatCompletionMessage>(chatRequest.Messages)
{
new()
{
Role = "user",
Role = "system",
Content = faultPrompt
}
};
Expand All @@ -114,15 +120,17 @@ public override async Task BeforeRequestAsync(ProxyRequestArgs e, CancellationTo

Logger.LogDebug("Added fault prompt to messages: {Prompt}", faultPrompt);
Logger.LogRequest($"Simulating fault {faultName}", MessageType.Chaos, new LoggingContext(e.Session));
e.Session.SetRequestBodyString(JsonSerializer.Serialize(newRequest, ProxyUtils.JsonSerializerOptions));
var modifiedBody = JsonSerializer.Serialize(newRequest, ProxyUtils.JsonSerializerOptions);
Logger.LogDebug("Modified request body:\n{Body}", modifiedBody);
e.Session.SetRequestBodyString(modifiedBody);
Comment thread
waldekmastykarz marked this conversation as resolved.
}
else if (openAiRequest is OpenAIResponsesRequest responsesRequest)
{
var inputItems = new List<OpenAIResponsesInputItem>(responsesRequest.Input ?? [])
{
new()
{
Role = "user",
Role = "system",
Content = faultPrompt
}
};
Expand All @@ -144,7 +152,9 @@ public override async Task BeforeRequestAsync(ProxyRequestArgs e, CancellationTo

Logger.LogDebug("Added fault prompt to Responses API input: {Prompt}", faultPrompt);
Logger.LogRequest($"Simulating fault {faultName}", MessageType.Chaos, new LoggingContext(e.Session));
e.Session.SetRequestBodyString(JsonSerializer.Serialize(newRequest, ProxyUtils.JsonSerializerOptions));
var modifiedBody = JsonSerializer.Serialize(newRequest, ProxyUtils.JsonSerializerOptions);
Logger.LogDebug("Modified request body:\n{Body}", modifiedBody);
Comment thread
waldekmastykarz marked this conversation as resolved.
e.Session.SetRequestBodyString(modifiedBody);
}
else
{
Expand Down
Loading