OpenAi_Fetcher 0.1.8

dotnet add package OpenAi_Fetcher --version 0.1.8
NuGet\Install-Package OpenAi_Fetcher -Version 0.1.8
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_Fetcher" Version="0.1.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenAi_Fetcher --version 0.1.8
#r "nuget: OpenAi_Fetcher, 0.1.8"
#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_Fetcher as a Cake Addin
#addin nuget:?package=OpenAi_Fetcher&version=0.1.8

// Install OpenAi_Fetcher as a Cake Tool
#tool nuget:?package=OpenAi_Fetcher&version=0.1.8

OpenAI Fetcher

Class library to incorporate OpenAI in your .NET application.

Changelog

0.1.8 - .NET8 + streamelined code

0.1.4 - Adjustment to readme

0.1.3 - More options

Added
  • More options: Other settings
  • Changed default model to gpt-3.5-turbo-1106

Use

Fetch data

Replace ’apiKey’ with your OpenAI API key. Replace 'instruction' and 'input' with your specific requirements.

var fetcher = new OpenAi.OpenAiApiFetcher(apiKey, "Return the 3 biggest cities of the country", "Sweden");

Change default model

Default setting is GPT-3.5-turbo. But you can select GPT-4 or GPT-4-1106-preview.

fetcher.Model = GptModels.Gpt4

Custom model

fetcher.Model = GptModels.Custom = "custom-model";

Other settings

You can also change Temprature, JsonMode* and token size.

Temp

Temp can be set between 0 and 1, where 0 will give little/none variation in the response, and 1 give more variation. Between 0.6 - 0.9 is recommended for creative tasks.

fetcher.Temp = 0.7 
JsonMode

Json mode is available with GPT-3.5-turbo-1106 and gpt-4-1106-preview (Gpt35T and Gpt4T)

fetcher.JsonMode = true
Token Size

Max size for context window. (Read OpenAi docs for limitations)

fetcher.TokenSize = 1000
Default settings
  • Model: gpt-3.5-turbo-1106
  • Temp: 0
  • JsonMode: false
  • TokenSize: 500

Results

You can get results returned as a JSON string or strongly-typed as GptResponse

Strongly-typed


GptResponse response = await fetcher.FetchCompletionsAsync(); 
var gptChoises = response.Choices[0];

Result

gptChoises.Message.Content:

1. Stockholm - The capital and largest city of Sweden, with a population of approximately 975,000 people.
2. Gothenburg - The second-largest city in Sweden, with a population of around 590,000 people.
3. Malmö - The third-largest city in Sweden, with a population of about 320,000 people.

JSON string


string result = await fetcher.FetchCompletionsJsonAsync();
Result
{
  "id": "chatcmpl-8Ig99G1IFcO0JIU77OOL7g15vgD7D",
  "object": "chat.completion",
  "created": 1699462607,
  "model": "gpt-3.5-turbo-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The three biggest cities in Sweden are:\n\n1. Stockholm - The capital and largest city of Sweden, with a population of approximately 975,000 people.\n2. Gothenburg - The second-largest city in Sweden, with a population of around 590,000 people.\n3. Malmö - The third-largest city in Sweden, with a population of about 320,000 people."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 21,
    "completion_tokens": 78,
    "total_tokens": 99
  }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • 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.1.8 97 3/8/2024
0.1.6 88 3/8/2024
0.1.5 218 11/22/2023
0.1.4 122 11/20/2023
0.1.3 105 11/17/2023
0.1.2 115 11/10/2023
0.1.1 85 11/9/2023

Fixed problem with models