![]() |
VOOZH | about |
dotnet add package fAI --version 1.0.213
NuGet\Install-Package fAI -Version 1.0.213
<PackageReference Include="fAI" Version="1.0.213" />
<PackageVersion Include="fAI" Version="1.0.213" />Directory.Packages.props
<PackageReference Include="fAI" />Project file
paket add fAI --version 1.0.213
#r "nuget: fAI, 1.0.213"
#:package fAI@1.0.213
#addin nuget:?package=fAI&version=1.0.213Install as a Cake Addin
#tool nuget:?package=fAI&version=1.0.213Install as a Cake Tool
Library fAI available on NuGet.
Querying and expecting answer in JSON format.
[Fact()]
public void Completion_JsonMode_WorldCup()
{
var client = new OpenAI();
var p = new Prompt_GPT_35_Turbo_JsonAnswer
{
Messages = new List<GPTMessage>()
{
new GPTMessage { Role = MessageRole.system, Content = "You are a helpful assistant designed to output JSON." },
new GPTMessage { Role = MessageRole.user, Content = "Who won the soccer world cup in 1998?" }
}
};
var response = client.Completions.Create(p);
Assert.True(response.Success);
var answer = response.JsonObject["winner"];
Assert.Equal("France", answer);
}
Conversation and data analysis with GPT 4
[Fact()]
public void Completion_Chat_QuestionAboutPastSchedule()
{
var client = new OpenAI();
var prompt = new Prompt_GPT_4
{
Messages = new List<GPTMessage>
{
new GPTMessage { Role = MessageRole.system, Content = "You are a helpful assistant." },
new GPTMessage { Role = MessageRole.user, Content = $"08/02/2021 15:00 Meeting with Eric." },
new GPTMessage { Role = MessageRole.user, Content = $"09/01/2021 15:00 Meeting with Eric." },
new GPTMessage { Role = MessageRole.user, Content = $"09/10/2021 10:00 Take the dog to the vet." },
new GPTMessage { Role = MessageRole.user, Content = $"09/20/2021 15:00 Meeting with Rick and John" },
}
};
var response = client.Completions.Create(prompt);
prompt.Messages.Add(new GPTMessage { Role = MessageRole.user, Content = "When was the last time I talked with Eric?" });
response = client.Completions.Create(prompt);
Assert.Matches(@"Eric.*09\/01\/2021 at 15:00", response.Text);
prompt.Messages.Add(new GPTMessage { Role = MessageRole.user, Content = "What do I have to do on 09/10/2021?" });
response = client.Completions.Create(prompt);
Assert.Matches(@"dog.*vet.*10:00", response.Text);
}
Translation with model gpt-3.5-turbo
public string Translate(string text, TranslationLanguages sourceLangague, TranslationLanguages targetLanguage);
const string ReferenceEnglishSentence = "Hello world.";
[Fact()]
public void Translate_EnglishToSpanish()
{
var client = new OpenAI();
var translation = client.Completions.Translate(ReferenceEnglishSentence, TranslationLanguages.English, TranslationLanguages.Spanish);
Assert.Equal("'Hola mundo.'", translation);
}
Others helper to execute translations. Translating dictionary or list of strings can do 2 things
key is not translated as part of the answer and can be use to map the translation
with the original texts.public Dictionary<string, string> Translate(Dictionary<string, string> inputDictionary, TranslationLanguages sourceLangague, TranslationLanguages targetLanguage);
public List<string> Translate(List<string> strings, TranslationLanguages sourceLangague, TranslationLanguages targetLanguage);
public class OpenAIEmbeddingsTests
{
[Fact()]
public void Embeddings_Create()
{
var input = "I am he as you are he as you are me. And we are all together. See how they run like pigs from a gun. See how they fly. I'm crying.";
var client = new OpenAI();
var r = client.Embeddings.Create(input);
// r.Data[0].Embedding contains the list of float
Assert.Equal("embedding", r.Data[0].Object);
Assert.Equal(r.Data[0].EmbeddingMaxValue, r.Data[0].Embedding.Count);
Assert.Equal(37, r.Usage.PromptTokens);
Assert.Equal(37, r.Usage.TotalTokens);
}
}
[Fact()]
public void Image_Generate()
{
var prompt = @"Generate an image inspired by Victor Hugo's classic novel, 'Les Misérables'.
The image should depict three characters, each with distinct characteristics.
The first is an older, physically strong man with a scarred face, wearing threadbare clothes, indicative of a hard life — this represents Jean Valjean.
The second is a young woman radiating innocence and kindness; she wears modest clothes and has beautiful shining eyes — this is Cosette.
The third is a stern-looking middle-aged man in a gentleman's attire and hat, representing law and order — representative of Javert.
Their expressions should reflect the nuances of the complex relationships
they share in the story.
";
var client = new OpenAI();
var r = client.Image.Generate(prompt, size : OpenAIImageSize._1792x1024);
var pngFileNames = r.DownloadImage();
Assert.True(pngFileNames.Count == 1);
Assert.True(File.Exists(pngFileNames[0]));
}
<img src=".\Image_Generate.example.png" alt="Image_Generate.example.png" width="448"/>
API keys can be hard coded in code or read automatically from environment variable.
| Environment Variable Names |
|---|
| MICROSOFT_AZURE_SEARCH_KEY |
| MICROSOFT_COGNITIVE_SERVICES_KEY |
| MICROSOFT_COGNITIVE_SERVICES_REGION |
| OPENAI_API_KEY |
| OPENAI_ORGANIZATION_ID |
| OPENAI_LOG_FILE |
| DEEPGRAM_API_KEY |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.213 | 70 | 6/16/2026 |
| 1.0.212 | 74 | 6/14/2026 |
| 1.0.210 | 101 | 6/10/2026 |
| 1.0.209 | 93 | 6/9/2026 |
| 1.0.208 | 103 | 6/9/2026 |
| 1.0.206 | 92 | 6/7/2026 |
| 1.0.205 | 91 | 6/7/2026 |
| 1.0.204 | 102 | 6/7/2026 |
| 1.0.203 | 93 | 6/7/2026 |
| 1.0.202 | 100 | 6/6/2026 |
| 1.0.201 | 97 | 6/6/2026 |
| 1.0.200 | 101 | 6/4/2026 |
| 1.0.199 | 105 | 6/1/2026 |
| 1.0.198 | 99 | 5/31/2026 |
| 1.0.197 | 95 | 5/31/2026 |
| 1.0.196 | 106 | 5/31/2026 |
| 1.0.195 | 103 | 5/31/2026 |
| 1.0.194 | 104 | 5/30/2026 |
| 1.0.193 | 98 | 5/30/2026 |
| 1.0.192 | 102 | 5/30/2026 |
Creation