llm

package
v0.11.16 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package llm is a small, shared client for large language model providers.

It exists so the ProjectDiscovery ecosystem has one LLM client rather than several: nuclei semantic matchers and the DSL llm_prompt helper both build on it. Any OpenAI-compatible endpoint is supported, which covers local runtimes (ollama, llama.cpp, vLLM, LM Studio) as well as hosted providers. There is no implicit hosted default: a caller must set Provider or BaseURL so a scan cannot send data off-box by accident.

Index

Constants

View Source
const APIKeyEnv = "LLM_API_KEY"

APIKeyEnv is the environment variable consulted when Config.APIKey is empty.

View Source
const ProviderJev = "jev"

ProviderJev is TypeSafe's Jev, a classifier rather than a chat model: it answers Judge with calibrated probabilities and cannot Complete.

View Source
const ProviderOpenAICompatible = "openai-compatible"

ProviderOpenAICompatible talks to any /v1/chat/completions endpoint. BaseURL is required; this name never maps to a hosted vendor.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a provider-agnostic LLM client with caching, a call budget, and a concurrency limit. It is safe for concurrent use.

func New

func New(config Config) (*Client, error)

New builds a client from config. Hosted presets require Config.APIKey or LLM_API_KEY; local presets and a custom BaseURL do not.

func (*Client) CanJudge added in v0.11.13

func (client *Client) CanJudge() bool

CanJudge reports whether the provider answers Judge.

func (*Client) Complete

func (client *Client) Complete(ctx context.Context, req Request) (string, error)

Complete returns a completion for the request.

func (*Client) Judge added in v0.11.13

func (client *Client) Judge(ctx context.Context, req JudgeRequest) (Verdict, error)

Judge asks the provider which label fits the inputs. It shares the cache, budget and concurrency limit with Complete.

type Config

type Config struct {
	// Provider selects a preset endpoint. Ignored when BaseURL is set.
	Provider string
	// APIKey overrides LLM_API_KEY. Empty means read the environment. Hosted
	// presets require a key; local presets and a custom BaseURL do not.
	APIKey string
	// BaseURL is any OpenAI-compatible endpoint, including a local one.
	BaseURL string
	// Model is the model identifier passed to the provider.
	Model string
	// Timeout bounds a single completion call. Zero uses a default.
	Timeout time.Duration
	// Cache enables in-memory response caching keyed on the request.
	Cache bool
	// MaxCalls caps completions for the lifetime of the client. Zero is
	// unlimited. It exists so a misbehaving caller cannot run up an unbounded
	// bill against a paid provider.
	MaxCalls int
	// MaxConcurrency caps in-flight completions. Zero or negative means one.
	MaxConcurrency int
}

Config describes how to reach a provider and how to bound its use.

type Format

type Format struct {
	// JSON asks the provider to return a single JSON value. Callers that need a
	// specific shape state it in the prompt and validate the result; this only
	// requests JSON rather than prose.
	JSON bool
}

Format controls the shape of a completion.

type JudgeRequest added in v0.11.13

type JudgeRequest struct {
	// Question is the instruction. It never carries the inputs, which is what
	// keeps text inside them from being read as instructions.
	Question string
	// Labels are the allowed answers. Empty means a yes or no question.
	Labels []string
	// Inputs are the data being judged, such as one or more responses.
	Inputs []string
}

JudgeRequest asks which label fits the inputs.

type Request

type Request struct {
	// System is an optional system instruction.
	System string
	// Prompt is the user input.
	Prompt string
	// Format optionally constrains the output.
	Format Format
}

Request is a single completion.

type Verdict added in v0.11.13

type Verdict struct {
	Label      string  `json:"label"`
	Confidence float64 `json:"confidence"`
	// Model is the exact model version that answered, when the provider
	// reports one, so a verdict can be traced after an alias moves.
	Model string `json:"model,omitempty"`
}

Verdict is the label a judge chose and its probability.

Jump to

Keyboard shortcuts

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