forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jira plugin open api (microsoft#648)
### Motivation and Context Provide an example implementation of connecting the Semantic Kernel to external plugins following the open api schema. ### Description Jira Open API schema usage example Renaming the azure key vault example, so all open api skill examples are grouped together Prevent RestApiOperationRunner.cs from wrapping a json response into a json object.
- Loading branch information
1 parent
2470615
commit 9546b8c
Showing
10 changed files
with
1,419 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
76 changes: 76 additions & 0 deletions
76
samples/dotnet/kernel-syntax-examples/Example23_OpenApiSkill_Jira.cs
This file contains 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,76 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Orchestration; | ||
using Microsoft.SemanticKernel.SkillDefinition; | ||
using Microsoft.SemanticKernel.Skills.OpenAPI.Authentication; | ||
using Newtonsoft.Json; | ||
using RepoUtils; | ||
|
||
/// <summary> | ||
/// This sample shows how to connect the Semantic Kernel to Jira as an Open Api plugin based on the Open Api schema. | ||
/// This format of registering the skill and its operations, and subsequently executing those operations can be applied | ||
/// to an Open Api plugin that follows the Open Api Schema. | ||
/// </summary> | ||
public static class Example23_OpenApiSkill_Jira | ||
{ | ||
public static async Task RunAsync() | ||
{ | ||
var kernel = new KernelBuilder().WithLogger(ConsoleLogger.Log).Build(); | ||
var contextVariables = new ContextVariables(); | ||
|
||
// Change <your-domain> to a jira instance you have access to with your authentication credentials | ||
string serverUrl = "https://<your-domain>.atlassian.net/rest/api/latest/"; | ||
contextVariables.Set("server-url", serverUrl); | ||
|
||
IDictionary<string, ISKFunction> jiraSkills; | ||
var tokenProvider = new BasicAuthenticationProvider(() => | ||
{ | ||
string s = Env.Var("MY_EMAIL_ADDRESS") + ":" + Env.Var("JIRA_API_KEY"); | ||
return Task.FromResult(s); | ||
}); | ||
|
||
// The bool useLocalFile can be used to toggle the ingestion method for the openapi schema between a file path and a URL | ||
bool useLocalFile = true; | ||
if (useLocalFile) | ||
{ | ||
var apiSkillFile = "./../../../Skills/JiraSkill/openapi.json"; | ||
jiraSkills = await kernel.ImportOpenApiSkillFromFileAsync("jiraSkills", apiSkillFile, tokenProvider.AuthenticateRequestAsync); | ||
} | ||
else | ||
{ | ||
var apiSkillRawFileURL = new Uri("https://raw.githubusercontent.com/microsoft/PowerPlatformConnectors/dev/certified-connectors/JIRA/apiDefinition.swagger.json"); | ||
jiraSkills = await kernel.ImportOpenApiSkillFromUrlAsync("jiraSkills", apiSkillRawFileURL, null, tokenProvider.AuthenticateRequestAsync); | ||
} | ||
|
||
// GetIssue Skill | ||
{ | ||
// Set Properties for the Get Issue operation in the openAPI.swagger.json | ||
contextVariables.Set("issueKey", "SKTES-2"); | ||
|
||
// Run operation via the semantic kernel | ||
var result = await kernel.RunAsync(contextVariables, jiraSkills["GetIssue"]); | ||
|
||
Console.WriteLine("\n\n\n"); | ||
var formattedContent = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(result.Result), Formatting.Indented); | ||
Console.WriteLine("GetIssue jiraSkills response: \n{0}", formattedContent); | ||
} | ||
|
||
// AddComment Skill | ||
{ | ||
// Set Properties for the AddComment operation in the openAPI.swagger.json | ||
contextVariables.Set("issueKey", "SKTES-1"); | ||
contextVariables.Set("body", "Here is a rad comment"); | ||
|
||
// Run operation via the semantic kernel | ||
var result = await kernel.RunAsync(contextVariables, jiraSkills["AddComment"]); | ||
|
||
Console.WriteLine("\n\n\n"); | ||
var formattedContent = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(result.Result), Formatting.Indented); | ||
Console.WriteLine("AddComment jiraSkills response: \n{0}", formattedContent); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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 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
6 changes: 6 additions & 0 deletions
6
samples/dotnet/kernel-syntax-examples/Skills/JiraSkill/README.md
This file contains 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,6 @@ | ||
# Jira Open API Schema | ||
|
||
We have our own curated version of the Jira Open API schema because the one available online | ||
at https://raw.githubusercontent.com/microsoft/PowerPlatformConnectors/dev/certified-connectors/JIRA/apiDefinition.swagger.json, | ||
doesn't follow OpenAPI specification for all of its operations. For example CreateIssueV2, its body param does not describe properties | ||
and so we can't build the body automatically. |
Oops, something went wrong.