Skip to content

Commit

Permalink
feat: Updated OpenAI spec and fixed some bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 15, 2024
1 parent 5c0f5d8 commit effbcd2
Show file tree
Hide file tree
Showing 199 changed files with 20,587 additions and 13,667 deletions.
26,836 changes: 13,619 additions & 13,217 deletions specs/openai.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static string ToClassName(
{
return text
.ToPropertyName()
.UseWordSeparator('_', '-', ' ', '\\', '/');
.UseWordSeparator('_', '-', ' ', '\\', '/', '[', ']');
}

public static string ReplaceIfEquals(
Expand Down
8 changes: 6 additions & 2 deletions src/libs/OpenApiGenerator.Core/Generation/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ .. includedTags.Select(x => PropertyData.Default with
settings.GenerateJsonSerializerContextTypes);
var allSchemas = settings.GenerateSdk || settings.GenerateModels ? classes.Values.Concat(methods
.SelectMany(x => x.AdditionalModels))
.SelectMany(x => x.Schema.Value.Properties.Concat([x.Schema]).ToArray())
.Select(x => x.Value)
.SelectMany(x => x.Schema.Value.Properties.Values
.Concat(x.Schema.Value.AnyOf)
.Concat(x.Schema.Value.OneOf)
.Concat(x.Schema.Value.AllOf)
.Concat([x.Schema.Value])
.ToArray())
.ToArray() : [];
var anyOfs = allSchemas
.Where(x => x.AnyOf is { Count: > 0 })
Expand Down
6 changes: 3 additions & 3 deletions src/libs/OpenApiGenerator.Core/Models/TypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public static string GetCSharpType(
(null, _) when schema.Value.OneOf.Any() && schema.IsComponent() => ($"global::{settings.Namespace}.{schema.Key}", false),
(null, _) when schema.Value.AllOf.Any() && schema.IsComponent() => ($"global::{settings.Namespace}.{schema.Key}", false),

(null, _) when schema.Value.AnyOf.Any() => ($"global::System.AnyOf<{string.Join(", ", schema.Value.AnyOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.OneOf.Any() => ($"global::System.OneOf<{string.Join(", ", schema.Value.OneOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.AllOf.Any() => ($"global::System.AllOf<{string.Join(", ", schema.Value.AllOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.AnyOf.Any() => ($"global::System.AnyOf<{string.Join(", ", schema.Value.AnyOf.Select(x => GetCSharpType(x.UseReferenceIdOrKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.OneOf.Any() => ($"global::System.OneOf<{string.Join(", ", schema.Value.OneOf.Select(x => GetCSharpType(x.UseReferenceIdOrKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.AllOf.Any() => ($"global::System.AllOf<{string.Join(", ", schema.Value.AllOf.Select(x => GetCSharpType(x.UseReferenceIdOrKey(schema.Key), settings, parents)))}>", false),

("object", _) or (null, _) when schema.Value.Reference != null =>
($"global::{settings.Namespace}.{ModelData.FromKey(schema.Value.Reference.Id, settings).ClassName}", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
<AnalysisMode>All</AnalysisMode>
</PropertyGroup>

<!-- <Target Name="FetchOpenApi" BeforeTargets="Build;BeforeCompile;CompileDesignTime">-->
<!-- &lt;!&ndash; Download the OpenAPI file (if expired) &ndash;&gt;-->
<!-- <DownloadFile-->
<!-- SourceUrl="https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml"-->
<!-- DestinationFolder="$(MSBuildThisFileDirectory)../../../specs"-->
<!-- DestinationFileName="openai.yaml"-->
<!-- SkipUnchangedFiles="true"-->
<!-- Retries="2" />-->
<!-- </Target>-->

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public partial class AssistantsClient
public async global::System.Threading.Tasks.Task<global::G.MessageObject> CreateMessageAsync(
string threadId,
global::G.CreateMessageRequestRole role,
global::System.OneOf<string, global::System.Collections.Generic.IList<global::System.OneOf<global::G.MessageContentImageFileObject, global::G.MessageContentImageUrlObject, global::G.MessageRequestContentTextObject>>> content,
global::System.OneOf<string, global::System.Collections.Generic.IList<global::System.OneOf<global::G.MessageContentImageFileObject?, global::G.MessageContentImageUrlObject?, global::G.MessageRequestContentTextObject?>>> content,
global::System.Collections.Generic.IList<global::G.CreateMessageRequestAttachments?>? attachments = default,
object? metadata = default,
global::System.Threading.CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public partial class AssistantsClient
/// <param name="maxCompletionTokens"></param>
/// <param name="truncationStrategy"></param>
/// <param name="toolChoice"></param>
/// <param name="parallelToolCalls"></param>
/// <param name="responseFormat"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
Expand All @@ -78,6 +79,7 @@ public partial class AssistantsClient
int? maxCompletionTokens = default,
global::G.TruncationObject? truncationStrategy = default,
global::System.OneOf<global::G.CreateRunRequestToolChoice?, global::G.AssistantsNamedToolChoice?> toolChoice = default,
bool parallelToolCalls = true,
global::System.OneOf<global::G.CreateRunRequestResponseFormat?, global::G.AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand All @@ -97,6 +99,7 @@ public partial class AssistantsClient
MaxCompletionTokens = maxCompletionTokens,
TruncationStrategy = truncationStrategy,
ToolChoice = toolChoice,
ParallelToolCalls = parallelToolCalls,
ResponseFormat = responseFormat,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public partial class AssistantsClient
/// <param name="maxCompletionTokens"></param>
/// <param name="truncationStrategy"></param>
/// <param name="toolChoice"></param>
/// <param name="parallelToolCalls"></param>
/// <param name="responseFormat"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
Expand All @@ -74,6 +75,7 @@ public partial class AssistantsClient
int? maxCompletionTokens = default,
global::G.TruncationObject? truncationStrategy = default,
global::System.OneOf<global::G.CreateThreadAndRunRequestToolChoice?, global::G.AssistantsNamedToolChoice?> toolChoice = default,
bool parallelToolCalls = true,
global::System.OneOf<global::G.CreateThreadAndRunRequestResponseFormat?, global::G.AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand All @@ -93,6 +95,7 @@ public partial class AssistantsClient
MaxCompletionTokens = maxCompletionTokens,
TruncationStrategy = truncationStrategy,
ToolChoice = toolChoice,
ParallelToolCalls = parallelToolCalls,
ResponseFormat = responseFormat,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public partial class AudioClient
/// <param name="prompt"></param>
/// <param name="responseFormat"></param>
/// <param name="temperature"></param>
/// <param name="timestampGranularities"></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<global::System.OneOf<global::G.CreateTranscriptionResponseJson, global::G.CreateTranscriptionResponseVerboseJson>> CreateTranscriptionAsync(
Expand All @@ -57,6 +58,7 @@ public partial class AudioClient
string? prompt = default,
global::G.CreateTranscriptionRequestResponseFormat? responseFormat = global::G.CreateTranscriptionRequestResponseFormat.Json,
double temperature = 0,
global::System.Collections.Generic.IList<global::G.CreateTranscriptionRequestTimestampGranularities?>? timestampGranularities = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new global::G.CreateTranscriptionRequest
Expand All @@ -67,6 +69,7 @@ public partial class AudioClient
Prompt = prompt,
ResponseFormat = responseFormat,
Temperature = temperature,
TimestampGranularities = timestampGranularities,
};

return await CreateTranscriptionAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace G
{
/// <summary>
/// Learn how to turn audio into text or text into audio.<br/>
/// Turn audio into text or text into audio.<br/>
/// If no httpClient is provided, a new one will be created.<br/>
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace G
public partial class BatchClient
{
/// <summary>
/// Cancels an in-progress batch.
/// Cancels an in-progress batch. The batch will be in status `cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file.
/// </summary>
/// <param name="batchId"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public partial class ChatClient
/// <param name="topP"></param>
/// <param name="tools"></param>
/// <param name="toolChoice"></param>
/// <param name="parallelToolCalls"></param>
/// <param name="user"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
Expand All @@ -82,6 +83,7 @@ public partial class ChatClient
double? topP = 1,
global::System.Collections.Generic.IList<global::G.ChatCompletionTool>? tools = default,
global::System.OneOf<global::G.CreateChatCompletionRequestToolChoice?, global::G.ChatCompletionNamedToolChoice?> toolChoice = default,
bool parallelToolCalls = true,
string? user = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand All @@ -105,6 +107,7 @@ public partial class ChatClient
TopP = topP,
Tools = tools,
ToolChoice = toolChoice,
ParallelToolCalls = parallelToolCalls,
User = user,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace G
public partial class FilesClient
{
/// <summary>
/// Upload a file that can be used across various endpoints. The size of all the files uploaded by one organization can be up to 100 GB.<br/>
/// The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See the [Assistants Tools guide](/docs/assistants/tools) to learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.<br/>
/// Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.<br/>
/// The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details.<br/>
/// The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models.<br/>
/// The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input).<br/>
/// Please [contact us](https://help.openai.com/) if you need to increase these storage limits.
/// </summary>
/// <param name="request"></param>
Expand Down Expand Up @@ -42,8 +44,10 @@ public partial class FilesClient
}

/// <summary>
/// Upload a file that can be used across various endpoints. The size of all the files uploaded by one organization can be up to 100 GB.<br/>
/// The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See the [Assistants Tools guide](/docs/assistants/tools) to learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.<br/>
/// Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.<br/>
/// The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details.<br/>
/// The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models.<br/>
/// The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input).<br/>
/// Please [contact us](https://help.openai.com/) if you need to increase these storage limits.
/// </summary>
/// <param name="file"></param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public sealed partial class AssistantObject
/// Default Value: []
/// </summary>
[global::Newtonsoft.Json.JsonProperty("tools", Required = global::Newtonsoft.Json.Required.Always)]
public global::System.Collections.Generic.IList<global::System.OneOf<global::G.AssistantToolsCode, global::G.AssistantToolsFileSearch, global::G.AssistantToolsFunction>> Tools { get; set; } = default!;
public global::System.Collections.Generic.IList<global::System.OneOf<global::G.AssistantToolsCode?, global::G.AssistantToolsFileSearch?, global::G.AssistantToolsFunction?>> Tools { get; set; } = default!;

/// <summary>
/// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
Expand All @@ -71,7 +71,7 @@ public sealed partial class AssistantObject
public object? Metadata { get; set; } = default!;

/// <summary>
/// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.<br/>
/// run_temperature_description | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.<br/>
/// Default Value: 1<br/>
/// Example: 1
/// </summary>
Expand All @@ -88,7 +88,7 @@ public sealed partial class AssistantObject
public double? TopP { get; set; } = 1;

/// <summary>
/// Specifies the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.<br/>
/// Specifies the format that the model must output. Compatible with [GPT-4o](/docs/models/gpt-4o), [GPT-4 Turbo](/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.<br/>
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.<br/>
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public sealed partial class AssistantToolsFileSearch
[global::Newtonsoft.Json.JsonProperty("type", Required = global::Newtonsoft.Json.Required.Always)]
public global::G.AssistantToolsFileSearchType Type { get; set; } = default!;

/// <summary>
/// Overrides for the file search tool.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("file_search")]
public global::G.AssistantToolsFileSearchFileSearch? FileSearch { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//HintName: G.Models.AssistantToolsFileSearchFileSearch.g.cs

#nullable enable

namespace G
{
/// <summary>
/// Overrides for the file search tool.
/// </summary>
public sealed partial class AssistantToolsFileSearchFileSearch
{
/// <summary>
/// The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive.<br/>
/// Note that the file search tool may output fewer than `max_num_results` results. See the [file search tool documentation](/docs/assistants/tools/file-search/number-of-chunks-returned) for more information.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("max_num_results")]
public int MaxNumResults { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::Newtonsoft.Json.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//HintName: G.Models.AssistantToolsFileSearchTypeOnly.g.cs

#nullable enable

namespace G
{
/// <summary>
///
/// </summary>
public sealed partial class AssistantToolsFileSearchTypeOnly
{
/// <summary>
/// The type of tool being defined: `file_search`
/// </summary>
[global::Newtonsoft.Json.JsonProperty("type", Required = global::Newtonsoft.Json.Required.Always)]
public global::G.AssistantToolsFileSearchTypeOnlyType Type { get; set; } = default!;

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::Newtonsoft.Json.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
Loading

0 comments on commit effbcd2

Please sign in to comment.