OpenAI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
using LangChain.Providers;
using LangChain.Providers.OpenAI.Predefined;

var apiKey =
    Environment.GetEnvironmentVariable("OPENAI_API_KEY") ??
    throw new InvalidOperationException("OPENAI_API_KEY environment variable is not found.");
var model = new OpenAiLatestFastChatModel(apiKey);

var result = await model.GenerateAsync("What is a good name for a company that sells colourful socks?");

Console.WriteLine(result);