-
Notifications
You must be signed in to change notification settings - Fork 27
/
Program.cs
42 lines (35 loc) · 1.22 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.TypeChat;
namespace Sentiment;
public class SentimentApp : ConsoleApp
{
JsonTranslator<SentimentResponse> _translator;
public SentimentApp()
{
OpenAIConfig config = Config.LoadOpenAI();
// Although this sample uses config files, you can also load config from environment variables
// OpenAIConfig config = OpenAIConfig.LoadFromJsonFile("your path");
// OpenAIConfig config = OpenAIConfig.FromEnvironment();
_translator = new JsonTranslator<SentimentResponse>(new LanguageModel(config));
}
public override async Task ProcessInputAsync(string input, CancellationToken cancelToken)
{
SentimentResponse response = await _translator.TranslateAsync(input, cancelToken);
Console.WriteLine($"The sentiment is {response.Sentiment}");
}
public static async Task<int> Main(string[] args)
{
try
{
SentimentApp app = new SentimentApp();
await app.RunAsync("😀> ", args.GetOrNull(0));
}
catch (Exception ex)
{
WriteError(ex);
Console.ReadLine();
return -1;
}
return 0;
}
}