openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
achandmsft-patch-1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/Chat/Internal/InternalChatCompletionRequestMessageContentPartFileFile.cs

32lines · modecode

1using System;
2using System.Text.RegularExpressions;
3
4namespace OpenAI.Chat;
5
6[CodeGenType("ChatCompletionRequestMessageContentPartFileFile")]
7internal partial class InternalChatCompletionRequestMessageContentPartFileFile
8{
9 private readonly BinaryData _fileBytes;
10 private readonly string _fileBytesMediaType;
11
12 // CUSTOM: Changed type from Uri to string to be able to support data URIs properly.
13 /// <summary> Either a URL of the image or the base64 encoded image data. </summary>
14 [CodeGenMember("FileData")]
15 internal string FileData { get; }
16
17 public InternalChatCompletionRequestMessageContentPartFileFile(BinaryData fileBytes, string fileBytesMediaType)
18 {
19 Argument.AssertNotNull(fileBytes, nameof(fileBytes));
20 Argument.AssertNotNull(fileBytesMediaType, nameof(fileBytesMediaType));
21
22 _fileBytes = fileBytes;
23 _fileBytesMediaType = fileBytesMediaType;
24
25 string base64EncodedData = Convert.ToBase64String(_fileBytes.ToArray());
26 FileData = $"data:{_fileBytesMediaType};base64,{base64EncodedData}";
27 }
28
29 public BinaryData FileBytes => _fileBytes;
30
31 public string FileBytesMediaType => _fileBytesMediaType;
32}
33