diff --git a/docs/guides/tools-web-search/responses/quickstart.cs b/docs/guides/tools-web-search/responses/quickstart.cs new file mode 100644 index 000000000..4eb075d2f --- /dev/null +++ b/docs/guides/tools-web-search/responses/quickstart.cs @@ -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()); \ No newline at end of file diff --git a/docs/guides/tools-web-search/responses/user-location.cs b/docs/guides/tools-web-search/responses/user-location.cs new file mode 100644 index 000000000..b087e00f6 --- /dev/null +++ b/docs/guides/tools-web-search/responses/user-location.cs @@ -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: "Granary Square" + ) +)); + +OpenAIResponse response = (OpenAIResponse)client.CreateResponse([ + ResponseItem.CreateUserMessageItem([ + ResponseContentPart.CreateInputTextPart( + "What are the best restaurants near me?" + ) + ]) +], options); + +Console.WriteLine(response.GetOutputText()); \ No newline at end of file