Skip to content

Commit 9c41f24

Browse files
authored
Merge pull request #6558 from psiinon/llm/stats
llm: add basic stats
2 parents 14563fe + dd3933f commit 9c41f24

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

addOns/callhome/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7-
7+
### Added
8+
- LLM stats to telemetry.
89

910
## [0.14.0] - 2025-01-09
1011
### Changed

addOns/callhome/src/main/java/org/zaproxy/addon/callhome/ExtensionCallHome.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public boolean test(Entry<String, Long> t) {
299299
|| key.startsWith("stats.fuzz.")
300300
|| key.startsWith("stats.graphql.")
301301
|| key.startsWith("stats.hud.")
302+
|| key.startsWith("stats.llm.")
302303
|| key.startsWith("stats.network.")
303304
|| key.startsWith("stats.oast.")
304305
|| key.startsWith("stats.openapi.")

addOns/llm/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
## Unreleased
77
### Added
88
- Allow to perform API sequencing and alert review.
9-
9+
- Basic stats

addOns/llm/src/main/java/org/zaproxy/addon/llm/services/LlmAssistant.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
public interface LlmAssistant {
2929
@UserMessage(
30-
"Given the following OpenAPI definition, generate a list of chained HTTP requests to simulate a real world interaction : {{swagger}} ")
31-
HttpRequestList extractHttpRequests(String swagger);
30+
"Given the following OpenAPI definition, generate a list of chained HTTP requests to simulate a real world interaction : {{openapi}} ")
31+
HttpRequestList extractHttpRequests(String openapi);
3232

3333
@UserMessage(
34-
"As a software architect, and based on your previous answer, generate other potential missing endpoints that are not mentioned in the swagger file. For example, if there is GET /product/1, suggest DELETE /product/1 if it's not mentioned")
34+
"As a software architect, and based on your previous answer, generate other potential missing endpoints that are not mentioned in the OpenAPI file. For example, if there is GET /product/1, suggest DELETE /product/1 if it's not mentioned")
3535
HttpRequestList complete();
3636

3737
@SystemMessage(

addOns/llm/src/main/java/org/zaproxy/addon/llm/services/LlmCommunicationService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.zaproxy.addon.llm.utils.HistoryPersister;
4949
import org.zaproxy.addon.llm.utils.Requestor;
5050
import org.zaproxy.zap.extension.alert.ExtensionAlert;
51+
import org.zaproxy.zap.utils.Stats;
5152

5253
public class LlmCommunicationService {
5354

@@ -99,12 +100,15 @@ private ChatLanguageModel buildModel(LlmOptions options) {
99100
};
100101
}
101102

102-
private Integer importHttpCalls(String swaggercontent) throws IOException {
103-
HttpRequestList listHttpRequest = llmAssistant.extractHttpRequests(swaggercontent);
103+
private Integer importHttpCalls(String openapiContent) throws IOException {
104+
Stats.incCounter("stats.llm.openapiseq.call");
105+
HttpRequestList listHttpRequest = llmAssistant.extractHttpRequests(openapiContent);
104106
if (listHttpRequest == null) {
107+
Stats.incCounter("stats.llm.openapiseq.fail");
105108
throw new RuntimeException(
106109
"An issue occurred when trying to get response from the LLM");
107110
}
111+
Stats.incCounter("stats.llm.openapiseq.result.count", listHttpRequest.getRequests().size());
108112
requestor.run(listHttpRequest);
109113
return listHttpRequest.getRequests().size();
110114
}
@@ -165,7 +169,15 @@ public void reviewAlert(Alert alert) {
165169
Confidence llmConfidence;
166170
LOGGER.debug("Reviewing alert : {}", alert.getName());
167171
LOGGER.debug("Confidence level from ZAP : {}", alert.getConfidence());
172+
Stats.incCounter("stats.llm.alertreview.call");
168173
llmConfidence = llmAssistant.review(alert.getDescription(), alert.getEvidence());
174+
175+
if (llmConfidence.getLevel() == alert.getConfidence()) {
176+
Stats.incCounter("stats.llm.alertreview.result.same");
177+
} else {
178+
Stats.incCounter("stats.llm.alertreview.result.changed");
179+
}
180+
169181
LOGGER.debug(
170182
"Confidence level from LLM : {} | Explanation : {}",
171183
llmConfidence.getLevel(),

0 commit comments

Comments
 (0)