-
Notifications
You must be signed in to change notification settings - Fork 12
Adds support for conversion of API manifest document to OpenAI Plugin manifest #34
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
11 commits
Select commit
Hold shift + click to select a range
ba7dfe2
- Adds conversion of API manifest document to OpenAI Plugin manifest.
peombwa 50acade
chore: Validate the ApiManifestDocument before generating the OpenAI …
peombwa 8840b34
chore: Move error messages to constants.
peombwa a391b48
chore: Add tests.
peombwa 33c59d2
chore: Adds changelong and expands codeowners.
peombwa 2b4c048
Merge branch 'main' into feature/GeneratePluginManifest
peombwa 572c3c7
chore: Mock HttpResponse.
peombwa 98ef464
Merge branch 'main' into feature/GeneratePluginManifest
peombwa 4b71724
chore: Lazy load singleton HttpClient.
peombwa a673dec
chore: Use inline httpClient initialization.
peombwa 46b4974
Apply suggestions from code review
baywet 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| * @peombwa @darrelmiller @baywet | ||
| * @peombwa @darrelmiller @baywet @zengin |
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,33 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
|
|
||
| - Added support for conversion of API manifest document to OpenAI Plugin manifest. #4 | ||
| - Added VerificationTokens property to OpenAI Plugin manifest auth type. #32 | ||
| - Added OpenAI Plugin manifest validation. #32 | ||
| - Added API Manifest validation. #5 | ||
| - Added ApplicationName property to ApiManifestDocument. #5 | ||
|
|
||
| ### Changed | ||
|
|
||
| - Renamed Request class to RequestInfo to align with the API manifest specification. #21 | ||
| - Renamed Auth property in ApiDependency to AuthorizationRequirements to align with the API manifest specification. #5 | ||
|
|
||
| ## [0.5.1] - 2023-08-17 | ||
|
|
||
| ### Changed | ||
|
|
||
| - Fixed typos in properties. | ||
|
|
||
| ## [0.5.0] - 2023-08-17 | ||
|
|
||
| ### Added | ||
|
|
||
| - Initial release of the library. |
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
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,16 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.Exceptions | ||
| { | ||
| public class ApiManifestException : Exception | ||
| { | ||
| public ApiManifestException(string message) : base(message) | ||
| { | ||
| } | ||
|
|
||
| public ApiManifestException(string message, Exception innerException) : base(message, innerException) | ||
| { | ||
| } | ||
| } | ||
| } |
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
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,78 @@ | ||
| using Microsoft.OpenApi.ApiManifest.Exceptions; | ||
| using Microsoft.OpenApi.ApiManifest.Helpers; | ||
| using Microsoft.OpenApi.ApiManifest.OpenAI; | ||
| using Microsoft.OpenApi.ApiManifest.OpenAI.Authentication; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.TypeExtensions | ||
| { | ||
| public static class ApiManifestDocumentExtensions | ||
| { | ||
| /// <summary> | ||
| /// Converts an instance of <see cref="ApiManifestDocument"/> to an instance of <see cref="OpenAIPluginManifest"/>. | ||
| /// </summary> | ||
| /// <param name="apiManifestDocument">A valid instance of <see cref="ApiManifestDocument"/> to generate an OpenAI Plugin manifest from.</param> | ||
| /// <param name="logoUrl">The URL to a logo for the plugin.</param> | ||
| /// <param name="legalInfoUrl">The URL to a page with legal information about the plugin.</param> | ||
| /// <param name="apiDependencyName">The name of apiDependency to use from the provided <see cref="ApiManifestDocument.ApiDependencies"/>. The method defaults to the first apiDependency in <see cref="ApiManifestDocument.ApiDependencies"/> if no value is provided.</param> | ||
| /// <param name="openApiPath">The path to where the OpenAPI file that's packaged with the plugin manifest is stored. The method defaults to the ApiDependency.ApiDescriptionUrl if none is provided.</param> | ||
| /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
| /// <returns>A <see cref="Task{OpenAIPluginManifest}"/></returns> | ||
| public static async Task<OpenAIPluginManifest> ToOpenAIPluginManifestAsync(this ApiManifestDocument apiManifestDocument, string logoUrl, string legalInfoUrl, string? apiDependencyName = default, string? openApiPath = default, CancellationToken cancellationToken = default) | ||
| { | ||
| if (!TryGetApiDependency(apiManifestDocument.ApiDependencies, apiDependencyName, out ApiDependency? apiDependency)) | ||
| { | ||
| throw new ApiManifestException(string.Format(ErrorMessage.ApiDependencyNotFound, nameof(OpenAIPluginManifest))); | ||
| } | ||
| else if (string.IsNullOrWhiteSpace(apiDependency?.ApiDescriptionUrl)) | ||
| { | ||
| throw new ApiManifestException(string.Format(ErrorMessage.ApiDescriptionUrlNotFound, nameof(OpenAIPluginManifest))); | ||
| } | ||
| else | ||
| { | ||
| var result = await ParsingHelpers.ParseOpenApiAsync(new Uri(apiDependency.ApiDescriptionUrl), false, cancellationToken).ConfigureAwait(false); | ||
| return apiManifestDocument.ToOpenAIPluginManifest(result.OpenApiDocument, logoUrl, legalInfoUrl, openApiPath ?? apiDependency.ApiDescriptionUrl); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts an instance of <see cref="ApiManifestDocument"/> to an instance of <see cref="OpenAIPluginManifest"/>. | ||
| /// </summary> | ||
| /// <param name="apiManifestDocument">A valid instance of <see cref="ApiManifestDocument"/> with at least one API dependency.</param> | ||
| /// <param name="openApiDocument">The OpenAPI document to use for the OpenAIPluginManifest.</param> | ||
| /// <param name="logoUrl">The URL to a logo for the plugin.</param> | ||
| /// <param name="legalInfoUrl">The URL to a page with legal information about the plugin.</param> | ||
| /// <param name="openApiPath">The path to where the OpenAPI file that's packaged with the plugin manifest is stored.</param> | ||
| /// <returns>A <see cref="OpenAIPluginManifest"/></returns> | ||
| public static OpenAIPluginManifest ToOpenAIPluginManifest(this ApiManifestDocument apiManifestDocument, OpenApiDocument openApiDocument, string logoUrl, string legalInfoUrl, string openApiPath) | ||
| { | ||
| // Validates the ApiManifestDocument before generating the OpenAI manifest. This includes the publisher object. | ||
| apiManifestDocument.Validate(); | ||
| string contactEmail = apiManifestDocument.Publisher?.ContactEmail!; | ||
|
|
||
| var openApiManifest = OpenApiPluginFactory.CreateOpenAIPluginManifest(openApiDocument.Info.Title, openApiDocument.Info.Title, logoUrl, contactEmail, legalInfoUrl, openApiDocument.Info.Version); | ||
| openApiManifest.Api = new Api("openapi", openApiPath); | ||
| openApiManifest.Auth = new ManifestNoAuth(); | ||
| openApiManifest.DescriptionForHuman = openApiDocument.Info.Description ?? $"Description for {openApiManifest.NameForHuman}."; | ||
| openApiManifest.DescriptionForModel = openApiManifest.DescriptionForHuman; | ||
|
|
||
| return openApiManifest; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tries to get an <see cref="ApiDependency"/> from the provided <see cref="ApiDependencies"/>. | ||
| /// </summary> | ||
| /// <param name="apiDependencies">The <see cref="ApiDependencies"/> to search for the apiDependency.</param> | ||
| /// <param name="apiDependencyName">The name of apiDependency to use from the provided <see cref="ApiManifestDocument.ApiDependencies"/>. The method defaults to the first apiDependency in <see cref="ApiManifestDocument.ApiDependencies"/> if no value is provided.</param> | ||
| /// <param name="apiDependency">The <see cref="ApiDependency"/> that was found.</param> | ||
| /// <returns>Returns true if the apiDependency is found and not null, otherwise false.</returns> | ||
| private static bool TryGetApiDependency(ApiDependencies apiDependencies, string? apiDependencyName, out ApiDependency? apiDependency) | ||
| { | ||
| if (string.IsNullOrEmpty(apiDependencyName)) | ||
| apiDependency = apiDependencies.FirstOrDefault().Value; | ||
| else | ||
| _ = apiDependencies.TryGetValue(apiDependencyName, out apiDependency); | ||
| return apiDependency != 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
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
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.