OpenAI.WinRT 0.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenAI.WinRT --version 0.0.6                
NuGet\Install-Package OpenAI.WinRT -Version 0.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenAI.WinRT" Version="0.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenAI.WinRT --version 0.0.6                
#r "nuget: OpenAI.WinRT, 0.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenAI.WinRT as a Cake Addin
#addin nuget:?package=OpenAI.WinRT&version=0.0.6

// Install OpenAI.WinRT as a Cake Tool
#tool nuget:?package=OpenAI.WinRT&version=0.0.6                

OpenAI.WinRT

WinRT library for interacting with OpenAI APIs

Sample usage

GetCompletionAsync

#include <iostream>
#include <winrt/base.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>

#include <winrt/openai.h>
// Reference the CppWinRT.Builders NuGet package to get fluent-style property setters
#include <winrt/builders/OpenAI.CompletionRequest.h>


int main()
{
  winrt::init_apartment(/*winrt::apartment_type::multi_threaded*/);
  auto openai = winrt::OpenAI::OpenAIClient{};

  // configure the API key (otherwise it will use the value from the environment variable OPENAI_KEY)
  // openai.ApiKey(L"....");

  auto completionTask = openai.GetCompletionAsync(L"git clone ", L"text-davinci-003");
  auto completions = completionTask.get();  // you can co_await GetCompletionAsync instead if inside an async method
  for (auto const& c : completions) {
    std::wcout << c.Text() << L"\n";
  }
  std::wcout << L"\n\n---\n";
  auto completionTask2 = openai.GetCompletionAsync(
    winrt::OpenAI::builders::CompletionRequest{} // this uses the CppWinRT.Builders package
    .Prompt(L"git clone ")
    .Model(L"text-davinci-003")
    .NCompletions(5)
    .Temperature(0.7f)
    .MaxTokens(100)
  );
  
  auto completions2 = completionTask2.get();
  auto i = 0;
  for (auto const& c : completions2) {
    std::wcout << L"Completion #" << i << L"\n";
    std::wcout << c.Text() << L"\n";
    i++;
  }

If you'd rather not use the CppWinRT.Builders NuGet package, you can set properties individually on a CompletionRequest object:

  auto cr = winrt::OpenAI::CompletionRequest{};
  cr.Prompt(L"git clone ");
  cr.Model(L"text-davinci-003");
  cr.NCompletions(5);
  cr.Temperature(0.7f);
  cr.MaxTokens(100);
  
  auto completionTask2 = openai.GetCompletionAsync(cr);

Prompt templates

  auto promptTemplate = openai.CreateTemplate(L"Tell me a {adjective} joke about {content}");
  auto funnyJokeTask = promptTemplate.FormatAsync({ {L"adjective", L"funny"}, {L"content", L"chickens"} });
  auto funnyJoke = funnyJokeTask.get();

  std::wcout << L"\n\n" << funnyJoke << L"\n\n\n";

Few-shot example templates

  auto example = openai.CreateFewShotTemplate({ L"word", L"antonym" });

  auto examples = std::vector {
    winrt::multi_threaded_map(std::unordered_map<hstring, hstring> { {L"word", L"happy"}, { L"antonym", L"sad" }}),
    winrt::multi_threaded_map(std::unordered_map<hstring, hstring>{ {L"word", L"tall"}, { L"antonym", L"short" }}),
    };
  example.Examples(std::move(examples));


  auto fewshot = example.ExecuteAsync(L"big").get();
  std::wcout << L"the opposite of big is " << fewshot.Lookup(L"antonym").begin() << L"\n";
Product Compatible and additional computed target framework versions.
.NET net6.0-windows10.0.17763 is compatible.  net6.0-windows10.0.18362 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
native native is compatible. 
Universal Windows Platform uap was computed.  uap10.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.17 238 8/24/2023
0.0.16 167 8/18/2023
0.0.15 267 4/19/2023
0.0.14 240 4/19/2023
0.0.13 228 4/13/2023
0.0.12 235 4/4/2023
0.0.11 251 4/4/2023
0.0.10 249 3/30/2023
0.0.9 297 3/6/2023
0.0.8 311 2/17/2023
0.0.7 322 2/16/2023
0.0.6 338 2/13/2023
0.0.5 326 2/4/2023
0.0.4 285 2/4/2023
0.0.3 333 1/25/2023
0.0.2 326 1/19/2023
0.0.1 345 12/19/2022