Skip to content

Commit

Permalink
fix: Changed Files.DownloadFile return type to byte[].
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 31, 2024
1 parent 972ae31 commit 4d76474
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
13 changes: 13 additions & 0 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;

var path = args[0];
Expand All @@ -27,6 +28,18 @@
openApiDocument.Components.Schemas["MessageObject"]!.Required.Remove("completed_at");
openApiDocument.Components.Schemas["MessageObject"]!.Required.Remove("incomplete_at");

openApiDocument.Paths["/files/{file_id}/content"]!.Operations[OperationType.Get].Responses["200"]!.Content.Remove("application/json");
openApiDocument.Paths["/files/{file_id}/content"]!.Operations[OperationType.Get].Responses["200"]!.Content.Add(
"application/octet-stream",
new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Type = "string",
Format = "binary",
}
});

openApiDocument.Components.Schemas["CreateChatCompletionRequest"]!.Properties["model"].AnyOf[1].Enum =
openApiDocument.Components.Schemas["CreateChatCompletionRequest"]!.Properties["model"].AnyOf[1].Enum
.DistinctBy(x => (x as OpenApiString)?.Value)
Expand Down
24 changes: 6 additions & 18 deletions src/libs/OpenAI/Generated/OpenAI.FilesClient.DownloadFile.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ partial void ProcessDownloadFileResponse(
partial void ProcessDownloadFileResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);
ref byte[] content);

/// <summary>
/// Returns the contents of the specified file.
/// </summary>
/// <param name="fileId"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<string> DownloadFileAsync(
public async global::System.Threading.Tasks.Task<byte[]> DownloadFileAsync(
string fileId,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -61,29 +61,17 @@ partial void ProcessDownloadFileResponseContent(
httpClient: _httpClient,
httpResponseMessage: response);

var __content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
var __content = await response.Content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(false);

ProcessResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessDownloadFileResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);

try
{
response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException ex)
{
throw new global::System.InvalidOperationException(__content, ex);
}

return
global::System.Text.Json.JsonSerializer.Deserialize(__content, global::OpenAI.SourceGenerationContext.Default.String) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
response.EnsureSuccessStatusCode();

return __content;
}
}
}
3 changes: 2 additions & 1 deletion src/libs/OpenAI/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,10 @@ paths:
'200':
description: OK
content:
application/json:
application/octet-stream:
schema:
type: string
format: binary
x-oaiMeta:
name: Retrieve file content
group: files
Expand Down

0 comments on commit 4d76474

Please sign in to comment.