Skip to content
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

Jira plugin open api #648

Merged
merged 31 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
26b69b0
initial setup
amsacha Apr 19, 2023
0eb897c
remove functions that cant be called because of incomplete jira open …
amsacha Apr 24, 2023
e60bbf6
Update RestApiOperationRunner to not wrap json objects into jsons
amsacha Apr 25, 2023
2c22352
restore program.cs; update the simplified jira schema; rename and mov…
amsacha Apr 25, 2023
ee8e743
make variables generic
amsacha Apr 25, 2023
a47194f
minor name change typo
amsacha Apr 25, 2023
456b139
Merge branch 'main' into JiraPluginOpenAPI
adrianwyatt Apr 25, 2023
a1d33c2
Revert "Update RestApiOperationRunner to not wrap json objects into j…
amsacha Apr 25, 2023
2fd5a42
pr comments addressed
amsacha Apr 25, 2023
745871b
inline functions and remove full open api schema
amsacha Apr 25, 2023
f498e87
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 25, 2023
8e28bae
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 26, 2023
cf43bb3
minor naming and comment change
amsacha Apr 26, 2023
51c1fd9
Update samples/dotnet/kernel-syntax-examples/Example22_b_OpenApiSkill…
amsacha Apr 26, 2023
8aa85df
change example name
amsacha Apr 26, 2023
abc9ced
Update Example22_OpenApiSkill_Jira.cs
amsacha Apr 26, 2023
ab24599
Merge branch 'main' into JiraPluginOpenAPI
adrianwyatt Apr 27, 2023
5342bb6
add readme
amsacha Apr 27, 2023
68c7972
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 27, 2023
f490d3c
update namespaces being used
amsacha Apr 27, 2023
f68d42c
ran dotnet format
amsacha Apr 27, 2023
f955938
readme and comment fixes
amsacha Apr 27, 2023
8f6df5f
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 27, 2023
0239e6f
rename files
amsacha Apr 27, 2023
d84a707
rename all examples after 21
amsacha Apr 27, 2023
d990385
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 28, 2023
455c65d
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 28, 2023
d9497ad
Merge branch 'main' into JiraPluginOpenAPI
amsacha Apr 28, 2023
3e68708
Merge branch 'main' into JiraPluginOpenAPI
amsacha May 1, 2023
dcfce1d
Merge branch 'main' into JiraPluginOpenAPI
dluc May 1, 2023
00f384e
Merge branch 'main' into JiraPluginOpenAPI
amsacha May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using RepoUtils;

// ReSharper disable once InconsistentNaming
public static class Example22_OpenApiSkill
public static class Example22_OpenApiSkill_AzureKeyVault
{
public static async Task RunAsync()
{
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// of <see cref="IMemoryStore"/> has a single collection, and thus does not need to be named.
/// It also assumes that the JSON formatted data can be deserialized into <see cref="MemoryRecord"/> objects.
/// </summary>
public static class Example23_ReadOnlyMemoryStore
public static class Example24_ReadOnlyMemoryStore
{
public static async Task RunAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// If you use Semantic Kernel with other models, the tokenization logic is most probably different,
/// and you should not use the GPT tokenizer.
/// </summary>
public static class Example24_Tokenizer
public static class Example25_Tokenizer
{
public static void Run()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

// ReSharper disable once InconsistentNaming
public static class Example25_AADAuth
public static class Example26_AADAuth
{
public static async Task RunAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

// ReSharper disable once InconsistentNaming
public static class Example26_SemanticFunctionsUsingChatGPT
public static class Example27_SemanticFunctionsUsingChatGPT
{
public static async Task RunAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using RepoUtils;

// ReSharper disable once InconsistentNaming
public static class Example27_ActionPlanner
public static class Example28_ActionPlanner
{
public static async Task RunAsync()
{
Expand Down
15 changes: 9 additions & 6 deletions samples/dotnet/kernel-syntax-examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,25 @@ public static async Task Main()
await Example21_ChatGptPlugins.RunAsync();
Console.WriteLine("== DONE ==");

await Example22_OpenApiSkill.RunAsync();
await Example22_OpenApiSkill_AzureKeyVault.RunAsync();
Console.WriteLine("== DONE ==");

await Example23_ReadOnlyMemoryStore.RunAsync();
await Example23_OpenApiSkill_Jira.RunAsync();
Console.WriteLine("== DONE ==");

Example24_Tokenizer.Run();
await Example24_ReadOnlyMemoryStore.RunAsync();
Console.WriteLine("== DONE ==");

await Example25_AADAuth.RunAsync();
Example25_Tokenizer.Run();
Console.WriteLine("== DONE ==");

await Example26_SemanticFunctionsUsingChatGPT.RunAsync();
await Example26_AADAuth.RunAsync();
Console.WriteLine("== DONE ==");

await Example27_ActionPlanner.RunAsync();
await Example27_SemanticFunctionsUsingChatGPT.RunAsync();
Console.WriteLine("== DONE ==");

await Example28_ActionPlanner.RunAsync();
Console.WriteLine("== DONE ==");

await Example28_ChatWithPrompts.RunAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Jira Open API Schema
amsacha marked this conversation as resolved.
Show resolved Hide resolved

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
amsacha marked this conversation as resolved.
Show resolved Hide resolved
and so we can't build the body automatically.