openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-codeinterpretertoolcontainer

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

23lines · 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(key);
12
13CreateResponseOptions options = new() { Model = "gpt-5.2" };
14options.Tools.Add(
15 ResponseTool.CreateWebSearchTool()
16);
17options.InputItems.Add(
18 ResponseItem.CreateUserMessageItem("What was a positive news story from today?")
19);
20
21ResponseResult response = client.CreateResponse(options);
22
23Console.WriteLine(response.GetOutputText());