Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: File-scoped namespaces, remove unused usings, and implement primary constructors #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using OpenAI.Files;
using System;
using System.ClientModel;
using System.Collections.Generic;
using System.IO;
using System.Threading;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using OpenAI.Files;
using System;
using System.ClientModel;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using OpenAI.Assistants;
using System;
using System.ClientModel;
using System.Collections.Generic;

namespace OpenAI.Examples;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using OpenAI.Assistants;
using System;
using System.ClientModel;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenAI.Examples;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace OpenAI.Assistants
namespace OpenAI.Assistants;

/// <summary> Text output from the Code Interpreter tool call as part of a run step. </summary>
[CodeGenModel("RunStepDetailsToolCallsCodeOutputLogsObject")]
internal partial class InternalRunStepCodeInterpreterLogOutput : RunStepCodeInterpreterOutput
{
/// <summary> Text output from the Code Interpreter tool call as part of a run step. </summary>
[CodeGenModel("RunStepDetailsToolCallsCodeOutputLogsObject")]
internal partial class InternalRunStepCodeInterpreterLogOutput : RunStepCodeInterpreterOutput
{
/// <summary> The text output from the Code Interpreter tool call. </summary>
[CodeGenMember("Logs")]
public string InternalLogs { get; }
}
}
/// <summary> The text output from the Code Interpreter tool call. </summary>
[CodeGenMember("Logs")]
public string InternalLogs { get; }
}
29 changes: 14 additions & 15 deletions src/Custom/Assistants/MessageCreationOptions.Serialization.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using System.ClientModel.Primitives;
using System.Text.Json;

namespace OpenAI.Assistants
namespace OpenAI.Assistants;

public partial class MessageCreationOptions : IJsonModel<MessageCreationOptions>
{
public partial class MessageCreationOptions : IJsonModel<MessageCreationOptions>
private void SerializeContent(Utf8JsonWriter writer, ModelReaderWriterOptions options = null)
{
private void SerializeContent(Utf8JsonWriter writer, ModelReaderWriterOptions options = null)
if (Content.Count == 1 && Content[0] is InternalRequestMessageTextContent textContent)
{
if (Content.Count == 1 && Content[0] is InternalRequestMessageTextContent textContent)
{
writer.WriteStringValue(textContent.Text);
}
else
writer.WriteStringValue(textContent.Text);
}
else
{
writer.WriteStartArray();
foreach (var item in Content)
{
writer.WriteStartArray();
foreach (var item in Content)
{
writer.WriteObjectValue<MessageContent>(item, options);
}
writer.WriteEndArray();
writer.WriteObjectValue<MessageContent>(item, options);
}
writer.WriteEndArray();
}
}
}
}
21 changes: 10 additions & 11 deletions src/Custom/Assistants/RunStepDetails.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace OpenAI.Assistants
namespace OpenAI.Assistants;

[Experimental("OPENAI001")]
[CodeGenModel("RunStepObjectStepDetails")]
public abstract partial class RunStepDetails
{
[Experimental("OPENAI001")]
[CodeGenModel("RunStepObjectStepDetails")]
public abstract partial class RunStepDetails
{
public string CreatedMessageId => AsInternalMessageCreation?.InternalMessageId;
public IReadOnlyList<RunStepToolCall> ToolCalls => AsInternalToolCalls ?? [];
public string CreatedMessageId => AsInternalMessageCreation?.InternalMessageId;
public IReadOnlyList<RunStepToolCall> ToolCalls => AsInternalToolCalls ?? [];

private InternalRunStepDetailsMessageCreationObject AsInternalMessageCreation => this as InternalRunStepDetailsMessageCreationObject;
private InternalRunStepDetailsToolCallsObject AsInternalToolCalls => this as InternalRunStepDetailsToolCallsObject;
}
}
private InternalRunStepDetailsMessageCreationObject AsInternalMessageCreation => this as InternalRunStepDetailsMessageCreationObject;
private InternalRunStepDetailsToolCallsObject AsInternalToolCalls => this as InternalRunStepDetailsToolCallsObject;
}
121 changes: 60 additions & 61 deletions src/Custom/Assistants/RunTruncationStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,68 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace OpenAI.Assistants
namespace OpenAI.Assistants;

/// <summary> Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run. </summary>
[Experimental("OPENAI001")]
[CodeGenModel("TruncationObject")]
[CodeGenSuppress(nameof(RunTruncationStrategy), typeof(InternalTruncationObjectType))]
public partial class RunTruncationStrategy
{
/// <summary> Controls for how a thread will be truncated prior to the run. Use this to control the intial context window of the run. </summary>
[Experimental("OPENAI001")]
[CodeGenModel("TruncationObject")]
[CodeGenSuppress(nameof(RunTruncationStrategy), typeof(InternalTruncationObjectType))]
public partial class RunTruncationStrategy
{
/// <summary>
/// Keeps track of any properties unknown to the library.
/// <para>
/// To assign an object to the value of this property use <see cref="BinaryData.FromObjectAsJson{T}(T, System.Text.Json.JsonSerializerOptions?)"/>.
/// </para>
/// <para>
/// To assign an already formatted json string to this property use <see cref="BinaryData.FromString(string)"/>.
/// </para>
/// <para>
/// Examples:
/// <list type="bullet">
/// <item>
/// <term>BinaryData.FromObjectAsJson("foo")</term>
/// <description>Creates a payload of "foo".</description>
/// </item>
/// <item>
/// <term>BinaryData.FromString("\"foo\"")</term>
/// <description>Creates a payload of "foo".</description>
/// </item>
/// <item>
/// <term>BinaryData.FromObjectAsJson(new { key = "value" })</term>
/// <description>Creates a payload of { "key": "value" }.</description>
/// </item>
/// <item>
/// <term>BinaryData.FromString("{\"key\": \"value\"}")</term>
/// <description>Creates a payload of { "key": "value" }.</description>
/// </item>
/// </list>
/// </para>
/// </summary>
private IDictionary<string, BinaryData> SerializedAdditionalRawData;
/// <summary>
/// Keeps track of any properties unknown to the library.
/// <para>
/// To assign an object to the value of this property use <see cref="BinaryData.FromObjectAsJson{T}(T, System.Text.Json.JsonSerializerOptions?)"/>.
/// </para>
/// <para>
/// To assign an already formatted json string to this property use <see cref="BinaryData.FromString(string)"/>.
/// </para>
/// <para>
/// Examples:
/// <list type="bullet">
/// <item>
/// <term>BinaryData.FromObjectAsJson("foo")</term>
/// <description>Creates a payload of "foo".</description>
/// </item>
/// <item>
/// <term>BinaryData.FromString("\"foo\"")</term>
/// <description>Creates a payload of "foo".</description>
/// </item>
/// <item>
/// <term>BinaryData.FromObjectAsJson(new { key = "value" })</term>
/// <description>Creates a payload of { "key": "value" }.</description>
/// </item>
/// <item>
/// <term>BinaryData.FromString("{\"key\": \"value\"}")</term>
/// <description>Creates a payload of { "key": "value" }.</description>
/// </item>
/// </list>
/// </para>
/// </summary>
private IDictionary<string, BinaryData> SerializedAdditionalRawData;

/// <summary> The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the n most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`. </summary>
[CodeGenMember("Type")]
internal readonly InternalTruncationObjectType _type;
/// <summary> The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will be truncated to the n most recent messages in the thread. When set to `auto`, messages in the middle of the thread will be dropped to fit the context length of the model, `max_prompt_tokens`. </summary>
[CodeGenMember("Type")]
internal readonly InternalTruncationObjectType _type;

/// <summary> The number of most recent messages from the thread when constructing the context for the run. </summary>
/// <remarks>
/// </remarks>
[CodeGenMember("LastMessages")]
public int? LastMessages { get; }
/// <summary> The number of most recent messages from the thread when constructing the context for the run. </summary>
/// <remarks>
/// </remarks>
[CodeGenMember("LastMessages")]
public int? LastMessages { get; }

/// <summary>
/// The default <see cref="RunTruncationStrategy"/> that will eliminate messages in the middle of the thread
/// to fit within the context length of the model or the max prompt tokens.
/// </summary>
public static RunTruncationStrategy Auto { get; } = new(InternalTruncationObjectType.Auto, 0, null);
/// <summary>
/// The default <see cref="RunTruncationStrategy"/> that will eliminate messages in the middle of the thread
/// to fit within the context length of the model or the max prompt tokens.
/// </summary>
public static RunTruncationStrategy Auto { get; } = new(InternalTruncationObjectType.Auto, 0, null);

/// <summary>
/// Creates a new <see cref="RunTruncationStrategy"/> instance using the <c>last_messages</c> strategy type,
/// which will truncate the thread to specified count of preceding messages for the run.
/// </summary>
/// <param name="lastMessageCount"> The count of last messages that the run should evaluate. </param>
/// <returns></returns>
public static RunTruncationStrategy CreateLastMessagesStrategy(int lastMessageCount)
=> new(InternalTruncationObjectType.LastMessages, lastMessageCount, null);
}
}
/// <summary>
/// Creates a new <see cref="RunTruncationStrategy"/> instance using the <c>last_messages</c> strategy type,
/// which will truncate the thread to specified count of preceding messages for the run.
/// </summary>
/// <param name="lastMessageCount"> The count of last messages that the run should evaluate. </param>
/// <returns></returns>
public static RunTruncationStrategy CreateLastMessagesStrategy(int lastMessageCount)
=> new(InternalTruncationObjectType.LastMessages, lastMessageCount, null);
}
1 change: 0 additions & 1 deletion src/Custom/Audio/AudioTranscriptionOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using OpenAI.Internal;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down
3 changes: 0 additions & 3 deletions src/Custom/Audio/AudioTranslationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.Embeddings;
using OpenAI.Images;
using OpenAI.Internal;
using System;
using System.IO;

Expand Down
3 changes: 0 additions & 3 deletions src/Custom/Chat/ChatResponseFormat.Serialization.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text.Json;

namespace OpenAI.Chat;
Expand Down
1 change: 0 additions & 1 deletion src/Custom/Chat/ChatTokenTopLogProbabilityDetails.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace OpenAI.Chat;

Expand Down
1 change: 0 additions & 1 deletion src/Custom/Chat/ChatToolCall.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace OpenAI.Chat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System.ClientModel.Primitives;
using System.Data;
using System.Text.Json;
using System;

namespace OpenAI.Chat;
namespace OpenAI.Chat;

[CodeGenModel("ChatResponseFormatJsonSchema")]
internal partial class InternalChatResponseFormatJsonSchema
Expand Down
4 changes: 0 additions & 4 deletions src/Custom/Chat/Streaming/StreamingChatToolCallUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
namespace OpenAI.Chat;

using System;
using System.Text.Json;

/// <summary>
/// A base representation of an incremental update to a streaming tool call that is part of a streaming chat completion
/// request.
Expand Down
1 change: 0 additions & 1 deletion src/Custom/FineTuning/FineTuningClient.Protocol.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenAI.FineTuning;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using OpenAI.Models;
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Reflection;
using System.Text.Json;

namespace OpenAI.Models;
Expand Down
1 change: 0 additions & 1 deletion src/Custom/Models/OpenAIModelInfoCollection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;

namespace OpenAI.Models;

Expand Down
1 change: 0 additions & 1 deletion src/Custom/VectorStores/VectorStoreCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace OpenAI.VectorStores;
Expand Down
Loading