#1

Hidden Content
You must register or login to view this content.



UsageTo use the library, first create an instance of the 
Code:
Client
 class and provide your API key:var apiKey = "your-api-key";
var endpoint = "https://api.openai.com/v1/";
var client = new Client(apiKey, endpoint);You can now use the Client instance to call the various methods available in the library. For example, to generate text, you would call the GenerateText method:
var model = "text-davinci-002";
var prompt = "The future is bright.";
var length = 100;
var nopunct = false;
var stop = false;
var temperature = 0.5;
var result = client.GenerateText(model, prompt, length, nopunct, stop, temperature);The library also provides methods for summarizing text, completing code, analyzing sentiment, recognizing named entities, classifying text, translating text, and recognizing emotions in text or speech.
For more information on how to use each method, see the API reference section below.
API ReferenceGenerateTextGenerates text using the OpenAI API.
public string GenerateText(string model, string prompt, int length, bool nopunct, bool stop, int temperature)Parameters 
Code:
model
: The name of the OpenAI model to use for text generation. 
Code:
prompt
: The text prompt to use as input to the model. 
Code:
length
: The maximum length of the generated text, in characters. 
Code:
nopunct
: A flag indicating whether to include punctuation in the generated text. 
Code:
stop
: A flag indicating whether to stop generating text when the API returns an end-of-text token. 
Code:
temperature
: The temperature to use for text generation.Returns The generated text.
SummarizeTextSummarizes text using the OpenAI API.
public string SummarizeText(string text, int length)Parameters 
Code:
text
: The text to summarize. 
Code:
length
: The desired length of the summarized text, in characters.Returns The summarized text.
#CompleteCode Completes code using the OpenAI API.
public string CompleteCode(string model, string prompt, int maxTokens, int n)Parameters 
Code:
model
: The name of the OpenAI model to use for code completion. 
Code:
prompt
: The code prompt to use as input to the model. 
Code:
maxTokens
: The maximum number of tokens to generate in the completed code. 
Code:
n
: The number of completions to generate for the prompt.Returns The completed code.
#AnalyzeSentiment Analyzes the sentiment of text using the OpenAI API.
public string AnalyzeSentiment(string text)Parameters 
Code:
text
: The text to analyze.Returns The sentiment of the text, as a string value representing positive, negative, or neutral sentiment.
#RecognizeEntities Recognizes named entities in text using the OpenAI API.
public string RecognizeEntities(string text)Parameters 
Code:
text
: The text to recognize entities in.Returns A list of recognized entities and their types.
#ClassifyText Classifies text into categories using the OpenAI API.
public string ClassifyText(string text)Parameters 
Code:
text
: The text to classify.Returns A list of categories that the text belongs to.
#TranslateText Translates text from one language to another using the OpenAI API.
public string TranslateText(string text, string from, string to)Parameters 
Code:
text
: The text to translate. 
Code:
from
: The source language of the text. 
Code:
to
: The target language to translate the text into.Returns The translated text.
#RecognizeEmotion Recognizes emotions in text or speech (Coming Soon) using the OpenAI API.
public string RecognizeEmotion(string text)Parameters 
Code:
text
: The text or speech to recognize emotions in.Returns A list of emotions detected in the text or speech, along with the confidence level for each emotion.