diff --git a/docs/guides/tools/responses/file_search.cs b/docs/guides/tools/responses/file_search.cs new file mode 100644 index 000000000..889706882 --- /dev/null +++ b/docs/guides/tools/responses/file_search.cs @@ -0,0 +1,23 @@ +// SAMPLE: Get information from file search through Responses API +// PAGE: https://platform.openai.com/docs/guides/tools?tool-type=file-search +// 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.CreateFileSearchTool([ "" ])); + +OpenAIResponse response = (OpenAIResponse)client.CreateResponse([ + ResponseItem.CreateUserMessageItem([ + ResponseContentPart.CreateInputTextPart("What is deep research by OpenAI?") + ]) +], options); + +Console.WriteLine(response.GetOutputText()); \ No newline at end of file diff --git a/docs/guides/tools/responses/function_calling.cs b/docs/guides/tools/responses/function_calling.cs new file mode 100644 index 000000000..27eaf1e7e --- /dev/null +++ b/docs/guides/tools/responses/function_calling.cs @@ -0,0 +1,43 @@ +// SAMPLE: Generate response from function calling through Responses API +// PAGE: https://platform.openai.com/docs/guides/tools?tool-type=function-calling +// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start +#pragma warning disable OPENAI001 + +#:package OpenAI@2.* +#:property PublishAot=false + +using System.Text.Json; +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.CreateFunctionTool( + functionName: "get_weather", + functionDescription: "Get current temperature for a given location.", + functionParameters: BinaryData.FromObjectAsJson(new + { + type = "object", + properties = new + { + location = new + { + type = "string", + description = "City and country e.g. Bogotá, Colombia", + } + }, + required = new[] { "location" }, + additionalProperties = false + }), + strictModeEnabled: true + ) +); + +OpenAIResponse response = (OpenAIResponse)client.CreateResponse([ + ResponseItem.CreateUserMessageItem([ + ResponseContentPart.CreateInputTextPart("What is the weather like in Paris today?") + ]) +], options); + +Console.WriteLine(JsonSerializer.Serialize(response.OutputItems[0])); \ No newline at end of file diff --git a/docs/guides/tools/responses/remote_mcp.cs b/docs/guides/tools/responses/remote_mcp.cs new file mode 100644 index 000000000..1dee77096 --- /dev/null +++ b/docs/guides/tools/responses/remote_mcp.cs @@ -0,0 +1,27 @@ +// SAMPLE: Generate response from remote MCP through Responses API +// PAGE: https://platform.openai.com/docs/guides/tools?tool-type=remote-mcp +// 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.CreateMcpTool( + serverLabel: "dmcp", + serverUri: new Uri("https://dmcp-server.deno.dev/sse"), + toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval) +)); + +OpenAIResponse response = (OpenAIResponse)client.CreateResponse([ + ResponseItem.CreateUserMessageItem([ + ResponseContentPart.CreateInputTextPart("Roll 2d4+1") + ]) +], options); + +Console.WriteLine(response.GetOutputText()); \ No newline at end of file diff --git a/docs/guides/tools/responses/web_search.cs b/docs/guides/tools/responses/web_search.cs new file mode 100644 index 000000000..f1cbece6e --- /dev/null +++ b/docs/guides/tools/responses/web_search.cs @@ -0,0 +1,25 @@ +// SAMPLE: Get information from web search through Responses API +// PAGE: https://platform.openai.com/docs/guides/tools?tool-type=web-search +// 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