openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/modify-responsesclient-default-model

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
8using OpenAI.Responses;
9
10string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
11ResponsesClient client = new(apiKey: key);
12
13CreateResponseOptions options = new()
14{
15 Model = "gpt-5.2"
16};
17options.Tools.Add(
18 ResponseTool.CreateWebSearchTool()
19);
20options.InputItems.Add(
21 ResponseItem.CreateUserMessageItem("What was a positive news story from today?")
22);
23
24ResponseResult response = client.CreateResponse(options);
25
26Console.WriteLine(response.GetOutputText());