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/guides/text/responses/responses_fileinput.cs

36lines · modecode

1// SAMPLE: Prompt template with file input variable
2// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
3#pragma warning disable OPENAI001
4
5#:package OpenAI@2.*
6#:property PublishAot=false
7
8using System.ClientModel;
9using OpenAI.Responses;
10using OpenAI.Files;
11
12string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
13ResponsesClient client = new(key);
14
15// Upload a PDF we will reference in the variables
16OpenAIFileClient files = new(key);
17OpenAIFile file = files.UploadFile("draconomicon.pdf", FileUploadPurpose.UserData);
18
19ResponseResult response = (ResponseResult)client.CreateResponse(
20 BinaryContent.Create(BinaryData.FromObjectAsJson(
21 new {
22 model = "gpt-5.2",
23 prompt = new {
24 id = "pmpt_abc123",
25 variables = new {
26 topic = "Dragons",
27 reference_pdf = new {
28 type = "input_file",
29 file_id = file.Id,
30 }
31 }
32 }
33 }
34)));
35
36Console.WriteLine(response.GetOutputText());