openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
docs/quickstart/responses/extend_model_with_tools_web_search.cs
26lines · modecode
| 1 | // SAMPLE: Get information from web search through Responses API |
| 2 | // PAGE: https://platform.openai.com/docs/quickstart?tool-type=web-search#extend-the-model-with-tools |
| 3 | // GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start |
| 4 | #pragma warning disable OPENAI001 |
| 5 | |
| 6 | #:package OpenAI@2.* |
| 7 | |
| 8 | using OpenAI.Responses; |
| 9 | |
| 10 | string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!; |
| 11 | ResponsesClient client = new(apiKey: key); |
| 12 | |
| 13 | CreateResponseOptions options = new() |
| 14 | { |
| 15 | Model = "gpt-5.2" |
| 16 | }; |
| 17 | options.Tools.Add( |
| 18 | ResponseTool.CreateWebSearchTool() |
| 19 | ); |
| 20 | options.InputItems.Add( |
| 21 | ResponseItem.CreateUserMessageItem("What was a positive news story from today?") |
| 22 | ); |
| 23 | |
| 24 | ResponseResult response = client.CreateResponse(options); |
| 25 | |
| 26 | Console.WriteLine(response.GetOutputText()); |