openai-completion-example

command module
v0.0.0-...-238d1c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 5 Imported by: 0

README ΒΆ

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:

  1. πŸš€ Sets up an OpenAI language model client.
  2. 🧠 Generates a completion for the prompt "The first man to walk on the moon".
  3. 🎨 Uses a temperature of 0.8 for some creative variety in the output.
  4. πŸ›‘ Sets a stop word "Armstrong" to prevent the model from using that specific name.
  5. πŸ“ 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! πŸŒ™πŸ‘¨β€πŸš€

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL