Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal static class ChatClientAgentRunOptionsConverter
Model = request.Model,
ToolChoice = request.ToolChoice?.ToChatToolMode(),
Tools = request.Tools is { Count: > 0 } tools ? tools.Select(x => x.ToAITool()).ToList() : null,
WebSearchOptions = request.WebSearchOptions,
};

private static ChatResponseFormat ToChatResponseFormat(this ResponseFormat responseFormat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ public sealed class OpenAIChatCompletionRequestInfo
/// Gets or sets the tools supplied on the request, if any.
/// </summary>
public IReadOnlyList<AITool>? Tools { get; set; }

/// <summary>
/// Gets or sets the web search options (<c>web_search_options</c>) supplied on the request, if any.
/// </summary>
public object? WebSearchOptions { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public sealed class OpenAIChatCompletionsMapOptions
LocalAdd("tool_choice");
}

if (request.WebSearchOptions is not null)
{
LocalAdd("web_search_options");
}

if (unsupported is not null)
{
throw new NotSupportedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ public async Task ChatCompletions_DefaultEndpoint_RejectsRequestWithSettingsAsyn
Assert.Contains("invalid_request_error", body, StringComparison.Ordinal);
}

[Fact]
public async Task ChatCompletions_DefaultEndpoint_RejectsWebSearchOptionsAsync()
{
// Arrange
using var app = await CreateChatCompletionsServerAsync("reject-agent", mapOptions: null);
HttpClient client = GetClient(app);

// Act
HttpResponseMessage response = await client.PostAsync(
new Uri("/reject-agent/v1/chat/completions", UriKind.Relative),
new StringContent("""{"model":"myModel","messages":[{"role":"user","content":"hello"}],"web_search_options":{}}""", Encoding.UTF8, "application/json"));

// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
string body = await response.Content.ReadAsStringAsync();
Assert.Contains("web_search_options", body, StringComparison.Ordinal);
Assert.Contains("invalid_request_error", body, StringComparison.Ordinal);
}

[Fact]
public async Task ChatCompletions_ConfiguredEndpoint_HonorsRequestSettingsAsync()
{
Expand Down
Loading