Files
langchaingo/examples/llm-chain-example
Dmitry Ng 064f09155c chore(deps): bump Go toolchain to 1.26.5 and fix vulnerable dependencies
- Raised the `go` directive from 1.24.1 to 1.26.5 to satisfy pgx/v5 and ollama's minimum Go version requirements and to pick up 15 patched standard library CVEs.
- Updated `pgx/v5`, `otel`/`otel/sdk`/`otlptracehttp`, `x/net`, and the AWS `eventstream` protocol package to their latest requested versions.
- Remediated govulncheck-flagged CVEs in `grpc`, `x/text`, `x/crypto`, `antchfx/xpath`, AWS SDK `bedrock*`/`s3` services, `etcd/server`, and `mongo-driver` v1/v2.
- Fixed ollama's `MainGPU` API type change (`int` -> `*int`) in `llms/ollama/options.go` without breaking the public `WithRunnerMainGPU` signature.
2026-08-04 13:57:26 +03:00
..
2024-06-20 23:47:52 -04:00

LLM Chain Example

Welcome to this cheerful example of using LLM (Language Model) chains with LangChain in Go! 🎉

This example demonstrates how to create and use LLM chains for various natural language processing tasks. Let's dive in and see what exciting things we can do!

What Does This Example Do?

  1. Company Name Generation 🏢

    • We create an LLM chain that generates a company name based on a product.
    • It uses a simple prompt template: "What is a good name for a company that makes {{.product}}?"
    • We run this chain with "socks" as input and get a creative company name suggestion!
  2. Text Translation 🌍

    • We set up another LLM chain for translating text between languages.
    • The prompt template asks to translate from one language to another.
    • We demonstrate translating "I love programming" from English to French.

How It Works

  1. We start by setting up an OpenAI LLM (Language Model).
  2. For each task, we create a PromptTemplate with placeholders for inputs.
  3. We then create LLMChain instances combining the LLM and the prompt templates.
  4. For single-input chains, we use the Run function.
  5. For multi-input chains, we use the Call function with a map of inputs.

Running the Example

When you run this example, you'll see:

  1. A suggested company name for a sock manufacturer.
  2. The French translation of "I love programming".

It's a fun and practical demonstration of how LLM chains can be used for creative and linguistic tasks!

Happy coding, and enjoy exploring the world of LLM chains with Go! 🚀👨‍💻👩‍💻