Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
25 changes: 25 additions & 0 deletions docs/guides/tools-web-search/responses/quickstart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SAMPLE: Get information from web search through Responses API
// PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
OpenAIResponseClient client = new(model: "gpt-5", apiKey: key);

ResponseCreationOptions options = new();
options.Tools.Add(ResponseTool.CreateWebSearchTool());

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart(
"What was a positive news story from today?"
)
])
], options);

Console.WriteLine(response.GetOutputText());
31 changes: 31 additions & 0 deletions docs/guides/tools-web-search/responses/user-location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SAMPLE: Get information from web search by specifying user location through Responses API
// PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#user-location
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
OpenAIResponseClient client = new(model: "gpt-5", apiKey: key);

ResponseCreationOptions options = new();
options.Tools.Add(ResponseTool.CreateWebSearchTool(
userLocation: WebSearchToolLocation.CreateApproximateLocation(
country: "GB",
city: "London",
region: "London"
)
));

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart(
"What are the best restaurants around Granary Square?"
)
])
], options);

Console.WriteLine(response.GetOutputText());