Files
semantic-kernel/dotnet/samples/KernelSyntaxExamples/Example10_DescribeAllSkillsAndFunctions.cs
T
Gil LaHayeandShawn Callegari 0d0b1e4b8c .Net: Update examples and notebooks to stop using text-davinci-003 (#2307)
### Motivation and Context
text-davinci-003 is being retired by Azure OpenAI and is no longer
supported for new deployments

### Description
Update examples and notebooks to use gpt-35-turbo / gpt-3.5-turbo
instead

### Contribution Checklist
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Shawn Callegari <[email protected]>
2023-08-04 20:54:35 +00:00

206 lines
6.4 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.SkillDefinition;
using Microsoft.SemanticKernel.Skills.Core;
using RepoUtils;
using Skills;
// ReSharper disable once InconsistentNaming
public static class Example10_DescribeAllSkillsAndFunctions
{
/// <summary>
/// Print a list of all the functions imported into the kernel, including function descriptions,
/// list of parameters, parameters descriptions, etc.
/// See the end of the file for a sample of what the output looks like.
/// </summary>
public static Task RunAsync()
{
Console.WriteLine("======== Describe all skills and functions ========");
var kernel = Kernel.Builder
.WithOpenAIChatCompletionService(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey)
.Build();
// Import a native skill
var skill1 = new StaticTextSkill();
kernel.ImportSkill(skill1, "StaticTextskill");
// Import another native skill
var skill2 = new TextSkill();
kernel.ImportSkill(skill2, "AnotherTextskill");
// Import a semantic skill
string folder = RepoFiles.SampleSkillsPath();
kernel.ImportSemanticSkillFromDirectory(folder, "SummarizeSkill");
// Define a semantic function inline, without naming
var sFun1 = kernel.CreateSemanticFunction("tell a joke about {{$input}}", maxTokens: 150);
// Define a semantic function inline, with skill name
var sFun2 = kernel.CreateSemanticFunction(
"write a novel about {{$input}} in {{$language}} language",
skillName: "Writing",
functionName: "Novel",
description: "Write a bedtime story",
maxTokens: 150);
FunctionsView functions = kernel.Skills.GetFunctionsView();
ConcurrentDictionary<string, List<FunctionView>> nativeFunctions = functions.NativeFunctions;
ConcurrentDictionary<string, List<FunctionView>> semanticFunctions = functions.SemanticFunctions;
Console.WriteLine("*****************************************");
Console.WriteLine("****** Native skills and functions ******");
Console.WriteLine("*****************************************");
Console.WriteLine();
foreach (KeyValuePair<string, List<FunctionView>> skill in nativeFunctions)
{
Console.WriteLine("Skill: " + skill.Key);
foreach (FunctionView func in skill.Value) { PrintFunction(func); }
}
Console.WriteLine("*****************************************");
Console.WriteLine("***** Semantic skills and functions *****");
Console.WriteLine("*****************************************");
Console.WriteLine();
foreach (KeyValuePair<string, List<FunctionView>> skill in semanticFunctions)
{
Console.WriteLine("Skill: " + skill.Key);
foreach (FunctionView func in skill.Value) { PrintFunction(func); }
}
return Task.CompletedTask;
}
private static void PrintFunction(FunctionView func)
{
Console.WriteLine($" {func.Name}: {func.Description}");
if (func.Parameters.Count > 0)
{
Console.WriteLine(" Params:");
foreach (var p in func.Parameters)
{
Console.WriteLine($" - {p.Name}: {p.Description}");
Console.WriteLine($" default: '{p.DefaultValue}'");
}
}
Console.WriteLine();
}
}
#pragma warning disable CS1587 // XML comment is not placed on a valid language element
/** Sample output:
*****************************************
****** Native skills and functions ******
*****************************************
Skill: StaticTextskill
Uppercase: Change all string chars to uppercase
Params:
- input: Text to uppercase
default: ''
AppendDay: Append the day variable
Params:
- input: Text to append to
default: ''
- day: Value of the day to append
default: ''
Skill: Textskill
Uppercase: Convert a string to uppercase.
Params:
- input: Text to uppercase
default: ''
Trim: Trim whitespace from the start and end of a string.
Params:
- input: Text to edit
default: ''
TrimStart: Trim whitespace from the start of a string.
Params:
- input: Text to edit
default: ''
TrimEnd: Trim whitespace from the end of a string.
Params:
- input: Text to edit
default: ''
Lowercase: Convert a string to lowercase.
Params:
- input: Text to lowercase
default: ''
*****************************************
***** Semantic skills and functions *****
*****************************************
Skill: _GLOBAL_FUNCTIONS_
funcce97d27e3d0b4897acf6122e41430695: Generic function, unknown purpose
Params:
- input:
default: ''
Skill: Writing
Novel: Write a bedtime story
Params:
- input:
default: ''
- language:
default: ''
Skill: SummarizeSkill
Topics: Analyze given text or document and extract key topics worth remembering
Params:
- input:
default: ''
Summarize: Summarize given text or any text document
Params:
- input: Text to summarize
default: ''
MakeAbstractReadable: Given a scientific white paper abstract, rewrite it to make it more readable
Params:
- input:
default: ''
TopicsMore: Generate list of topics for long length content
Params:
- input: Block of text to analyze
default: ''
- previousResults: List of topics found from previous blocks of text
default: ''
Notegen: Automatically generate compact notes for any text or text document.
Params:
- input:
default: ''
ActionItems: unknown function
SummarizeMore: Summarize given text or any text document
Params:
- input: Block of text to analyze
default: ''
- previousResults: Overview generated from previous blocks of text
default: ''
- conversationType: Text type, e.g. chat, email thread, document
default: ''
*/
#pragma warning restore CS1587 // XML comment is not placed on a valid language element