-
Notifications
You must be signed in to change notification settings - Fork 4.6k
.Net - OpenAI File Service ADR #4803
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
13 commits
Select commit
Hold shift + click to select a range
4150d9d
Initial
crickman 739757e
Merge branch 'main' into adr_fileservice
crickman 6a9ae43
Updated
crickman 0f9dd65
Merge branch 'main' into adr_fileservice
crickman d2de002
Content
crickman f42b0f7
Merge branch 'main' into adr_fileservice
crickman 005965b
Update 0026-file-service.md
crickman 66b5919
Merge branch 'main' into adr_fileservice
crickman 433114a
Update 0026-file-service.md
crickman 2854ad8
Merge branch 'main' into adr_fileservice
crickman 8ba0719
Merge branch 'main' into adr_fileservice
crickman c2ad399
Merge branch 'main' into adr_fileservice
crickman 12b1742
Merge branch 'main' into adr_fileservice
crickman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| --- | ||
| # These are optional elements. Feel free to remove any of them. | ||
| status: proposed | ||
| contact: crickman, mabolan, semenshi | ||
| date: 2024-01-16 | ||
| --- | ||
|
|
||
| # File Services | ||
|
|
||
| ## Context and Problem Statement | ||
| OpenAI provides a file service for uploading files to be used for *assistant retrieval* or *model fine-tuning*: `https://api.openai.com/v1/files` | ||
|
|
||
| Other providers may also offer some type of file-service, such as Gemini. | ||
|
|
||
| > Note: *Azure Open AI* does not currently support the OpenAI file service API. | ||
|
|
||
| ## Considered Options | ||
|
|
||
| 1. Add OpenAI file service support to `Microsoft.SemanticKernel.Experimental.Agents` | ||
| 2. Add a file service abstraction and implement support for OpenAI | ||
| 3. Add OpenAI file service support without abstraction | ||
|
|
||
| ## Decision Outcome | ||
|
|
||
| > Option 3. **Add OpenAI file service support without abstraction** | ||
| > Mark code as experimental using label: `SKEXP0015` | ||
|
|
||
| Defining a generalized file service interface provides an extensibility point for other vendors, in addition to *OpenAI*. | ||
|
|
||
| ## Pros and Cons of the Options | ||
|
|
||
| ### Option 1. Add OpenAI file service support to `Microsoft.SemanticKernel.Experimental.Agents` | ||
|
crickman marked this conversation as resolved.
|
||
| **Pro:** | ||
| 1. No impact to existing AI connectors. | ||
|
|
||
| **Con:** | ||
| 1. No reuse via AI connectors. | ||
| 1. No common abstraction. | ||
| 1. Unnatural dependency binding for uses other than with OpenAI assistants. | ||
|
|
||
| ### Option 2. Add a file service abstraction and implement support for OpenAI | ||
|
crickman marked this conversation as resolved.
|
||
| **Pro:** | ||
| 1. Defines a common interface for file service interactions. | ||
| 1. Allows for specialization for vendor specific services. | ||
|
|
||
| **Con:** | ||
| 1. Other systems may diverge from existing assumptions. | ||
|
|
||
|
|
||
| ### Option 3. Add OpenAI file service support without abstraction | ||
| **Pro:** | ||
| 1. Provides support for OpenAI file-service. | ||
|
|
||
| **Con:** | ||
| 1. File service offerings from other vendors supported case-by-case without commonality. | ||
|
|
||
|
|
||
| ## More Information | ||
|
|
||
| ### Signature of BinaryContent | ||
|
|
||
| > Note: `BinaryContent` object able to provide either `BinaryData` or `Stream` regardless of which constructor is invoked. | ||
|
|
||
| #### `Microsoft.SemanticKernel.Abstractions` | ||
|
|
||
| ```csharp | ||
| namespace Microsoft.SemanticKernel; | ||
|
|
||
| /// <summary> | ||
| /// Represents binary content. | ||
| /// </summary> | ||
| public sealed class BinaryContent : KernelContent | ||
| { | ||
| public BinaryContent( | ||
| BinaryData content, | ||
| string? modelId = null, | ||
| object? innerContent = null, | ||
| IReadOnlyDictionary<string, object?>? metadata = null); | ||
|
|
||
| public BinaryContent( | ||
| Func<Stream> streamProvider, | ||
| string? modelId = null, | ||
| object? innerContent = null, | ||
| IReadOnlyDictionary<string, object?>? metadata = null); | ||
|
|
||
| public Task<BinaryData> GetContentAsync(); | ||
|
|
||
| public Task<Stream> GetStreamAsync(); | ||
| } | ||
| ``` | ||
| ### Signatures for Option 3: | ||
|
|
||
| #### `Microsoft.SemanticKernel.Connectors.OpenAI` | ||
| ```csharp | ||
| namespace Microsoft.SemanticKernel.Connectors.OpenAI; | ||
|
|
||
| public sealed class OpenAIFileService | ||
| { | ||
| public async Task<OpenAIFileReference> GetFileAsync( | ||
| string id, | ||
| CancellationToken cancellationToken = default); | ||
|
|
||
| public async Task<IEnumerable<OpenAIFileReference>> GetFilesAsync(CancellationToken cancellationToken = default); | ||
|
|
||
| public async Task<BinaryContent> GetFileContentAsync( | ||
| string id, | ||
| CancellationToken cancellationToken = default); | ||
|
|
||
| public async Task DeleteFileAsync( | ||
| string id, | ||
| CancellationToken cancellationToken = default); | ||
|
|
||
| public async Task<OpenAIFileReference> UploadContentAsync( | ||
| BinaryContent content, | ||
| OpenAIFileUploadExecutionSettings settings, | ||
| CancellationToken cancellationToken = default); | ||
| } | ||
|
|
||
| public sealed class OpenAIFileUploadExecutionSettings | ||
| { | ||
| public string FileName { get; } | ||
|
|
||
| public OpenAIFilePurpose Purpose { get; } | ||
| } | ||
|
|
||
| public sealed class OpenAIFileReference | ||
| { | ||
| public string Id { get; set; } | ||
|
|
||
| public DateTime CreatedTimestamp { get; set; } | ||
|
|
||
| public string FileName { get; set; } | ||
|
|
||
| public OpenAIFilePurpose Purpose { get; set; } | ||
|
|
||
| public int SizeInBytes { get; set; } | ||
| } | ||
|
|
||
| public enum OpenAIFilePurpose | ||
| { | ||
| Assistants, | ||
| Finetuning, | ||
| } | ||
| ``` | ||
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.