Skip to content

Commit 3d60413

Browse files
committed
feat: updated notebooks
1 parent 8e76c7a commit 3d60413

File tree

2 files changed

+206
-131
lines changed

2 files changed

+206
-131
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {
5+
"jupyter": {
6+
"is_executing": true
7+
}
8+
},
9+
"cell_type": "code",
10+
"source": [
11+
"%load_ext autoreload\n",
12+
"%autoreload 2"
13+
],
14+
"id": "75f8c0afdb49a7bd",
15+
"outputs": [],
16+
"execution_count": null
17+
},
18+
{
19+
"metadata": {},
20+
"cell_type": "code",
21+
"source": [
22+
"import json\n",
23+
"import logging\n",
24+
"from IPython.display import HTML, Markdown\n",
25+
"\n",
26+
"\n",
27+
"logging.basicConfig(level=logging.WARNING) # set your preferred logging level here\n",
28+
"\n",
29+
"# we import the things we need (obviously)\n",
30+
"from data.VulnerabilityReport import VulnerabilityReport, create_from_flama_json # this is the function that creates the VulnerabilityReport object from the json data\n",
31+
"from ai.LLM.LLMServiceStrategy import LLMServiceStrategy \n",
32+
"\n",
33+
"from ai.LLM.Strategies.OpenAIService import OpenAIService\n",
34+
"from ai.LLM.Strategies.AnthropicService import AnthropicService\n",
35+
"from ai.LLM.Strategies.OLLAMAService import OLLAMAService # this is the service that uses ollama to generate solution\n",
36+
"\n",
37+
"model_name=None # but can be anything from here https://ollama.com/library\n",
38+
"my_strategy_local = OLLAMAService(model_name=model_name)\n",
39+
"my_strategy = AnthropicService()\n",
40+
"\n",
41+
"\n",
42+
"llm_service_local = LLMServiceStrategy(my_strategy_local)\n",
43+
"llm_service = LLMServiceStrategy(my_strategy)"
44+
],
45+
"id": "4e31ad32f428583a",
46+
"outputs": [],
47+
"execution_count": null
48+
},
49+
{
50+
"metadata": {},
51+
"cell_type": "code",
52+
"source": [
53+
"vulnerabilityReport=VulnerabilityReport.import_from_json('../../../data/VulnerabilityReport_all_llama3_instruct.json')\n",
54+
"#Markdown(vulnerabilityReport.sort().get_findings()[4].to_html())"
55+
],
56+
"id": "7c1fc9d564f0a009",
57+
"outputs": [],
58+
"execution_count": null
59+
},
60+
{
61+
"metadata": {},
62+
"cell_type": "code",
63+
"source": [
64+
"from ai.Grouping.FindingBatcher import FindingBatcher\n",
65+
"\n",
66+
"findingBatcher = FindingBatcher(llm_service_local)\n",
67+
"batches = findingBatcher.create_batches(vulnerabilityReport.get_findings())"
68+
],
69+
"id": "aaa5de83fd48e1fa",
70+
"outputs": [],
71+
"execution_count": null
72+
},
73+
{
74+
"metadata": {},
75+
"cell_type": "raw",
76+
"source": [
77+
"print([len(x) for x in batches])\n",
78+
"batches[0]"
79+
],
80+
"id": "2953629a123ac1aa"
81+
},
82+
{
83+
"metadata": {},
84+
"cell_type": "code",
85+
"source": [
86+
"from ai.Grouping.FindingGrouper import FindingGrouper\n",
87+
"\n",
88+
"findingGrouper = FindingGrouper(vulnerabilityReport, llm_service)\n",
89+
"\n",
90+
"grouped_findings = findingGrouper.generate_aggregated_solutions()"
91+
],
92+
"id": "cb15caef69d579f6",
93+
"outputs": [],
94+
"execution_count": null
95+
},
96+
{
97+
"metadata": {},
98+
"cell_type": "code",
99+
"source": [
100+
"#Markdown(vulnerabilityReport.to_html())\n",
101+
"vulnerabilityReport.export_to_json('../../../data/VulnerabilityReport_all_llama3_instruct_with_solution_by_claude.json')"
102+
],
103+
"id": "bcd6375cc442e37f",
104+
"outputs": [],
105+
"execution_count": null
106+
},
107+
{
108+
"metadata": {
109+
"jupyter": {
110+
"is_executing": true
111+
}
112+
},
113+
"cell_type": "code",
114+
"source": "",
115+
"id": "c556bfb48809eece",
116+
"outputs": [],
117+
"execution_count": null
118+
}
119+
],
120+
"metadata": {
121+
"kernelspec": {
122+
"display_name": "Python 3",
123+
"language": "python",
124+
"name": "python3"
125+
},
126+
"language_info": {
127+
"codemirror_mode": {
128+
"name": "ipython",
129+
"version": 2
130+
},
131+
"file_extension": ".py",
132+
"mimetype": "text/x-python",
133+
"name": "python",
134+
"nbconvert_exporter": "python",
135+
"pygments_lexer": "ipython2",
136+
"version": "2.7.6"
137+
}
138+
},
139+
"nbformat": 4,
140+
"nbformat_minor": 5
141+
}

0 commit comments

Comments
 (0)