openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
mailinhphan/clientOptions

Branches

Tags

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

Clone

HTTPS

Download ZIP

OpenAI/src/Custom/Chat/Internal/InternalChatCompletionRequestMessageContentPartFileFile.cs

43lines · modecode

1using Microsoft.TypeSpec.Generator.Customizations;
2using System;
3
4namespace OpenAI.Chat;
5
6[CodeGenType("ChatCompletionRequestMessageContentPartFileFile")]
7internal partial class InternalChatCompletionRequestMessageContentPartFileFile
8{
9 private BinaryData _fileBytes;
10 private 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 InternalFileData
16 {
17 get => _internalFileData;
18 set
19 {
20 _internalFileData = value;
21 if (value is not null && !DataEncodingHelpers.TryParseDataUri(value, out _fileBytes, out _fileBytesMediaType))
22 {
23 throw new ArgumentException($"Input did not parse a valid data URI.");
24 }
25 }
26 }
27 private string _internalFileData;
28
29 public InternalChatCompletionRequestMessageContentPartFileFile(BinaryData fileBytes, string fileBytesMediaType, string filename)
30 : this(filename: filename, null, null, default)
31 {
32 Argument.AssertNotNull(fileBytes, nameof(fileBytes));
33 Argument.AssertNotNull(fileBytesMediaType, nameof(fileBytesMediaType));
34
35 _fileBytes = fileBytes;
36 _fileBytesMediaType = fileBytesMediaType;
37 _internalFileData = DataEncodingHelpers.CreateDataUri(fileBytes, fileBytesMediaType);
38 }
39
40 public BinaryData FileBytes => _fileBytes;
41
42 public string FileBytesMediaType => _fileBytesMediaType;
43}
44