Skip to content

Commit

Permalink
Remove the virtual keyword from the Pipeline property across all clie…
Browse files Browse the repository at this point in the history
…nts (openai#227)

Co-authored-by: ShivangiReja <[email protected]>
  • Loading branch information
ShivangiReja and ShivangiReja authored Sep 26, 2024
1 parent 19ceae4 commit 75eded5
Show file tree
Hide file tree
Showing 53 changed files with 240 additions and 135 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

### Breaking Changes

- Refactored `ModerationResult` by merging `ModerationCategories` and `ModerationCategoryScores` into individual `ModerationCategory` properties, each with `Flagged` and `Score` properties. (commit_hash)
- Refactored `ModerationResult` by merging `ModerationCategories` and `ModerationCategoryScores` into individual `ModerationCategory` properties, each with `Flagged` and `Score` properties. (commit_id)
- Renamed type `OpenAIFileInfo` to `OpenAIFile` and `OpenAIFileInfoCollection` to `OpenAIFileCollection`. (commit_id)
- Renamed type `OpenAIModelInfo` to `OpenAIModel` and `OpenAIModelInfoCollection` to `OpenAIModelCollection`. (commit_id)
- Renamed type `Embedding` to `OpenAIEmbedding` and `EmbeddingCollection` to `OpenAIEmbeddingCollection`. (commit_id)
- Renamed property `ImageUrl` to `ImageUri` and method `FromImageUrl` to `FromImageUri` in `MessageContent`. (commit_id)
- Renamed property `ParallelToolCallsEnabled` to `AllowParallelToolCalls` in `RunCreationOptions`, `ThreadRun`, and `ChatCompletionOptions` types. (commit_id)
- Renamed property `PromptTokens` to `InputTokenCount`, `CompletionTokens` to `OutputTokenCount`, and `TotalTokens` to `TotalTokenCount` in `RunTokenUsage`. (commit_id)
- Renamed property `InputTokens` to `InputTokenCount` and `TotalTokens` to `TotalTokenCount` in `EmbeddingTokenUsage`. (commit_id)
- Renamed property `ImageUrl` to `ImageUri` and method `FromImageUrl` to `FromImageUri` in the `MessageContent` type. (commit_id)
- Renamed property `ParallelToolCallsEnabled` to `AllowParallelToolCalls` in the `RunCreationOptions`, `ThreadRun`, and `ChatCompletionOptions` types. (commit_id)
- Renamed properties `PromptTokens` to `InputTokenCount`, `CompletionTokens` to `OutputTokenCount`, and `TotalTokens` to `TotalTokenCount` in the `RunTokenUsage` and `RunStepTokenUsage` types. (commit_id)
- Renamed properties `InputTokens` to `InputTokenCount` and `TotalTokens` to `TotalTokenCount` in the `EmbeddingTokenUsage` type. (commit_id)
- Renamed properties `MaxPromptTokens` to `MaxInputTokenCount` and `MaxCompletionTokens` to `MaxOutputTokenCount` in the `ThreadRun`, `RunCreationOptions`, and `RunIncompleteReason` types. (commit_id)
- Removed the `virtual` keyword from the `Pipeline` property across all clients. (commit_id)

### Bugs Fixed

Expand Down
48 changes: 24 additions & 24 deletions api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class OpenAIClient {
protected internal OpenAIClient(ClientPipeline pipeline, OpenAIClientOptions options);
public OpenAIClient(string apiKey, OpenAIClientOptions options);
public OpenAIClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual AssistantClient GetAssistantClient();
public virtual AudioClient GetAudioClient(string model);
public virtual BatchClient GetBatchClient();
Expand Down Expand Up @@ -53,7 +53,7 @@ public class AssistantClient {
protected internal AssistantClient(ClientPipeline pipeline, OpenAIClientOptions options);
public AssistantClient(string apiKey, OpenAIClientOptions options);
public AssistantClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult<ThreadRun> CancelRun(ThreadRun run);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult CancelRun(string threadId, string runId, RequestOptions options);
Expand Down Expand Up @@ -600,8 +600,8 @@ public class RunCreationOptions : IJsonModel<RunCreationOptions>, IPersistableMo
public IList<ThreadInitializationMessage> AdditionalMessages { get; }
public bool? AllowParallelToolCalls { get; set; }
public string InstructionsOverride { get; set; }
public int? MaxCompletionTokens { get; set; }
public int? MaxPromptTokens { get; set; }
public int? MaxInputTokenCount { get; set; }
public int? MaxOutputTokenCount { get; set; }
public IDictionary<string, string> Metadata { get; }
public string ModelOverride { get; set; }
public float? NucleusSamplingFactor { get; set; }
Expand Down Expand Up @@ -654,8 +654,8 @@ public class RunIncompleteDetails : IJsonModel<RunIncompleteDetails>, IPersistab
private readonly object _dummy;
private readonly int _dummyPrimitive;
public RunIncompleteReason(string value);
public static RunIncompleteReason MaxCompletionTokens { get; }
public static RunIncompleteReason MaxPromptTokens { get; }
public static RunIncompleteReason MaxInputTokenCount { get; }
public static RunIncompleteReason MaxOutputTokenCount { get; }
public readonly bool Equals(RunIncompleteReason other);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly bool Equals(object obj);
Expand Down Expand Up @@ -826,9 +826,9 @@ public class RunStepFileSearchResult : IJsonModel<RunStepFileSearchResult>, IPer
public override readonly string ToString();
}
public class RunStepTokenUsage : IJsonModel<RunStepTokenUsage>, IPersistableModel<RunStepTokenUsage> {
public int CompletionTokens { get; }
public int PromptTokens { get; }
public int TotalTokens { get; }
public int InputTokenCount { get; }
public int OutputTokenCount { get; }
public int TotalTokenCount { get; }
RunStepTokenUsage IJsonModel<RunStepTokenUsage>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
void IJsonModel<RunStepTokenUsage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
RunStepTokenUsage IPersistableModel<RunStepTokenUsage>.Create(BinaryData data, ModelReaderWriterOptions options);
Expand Down Expand Up @@ -1022,8 +1022,8 @@ public class ThreadRun : IJsonModel<ThreadRun>, IPersistableModel<ThreadRun> {
public RunIncompleteDetails IncompleteDetails { get; }
public string Instructions { get; }
public RunError LastError { get; }
public int? MaxCompletionTokens { get; }
public int? MaxPromptTokens { get; }
public int? MaxInputTokenCount { get; }
public int? MaxOutputTokenCount { get; }
public IReadOnlyDictionary<string, string> Metadata { get; }
public string Model { get; }
public float? NucleusSamplingFactor { get; }
Expand Down Expand Up @@ -1114,7 +1114,7 @@ public class AudioClient {
public AudioClient(string model, ApiKeyCredential credential);
public AudioClient(string model, string apiKey, OpenAIClientOptions options);
public AudioClient(string model, string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult GenerateSpeech(BinaryContent content, RequestOptions options = null);
public virtual ClientResult<BinaryData> GenerateSpeech(string text, GeneratedSpeechVoice voice, SpeechGenerationOptions options = null, CancellationToken cancellationToken = default);
Expand Down Expand Up @@ -1306,7 +1306,7 @@ public class BatchClient {
protected internal BatchClient(ClientPipeline pipeline, OpenAIClientOptions options);
public BatchClient(string apiKey, OpenAIClientOptions options);
public BatchClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult CancelBatch(string batchId, RequestOptions options);
public virtual Task<ClientResult> CancelBatchAsync(string batchId, RequestOptions options);
public virtual ClientResult CreateBatch(BinaryContent content, RequestOptions options = null);
Expand Down Expand Up @@ -1343,7 +1343,7 @@ public class ChatClient {
public ChatClient(string model, ApiKeyCredential credential);
public ChatClient(string model, string apiKey, OpenAIClientOptions options);
public ChatClient(string model, string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult<ChatCompletion> CompleteChat(params ChatMessage[] messages);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult CompleteChat(BinaryContent content, RequestOptions options = null);
Expand Down Expand Up @@ -1660,10 +1660,10 @@ public class FunctionChatMessage : ChatMessage, IJsonModel<FunctionChatMessage>,
}
public static class OpenAIChatModelFactory {
public static ChatCompletion ChatCompletion(string id = null, ChatFinishReason finishReason = ChatFinishReason.Stop, IEnumerable<ChatMessageContentPart> content = null, string refusal = null, IEnumerable<ChatToolCall> toolCalls = null, ChatMessageRole role = ChatMessageRole.System, ChatFunctionCall functionCall = null, IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = null, IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = null, DateTimeOffset createdAt = default, string model = null, string systemFingerprint = null, ChatTokenUsage usage = null);
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokens = 0);
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = 0);
public static ChatTokenLogProbabilityDetails ChatTokenLogProbabilityDetails(string token = null, float logProbability = 0, ReadOnlyMemory<byte>? utf8Bytes = null, IEnumerable<ChatTokenTopLogProbabilityDetails> topLogProbabilities = null);
public static ChatTokenTopLogProbabilityDetails ChatTokenTopLogProbabilityDetails(string token = null, float logProbability = 0, ReadOnlyMemory<byte>? utf8Bytes = null);
public static ChatTokenUsage ChatTokenUsage(int outputTokens = 0, int inputTokens = 0, int totalTokens = 0, ChatOutputTokenUsageDetails outputTokenDetails = null);
public static ChatTokenUsage ChatTokenUsage(int outputTokenCount = 0, int inputTokenCount = 0, int totalTokenCount = 0, ChatOutputTokenUsageDetails outputTokenDetails = null);
public static StreamingChatCompletionUpdate StreamingChatCompletionUpdate(string id = null, IEnumerable<ChatMessageContentPart> contentUpdate = null, StreamingChatFunctionCallUpdate functionCallUpdate = null, IEnumerable<StreamingChatToolCallUpdate> toolCallUpdates = null, ChatMessageRole? role = null, string refusalUpdate = null, IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = null, IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = null, ChatFinishReason? finishReason = null, DateTimeOffset createdAt = default, string model = null, string systemFingerprint = null, ChatTokenUsage usage = null);
[Obsolete("This class is obsolete. Please use StreamingChatToolCallUpdate instead.")]
public static StreamingChatFunctionCallUpdate StreamingChatFunctionCallUpdate(string functionArgumentsUpdate = null, string functionName = null);
Expand Down Expand Up @@ -1754,7 +1754,7 @@ public class EmbeddingClient {
public EmbeddingClient(string model, ApiKeyCredential credential);
public EmbeddingClient(string model, string apiKey, OpenAIClientOptions options);
public EmbeddingClient(string model, string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult<OpenAIEmbedding> GenerateEmbedding(string input, EmbeddingGenerationOptions options = null, CancellationToken cancellationToken = default);
public virtual Task<ClientResult<OpenAIEmbedding>> GenerateEmbeddingAsync(string input, EmbeddingGenerationOptions options = null, CancellationToken cancellationToken = default);
[EditorBrowsable(EditorBrowsableState.Never)]
Expand Down Expand Up @@ -1803,7 +1803,7 @@ public class OpenAIEmbeddingCollection : ObjectModel.ReadOnlyCollection<OpenAIEm
BinaryData IPersistableModel<OpenAIEmbeddingCollection>.Write(ModelReaderWriterOptions options);
}
public static class OpenAIEmbeddingsModelFactory {
public static EmbeddingTokenUsage EmbeddingTokenUsage(int inputTokens = 0, int totalTokens = 0);
public static EmbeddingTokenUsage EmbeddingTokenUsage(int inputTokenCount = 0, int totalTokenCount = 0);
public static OpenAIEmbedding OpenAIEmbedding(int index = 0, IEnumerable<float> vector = null);
public static OpenAIEmbeddingCollection OpenAIEmbeddingCollection(IEnumerable<OpenAIEmbedding> items = null, string model = null, EmbeddingTokenUsage usage = null);
}
Expand All @@ -1816,7 +1816,7 @@ public class FileClient {
protected internal FileClient(ClientPipeline pipeline, OpenAIClientOptions options);
public FileClient(string apiKey, OpenAIClientOptions options);
public FileClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult AddUploadPart(string uploadId, BinaryContent content, string contentType, RequestOptions options = null);
public virtual Task<ClientResult> AddUploadPartAsync(string uploadId, BinaryContent content, string contentType, RequestOptions options = null);
public virtual ClientResult CancelUpload(string uploadId, RequestOptions options = null);
Expand Down Expand Up @@ -1965,7 +1965,7 @@ public class FineTuningClient {
protected internal FineTuningClient(ClientPipeline pipeline, OpenAIClientOptions options);
public FineTuningClient(string apiKey, OpenAIClientOptions options);
public FineTuningClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult CancelJob(string jobId, RequestOptions options);
public virtual Task<ClientResult> CancelJobAsync(string jobId, RequestOptions options);
public virtual ClientResult CreateJob(BinaryContent content, RequestOptions options = null);
Expand Down Expand Up @@ -2036,7 +2036,7 @@ public class ImageClient {
public ImageClient(string model, ApiKeyCredential credential);
public ImageClient(string model, string apiKey, OpenAIClientOptions options);
public ImageClient(string model, string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult<GeneratedImage> GenerateImage(string prompt, ImageGenerationOptions options = null, CancellationToken cancellationToken = default);
public virtual Task<ClientResult<GeneratedImage>> GenerateImageAsync(string prompt, ImageGenerationOptions options = null, CancellationToken cancellationToken = default);
public virtual ClientResult<GeneratedImage> GenerateImageEdit(Stream image, string imageFilename, string prompt, ImageEditOptions options = null, CancellationToken cancellationToken = default);
Expand Down Expand Up @@ -2123,7 +2123,7 @@ public class ModelClient {
protected internal ModelClient(ClientPipeline pipeline, OpenAIClientOptions options);
public ModelClient(string apiKey, OpenAIClientOptions options);
public ModelClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult DeleteModel(string model, RequestOptions options);
public virtual ClientResult<ModelDeletionResult> DeleteModel(string model, CancellationToken cancellationToken = default);
Expand Down Expand Up @@ -2187,7 +2187,7 @@ public class ModerationClient {
public ModerationClient(string model, ApiKeyCredential credential);
public ModerationClient(string model, string apiKey, OpenAIClientOptions options);
public ModerationClient(string model, string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult ClassifyText(BinaryContent content, RequestOptions options = null);
public virtual ClientResult<ModerationResultCollection> ClassifyText(IEnumerable<string> inputs, CancellationToken cancellationToken = default);
Expand Down Expand Up @@ -2315,7 +2315,7 @@ public class VectorStoreClient {
protected internal VectorStoreClient(ClientPipeline pipeline, OpenAIClientOptions options);
public VectorStoreClient(string apiKey, OpenAIClientOptions options);
public VectorStoreClient(string apiKey);
public virtual ClientPipeline Pipeline { get; }
public ClientPipeline Pipeline { get; }
public virtual ClientResult<VectorStoreFileAssociation> AddFileToVectorStore(VectorStore vectorStore, OpenAIFile file);
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult AddFileToVectorStore(string vectorStoreId, BinaryContent content, RequestOptions options = null);
Expand Down
10 changes: 8 additions & 2 deletions src/Custom/Assistants/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public partial class AssistantClient
private readonly InternalAssistantRunClient _runSubClient;
private readonly InternalAssistantThreadClient _threadSubClient;

// CUSTOM: Remove virtual keyword.
/// <summary>
/// The HTTP pipeline for sending and receiving REST requests and responses.
/// </summary>
public ClientPipeline Pipeline => _pipeline;

// CUSTOM: Added as a convenience.
/// <summary> Initializes a new instance of <see cref="AssistantClient">. </summary>
/// <param name="apiKey"> The API key to authenticate with the service. </param>
Expand Down Expand Up @@ -1263,8 +1269,8 @@ private static BinaryContent CreateThreadAndRunProtocolContent(
runOptions.Temperature,
runOptions.NucleusSamplingFactor,
runOptions.Stream,
runOptions.MaxPromptTokens,
runOptions.MaxCompletionTokens,
runOptions.MaxInputTokenCount,
runOptions.MaxOutputTokenCount,
runOptions.TruncationStrategy,
runOptions.ToolConstraint,
runOptions.AllowParallelToolCalls,
Expand Down
8 changes: 0 additions & 8 deletions src/Custom/Assistants/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public readonly partial struct RunErrorCode { }
[CodeGenModel("RunObjectIncompleteDetails")]
public partial class RunIncompleteDetails { }

[Experimental("OPENAI001")]
[CodeGenModel("RunObjectIncompleteDetailsReason")]
public readonly partial struct RunIncompleteReason { }

[Experimental("OPENAI001")]
[CodeGenModel("RunStepObjectType")]
public readonly partial struct RunStepType { }
Expand All @@ -54,10 +50,6 @@ public partial class RunStepError { }
[CodeGenModel("RunStepObjectLastErrorCode")]
public readonly partial struct RunStepErrorCode { }

[Experimental("OPENAI001")]
[CodeGenModel("RunStepCompletionUsage")]
public partial class RunStepTokenUsage { }

[Experimental("OPENAI001")]
[CodeGenModel("RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsObject")]
public partial class RunStepCodeInterpreterOutput { }
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace OpenAI.Assistants;
[CodeGenSuppress("DeleteMessage", typeof(string), typeof(string))]
internal partial class InternalAssistantMessageClient
{
// CUSTOM: Remove virtual keyword.
/// <summary>
/// The HTTP pipeline for sending and receiving REST requests and responses.
/// </summary>
public ClientPipeline Pipeline => _pipeline;

// CUSTOM:
// - Used a custom pipeline.
// - Demoted the endpoint parameter to be a property in the options class.
Expand Down
6 changes: 6 additions & 0 deletions src/Custom/Assistants/Internal/InternalAssistantRunClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ namespace OpenAI.Assistants;
[CodeGenSuppress("GetRunStep", typeof(string), typeof(string), typeof(string))]
internal partial class InternalAssistantRunClient
{
// CUSTOM: Remove virtual keyword.
/// <summary>
/// The HTTP pipeline for sending and receiving REST requests and responses.
/// </summary>
public ClientPipeline Pipeline => _pipeline;

// CUSTOM:
// - Used a custom pipeline.
// - Demoted the endpoint parameter to be a property in the options class.
Expand Down
Loading

0 comments on commit 75eded5

Please sign in to comment.