-
Notifications
You must be signed in to change notification settings - Fork 349
[ModelFactory] Implemented Audio, Embedding, and Image factories #139
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c66a25
[ModelFactory] Implemented Audio, Embedding, and Image factories
kinelski 822d6ad
Addressing PR feedback (#139)
kinelski 39f32f1
Addressing PR feedback (2) (#139)
kinelski 958da41
Merge remote-tracking branch 'origin/main' into factory
kinelski 398938e
Addressing PR feedback (3) (#139)
kinelski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace OpenAI.Audio; | ||
|
|
||
| /// <summary> Model factory for models. </summary> | ||
| public static partial class OpenAIAudioModelFactory | ||
| { | ||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Audio.AudioTranscription"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Audio.AudioTranscription"/> instance for mocking. </returns> | ||
| public static AudioTranscription AudioTranscription(string language = null, TimeSpan? duration = null, string text = null, IEnumerable<TranscribedWord> words = null, IEnumerable<TranscribedSegment> segments = null) | ||
| { | ||
| words ??= new List<TranscribedWord>(); | ||
| segments ??= new List<TranscribedSegment>(); | ||
|
|
||
| return new AudioTranscription( | ||
| InternalCreateTranscriptionResponseVerboseJsonTask.Transcribe, | ||
| language, | ||
| duration, | ||
| text, | ||
| words.ToList(), | ||
| segments.ToList(), | ||
| serializedAdditionalRawData: null); | ||
| } | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Audio.AudioTranslation"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Audio.AudioTranslation"/> instance for mocking. </returns> | ||
| public static AudioTranslation AudioTranslation(string language = null, TimeSpan? duration = null, string text = null, IEnumerable<TranscribedSegment> segments = null) | ||
kinelski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| segments ??= new List<TranscribedSegment>(); | ||
|
|
||
| return new AudioTranslation( | ||
| InternalCreateTranslationResponseVerboseJsonTask.Translate, | ||
| language, | ||
| duration, | ||
| text, | ||
| segments.ToList(), | ||
| serializedAdditionalRawData: null); | ||
| } | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Audio.TranscribedSegment"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Audio.TranscribedSegment"/> instance for mocking. </returns> | ||
| public static TranscribedSegment TranscribedSegment(int id = default, long seekOffset = default, TimeSpan start = default, TimeSpan end = default, string text = null, IEnumerable<long> tokenIds = null, float temperature = default, double averageLogProbability = default, float compressionRatio = default, double noSpeechProbability = default) | ||
| { | ||
| tokenIds ??= new List<long>(); | ||
|
|
||
| return new TranscribedSegment( | ||
| id, | ||
| seekOffset, | ||
| start, | ||
| end, | ||
| text, | ||
| tokenIds.ToList(), | ||
| temperature, | ||
| averageLogProbability, | ||
| compressionRatio, | ||
| noSpeechProbability, | ||
| serializedAdditionalRawData: null); | ||
| } | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Audio.TranscribedWord"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Audio.TranscribedWord"/> instance for mocking. </returns> | ||
| public static TranscribedWord TranscribedWord(string word = null, TimeSpan start = default, TimeSpan end = default) | ||
| { | ||
| return new TranscribedWord( | ||
| word, | ||
| start, | ||
| end, | ||
| serializedAdditionalRawData: null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace OpenAI.Embeddings; | ||
|
|
||
| /// <summary> Model factory for models. </summary> | ||
| public static partial class OpenAIEmbeddingsModelFactory | ||
| { | ||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.Embedding"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Embeddings.Embeddings"/> instance for mocking. </returns> | ||
| public static Embedding Embedding(int index = default, IEnumerable<float> vector = null) | ||
| { | ||
| vector ??= new List<float>(); | ||
|
|
||
| return new Embedding( | ||
| index, | ||
| vector.ToArray()); | ||
| } | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.EmbeddingCollection"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Embeddings.EmbeddingCollection"/> instance for mocking. </returns> | ||
| public static EmbeddingCollection EmbeddingCollection(IEnumerable<Embedding> items = null, string model = null, EmbeddingTokenUsage usage = null) | ||
| { | ||
| items ??= new List<Embedding>(); | ||
|
|
||
| return new EmbeddingCollection( | ||
| items.ToList(), | ||
| model, | ||
| @object: default, | ||
| usage, | ||
| serializedAdditionalRawData: null); | ||
| } | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Embeddings.EmbeddingTokenUsage"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Embeddings.EmbeddingTokenUsage"/> instance for mocking. </returns> | ||
| public static EmbeddingTokenUsage EmbeddingTokenUsage(int inputTokens = default, int totalTokens = default) | ||
| { | ||
| return new EmbeddingTokenUsage( | ||
| inputTokens, | ||
| totalTokens, | ||
| serializedAdditionalRawData: null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace OpenAI.Images; | ||
|
|
||
| /// <summary> Model factory for models. </summary> | ||
| public static partial class OpenAIImagesModelFactory | ||
| { | ||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Images.GeneratedImage"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Images.GeneratedImage"/> instance for mocking. </returns> | ||
| public static GeneratedImage GeneratedImage(BinaryData imageBytes = null, Uri imageUri = null, string revisedPrompt = null) | ||
| { | ||
| return new GeneratedImage( | ||
| imageBytes, | ||
| imageUri, | ||
| revisedPrompt, | ||
| serializedAdditionalRawData: null); | ||
| } | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="OpenAI.Images.GeneratedImageCollection"/>. </summary> | ||
| /// <returns> A new <see cref="OpenAI.Images.GeneratedImageCollection"/> instance for mocking. </returns> | ||
| public static GeneratedImageCollection GeneratedImageCollection(DateTimeOffset createdAt = default, IEnumerable<GeneratedImage> items = null) | ||
| { | ||
| items ??= new List<GeneratedImage>(); | ||
|
|
||
| return new GeneratedImageCollection( | ||
| createdAt, | ||
| items.ToList(), | ||
| serializedAdditionalRawData: null); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.