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 ¶
Call sends a single prompt to the model and returns the generated text. This implements the LangChain-Go schema.LLM.Call signature.
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.