langchain

package
v1.38.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package langchain provides an adapter that makes Zerfoo's OpenAI-compatible HTTP API compatible with LangChain-Go's LLM interface.

The adapter does not import LangChain-Go directly. Instead it exposes the same method signatures that LangChain-Go expects (Call, Generate, GeneratePrompt) so that callers can use it as a drop-in LLM without taking a dependency on the langchain-go module.

Usage:

llm := langchain.NewAdapter("http://localhost:8080", "llama3")
resp, err := llm.Call(ctx, "What is the capital of France?")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {

	// Temperature controls randomness (0–1). Default 0.7.
	Temperature float32
	// MaxTokens limits the response length. 0 means server default.
	MaxTokens int
	// StopWords is an optional list of stop sequences.
	StopWords []string
	// contains filtered or unexported fields
}

Adapter wraps Zerfoo's OpenAI-compatible HTTP API and exposes it with the method signatures expected by LangChain-Go's schema.LLM interface.

func NewAdapter

func NewAdapter(baseURL, model string, opts ...AdapterOption) *Adapter

NewAdapter creates an Adapter pointing at a running Zerfoo serve instance.

baseURL is the server root (e.g. "http://localhost:8080"). model is the model identifier forwarded in the request body.

func (*Adapter) Call

func (a *Adapter) Call(ctx context.Context, prompt string, stop ...string) (string, error)

Call sends a single prompt to the model and returns the generated text. This implements the LangChain-Go schema.LLM.Call signature.

func (*Adapter) Generate

func (a *Adapter) Generate(ctx context.Context, prompts []string, stop ...string) ([]string, error)

Generate runs the model over each prompt in prompts and returns one generation per prompt. This mirrors the LangChain-Go schema.LLM.Generate signature (adapted to work without importing langchain types).

func (*Adapter) Type

func (a *Adapter) Type() string

Type returns a string identifier for this LLM type, satisfying the LangChain-Go schema.LLM interface.

type AdapterOption

type AdapterOption func(*Adapter)

AdapterOption configures an Adapter.

func WithHTTPClient

func WithHTTPClient(c *http.Client) AdapterOption

WithHTTPClient replaces the default HTTP client.

func WithMaxTokens

func WithMaxTokens(n int) AdapterOption

WithMaxTokens sets the maximum number of tokens to generate.

func WithStopWords

func WithStopWords(words ...string) AdapterOption

WithStopWords sets stop sequences that halt generation.

func WithTemperature

func WithTemperature(t float32) AdapterOption

WithTemperature sets the sampling temperature.

Jump to

Keyboard shortcuts

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