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 · modeblame

aaa924ecJose Arriaga Maldonado1 years ago1using System;
2using System.Text.RegularExpressions;
3
4namespace OpenAI.Chat;
5
6[CodeGenType("ChatCompletionRequestMessageContentPartFileFile")]
7internal partial class InternalChatCompletionRequestMessageContentPartFileFile
8{
9private readonly BinaryData _fileBytes;
10private 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")]
15internal string FileData { get; }
16
17public InternalChatCompletionRequestMessageContentPartFileFile(BinaryData fileBytes, string fileBytesMediaType)
18{
19Argument.AssertNotNull(fileBytes, nameof(fileBytes));
20Argument.AssertNotNull(fileBytesMediaType, nameof(fileBytesMediaType));
21
22_fileBytes = fileBytes;
23_fileBytesMediaType = fileBytesMediaType;
24
25string base64EncodedData = Convert.ToBase64String(_fileBytes.ToArray());
26FileData = $"data:{_fileBytesMediaType};base64,{base64EncodedData}";
27}
28
29public BinaryData FileBytes => _fileBytes;
30
31public string FileBytesMediaType => _fileBytesMediaType;
32}