Class library to incorporate OpenAI in your .NET application.
- More options: [Other settings]
- Changed default model to gpt-3.5-turbo-1106
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");
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";
You can also change Temprature, JsonMode* and token size.
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
Json mode is available with GPT-3.5-turbo-1106 and gpt-4-1106-preview (Gpt35T and Gpt4T)
fetcher.JsonMode = true
Max size for context window. (Read OpenAi docs for limitations)
fetcher.TokenSize = 1000
- Model: gpt-3.5-turbo-1106
- Temp: 0
- JsonMode: false
- TokenSize: 500
You can get results returned as a JSON string or strongly-typed as GptResponse
GptResponse response = await fetcher.FetchCompletionsAsync();
var gptChoises = response.Choices[0];
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.
string result = await fetcher.FetchCompletionsJsonAsync();
{
"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
}
}