openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
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 | |
| 8 | using System.ClientModel; |
| 9 | using OpenAI.Responses; |
| 10 | using OpenAI.Files; |
| 11 | |
| 12 | string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!; |
| 13 | ResponsesClient client = new(key); |
| 14 | |
| 15 | // Upload a PDF we will reference in the variables |
| 16 | OpenAIFileClient files = new(key); |
| 17 | OpenAIFile file = files.UploadFile("draconomicon.pdf", FileUploadPurpose.UserData); |
| 18 | |
| 19 | ResponseResult 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 | |
| 36 | Console.WriteLine(response.GetOutputText()); |