mirror of
https://github.com/vxcontrol/langchaingo.git
synced 2026-08-24 21:31:28 -04:00
064f09155c
- 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.
Prompt Template Example
This example demonstrates the core features of LangChain Go's prompt template system.
Features Demonstrated
- Basic Templates - Simple variable substitution using Go templates
- Template Formats - Using different template syntaxes (Go, Jinja2, F-string)
- Partial Variables - Pre-filling some template variables
- Chat Templates - Creating structured chat prompts
- Optional Sanitization - HTML escaping for untrusted data
Running the Example
go run main.go
Key Concepts
Template Formats
LangChain Go supports three template formats:
- Go Templates (default):
{{ .variable }} - Jinja2:
{{ variable }} - F-strings:
{variable}
Security
By default, templates render without sanitization for maximum compatibility. When working with untrusted user input, enable sanitization:
result, err := prompts.RenderTemplate(
template,
prompts.TemplateFormatGoTemplate,
data,
prompts.WithSanitization(), // Enables HTML escaping
)
Partial Variables
Partial variables let you pre-fill template values:
template := prompts.PromptTemplate{
Template: "{{.greeting}}, {{.name}}!",
InputVariables: []string{"name"},
PartialVariables: map[string]any{
"greeting": "Hello",
},
}