File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
docs/guides/tools-web-search/responses Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ // SAMPLE: Get information from web search through Responses API
2+ // PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses
3+ // GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4+ #pragma warning disable OPENAI001
5+
6+ #: package OpenAI @2 . *
7+ #: property PublishAot = false
8+
9+ using OpenAI. Responses ;
10+
11+ string key = Environment . GetEnvironmentVariable ( "OPENAI_API_KEY" ) ! ;
12+ OpenAIResponseClient client = new ( model : "gpt-5" , apiKey : key ) ;
13+
14+ ResponseCreationOptions options = new ( ) ;
15+ options . Tools . Add ( ResponseTool . CreateWebSearchTool ( ) ) ;
16+
17+ OpenAIResponse response = ( OpenAIResponse ) client . CreateResponse ( [
18+ ResponseItem . CreateUserMessageItem ( [
19+ ResponseContentPart . CreateInputTextPart (
20+ "What was a positive news story from today?"
21+ )
22+ ] )
23+ ] , options ) ;
24+
25+ Console . WriteLine ( response . GetOutputText ( ) ) ;
Original file line number Diff line number Diff line change 1+ // SAMPLE: Get information from web search by specifying user location through Responses API
2+ // PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#user-location
3+ // GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4+ #pragma warning disable OPENAI001
5+
6+ #: package OpenAI @2 . *
7+ #: property PublishAot = false
8+
9+ using OpenAI. Responses ;
10+
11+ string key = Environment . GetEnvironmentVariable ( "OPENAI_API_KEY" ) ! ;
12+ OpenAIResponseClient client = new ( model : "gpt-5" , apiKey : key ) ;
13+
14+ ResponseCreationOptions options = new ( ) ;
15+ options . Tools . Add ( ResponseTool . CreateWebSearchTool (
16+ userLocation : WebSearchToolLocation . CreateApproximateLocation (
17+ country : "GB" ,
18+ city : "London" ,
19+ region : "Granary Square"
20+ )
21+ ) ) ;
22+
23+ OpenAIResponse response = ( OpenAIResponse ) client . CreateResponse ( [
24+ ResponseItem . CreateUserMessageItem ( [
25+ ResponseContentPart . CreateInputTextPart (
26+ "What are the best restaurants near me?"
27+ )
28+ ] )
29+ ] , options ) ;
30+
31+ Console . WriteLine ( response . GetOutputText ( ) ) ;
You can’t perform that action at this time.
0 commit comments