Package org.mockserver.llm.analysis
Class LlmOptimisationReportBuilder
java.lang.Object
org.mockserver.llm.analysis.LlmOptimisationReportBuilder
Builds a deterministic
LlmOptimisationReport from captured LLM
FORWARDED_REQUEST exchanges.
Pure and read-only: each exchange's request body is decoded with the
provider's ProviderCodec, the provider is detected with
LlmProviderSniffer, token usage is read from the response (via
LlmClient.parseCompletionResponse(org.mockserver.model.HttpResponse)) or estimated from decoded text when
the provider returned no usage, and cost is estimated with LlmPricing.
No network and no LLM calls. The signal detectors (OptimisationSignals)
run over the assembled calls.
Token estimation when usage is absent: a coarse ~4 chars per token
heuristic over the decoded prompt/completion text; flagged with
costIsEstimated = true so consumers know not to treat it as billed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA transport-agnostic captured exchange: the forwarded request, the upstream response, and the request timestamp in epoch millis (ornullwhen unknown). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild(List<LlmOptimisationReportBuilder.CapturedExchange> exchanges, String sessionKey, LlmOptimisationReport.GroupingBasis groupingBasis, List<String> redactedHeaders, List<String> redactedBodyFields) Build the report from the given exchanges.
-
Constructor Details
-
LlmOptimisationReportBuilder
public LlmOptimisationReportBuilder()
-
-
Method Details
-
build
public LlmOptimisationReport build(List<LlmOptimisationReportBuilder.CapturedExchange> exchanges, String sessionKey, LlmOptimisationReport.GroupingBasis groupingBasis, List<String> redactedHeaders, List<String> redactedBodyFields) Build the report from the given exchanges. Non-LLM exchanges (no provider detected) are ignored. The report's session key/grouping is supplied by the caller (it has already grouped/filtered the traffic).- Parameters:
exchanges- captured forwarded request/response pairs, in chronological ordersessionKey- the session/grouping key (e.g.host:api.openai.com)groupingBasis- how the traffic was groupedredactedHeaders- header names that were/are redacted before renderingredactedBodyFields- body field names that were/are redacted before rendering
-