-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this PR * Added a sample app to allow testing of nuget packages * Added a CodeOwners file * Refactored IVocabCollection and IVocab into their own files * Updated readmes for examples
- Loading branch information
Showing
14 changed files
with
196 additions
and
44 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,2 @@ | ||
# @microsoft/TypeChat.Net-PR owns any files in this repo | ||
@microsoft/TypeChat.Net-PR |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.TypeChat.Schema; | ||
|
||
/// <summary> | ||
/// A Vocabulary is a string table whose values need not be hardcoded in code | ||
/// Example: lists of product names | ||
/// This means that each time a schema is generated, it can be different. | ||
/// | ||
/// These string tables can be emitted in Typescript schema, e.g. like this: | ||
/// type FourSeasons: 'Winter' | 'Spring' | 'Summer' | 'Fall' | ||
/// | ||
/// The string tables can also be automatically validated to ensure the model sends back know strings. | ||
/// Any error can be sent to the model for correction | ||
/// | ||
/// </summary> | ||
public interface IVocab : IEnumerable<VocabEntry> | ||
{ | ||
bool Contains(VocabEntry entry); | ||
bool Contains(VocabEntry entry, StringComparison comparison); | ||
} |
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,13 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.TypeChat.Schema; | ||
|
||
/// <summary> | ||
/// A collection of named vocabularies. | ||
/// Vocabulary collections can be dynamic and load vocabularies at runtime from data bases, files and so on | ||
/// </summary> | ||
public interface IVocabCollection : IEnumerable<NamedVocab> | ||
{ | ||
NamedVocab? Get(string name); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.TypeChat" Version="0.1.230922.3-preview" /> | ||
<PackageReference Include="Microsoft.TypeChat.Dialog" Version="0.1.230922.3-preview" /> | ||
<PackageReference Include="Microsoft.TypeChat.Program" Version="0.1.230922.3-preview" /> | ||
<PackageReference Include="Microsoft.TypeChat.SemanticKernel" Version="0.1.230922.3-preview" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.34031.279 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emoji", "Emoji.csproj", "{E05F478D-9736-4252-BEE1-8060E027C5A6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E05F478D-9736-4252-BEE1-8060E027C5A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E05F478D-9736-4252-BEE1-8060E027C5A6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E05F478D-9736-4252-BEE1-8060E027C5A6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E05F478D-9736-4252-BEE1-8060E027C5A6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {1709003B-ED8F-466F-9B59-E7D4FE42247A} | ||
EndGlobalSection | ||
EndGlobal |
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,95 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
//------------------------------------------------------ | ||
// | ||
// A simple app that translates user requests into emojis | ||
// using all 3 options in TypeChat. | ||
// This application is used to test Package installs | ||
// | ||
//------------------------------------------------------ | ||
|
||
using Microsoft.TypeChat; | ||
using Microsoft.TypeChat.Dialog; | ||
|
||
namespace Emoji; | ||
|
||
public class EmojiResponse | ||
{ | ||
public string EmojiTranslation { get; set; } = string.Empty; | ||
} | ||
|
||
public interface IEmojiService | ||
{ | ||
Task<string> ToEmoji(string userText); | ||
} | ||
|
||
internal class EmojiProgram : IEmojiService | ||
{ | ||
LanguageModel _model; | ||
JsonTranslator<EmojiResponse> _translator; | ||
public EmojiProgram() | ||
{ | ||
_model = new LanguageModel(OpenAIConfig.FromEnvironment()); | ||
_translator = new JsonTranslator<EmojiResponse>(_model); | ||
} | ||
|
||
public async Task<string> ToEmoji(string line) | ||
{ | ||
EmojiResponse response = await _translator.TranslateAsync(line); | ||
return response.EmojiTranslation; | ||
} | ||
|
||
public async Task TestTranslate() | ||
{ | ||
string? line; | ||
Console.Write(">"); | ||
|
||
while ((line = Console.ReadLine()) != null) | ||
{ | ||
string result = await ToEmoji(line); | ||
Console.WriteLine(result); | ||
Console.Write(">"); | ||
} | ||
} | ||
|
||
public async Task TestProgram() | ||
{ | ||
string? line; | ||
Console.Write(">"); | ||
Console.OutputEncoding = System.Text.Encoding.UTF8; | ||
|
||
var api = new Api<IEmojiService>(this); | ||
ProgramTranslator programGen = new ProgramTranslator<IEmojiService>(_model, api); | ||
while ((line = Console.ReadLine()) != null) | ||
{ | ||
using Program program = await programGen.TranslateAsync(line); | ||
string result = await program.RunAsync(api); | ||
Console.WriteLine(result); | ||
Console.Write(">"); | ||
} | ||
} | ||
|
||
public async Task TestAgent() | ||
{ | ||
Agent<EmojiResponse> agent = new AgentWithHistory<EmojiResponse>(_model); | ||
agent.Instructions.Append("Respond to me in emojis"); | ||
string? line; | ||
Console.Write(">"); | ||
while ((line = Console.ReadLine()) != null) | ||
{ | ||
var response = await agent.GetResponseAsync(line); | ||
Console.WriteLine(response.EmojiTranslation); | ||
Console.Write(">"); | ||
} | ||
} | ||
|
||
public static async Task<int> Main(string[] args) | ||
{ | ||
Console.OutputEncoding = System.Text.Encoding.UTF8; | ||
EmojiProgram p = new EmojiProgram(); | ||
await p.TestTranslate(); | ||
//await p.TestProgram(); | ||
//await p.TestAgent(); | ||
return 0; | ||
} | ||
} |
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,4 @@ | ||
dotnet add package Microsoft.TypeChat --prerelease | ||
dotnet add package Microsoft.TypeChat.SemanticKernel --prerelease | ||
dotnet add package Microsoft.TypeChat.Program --prerelease | ||
dotnet add package Microsoft.TypeChat.Dialog --prerelease |