Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/guides/tools/responses/file_search.cs
Original file line number Diff line number Diff line change
@@ -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([ "<vector_store_id>" ]));

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("What is deep research by OpenAI?")
])
], options);

Console.WriteLine(response.GetOutputText());
43 changes: 43 additions & 0 deletions docs/guides/tools/responses/function_calling.cs
Original file line number Diff line number Diff line change
@@ -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]));
27 changes: 27 additions & 0 deletions docs/guides/tools/responses/remote_mcp.cs
Original file line number Diff line number Diff line change
@@ -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());
25 changes: 25 additions & 0 deletions docs/guides/tools/responses/web_search.cs
Original file line number Diff line number Diff line change
@@ -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());