OpenAI Completion Example
Welcome to this cheerful example of using the LangChain Go library with OpenAI's completion API! π
What This Example Does
This fun little program demonstrates how to use the LangChain Go library to generate text completions using OpenAI's powerful language model. Here's what it does:
- π Sets up an OpenAI language model client.
- π§ Generates a completion for the prompt "The first man to walk on the moon".
- π¨ Uses a temperature of 0.8 for some creative variety in the output.
- π Sets a stop word "Armstrong" to prevent the model from using that specific name.
- π Prints the generated completion to the console.
How It Works
The program uses the langchaingo
library to interact with OpenAI's API. It creates a new OpenAI client, sets up a context, and then generates a completion based on the given prompt.
The GenerateFromSinglePrompt
function is used with some interesting options:
WithTemperature(0.8)
: This adds a bit of randomness to the output.
WithStopWords([]string{"Armstrong"})
: This prevents the model from using "Armstrong" in its response.
Running the Example
To run this example, make sure you have your OpenAI API key set up in your environment variables. Then, simply execute the program and watch as it generates a creative response about the first moon landing!
Have fun exploring the possibilities with LangChain and OpenAI! ππ¨βπ