Skip to content

Commit

Permalink
Merge pull request #1259 from yogeshojha/feature/llm
Browse files Browse the repository at this point in the history
Add LLM Toolkit
  • Loading branch information
yogeshojha authored May 12, 2024
2 parents 7bb9d42 + 95f5384 commit 56da132
Show file tree
Hide file tree
Showing 20 changed files with 680 additions and 84 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Thanks to these individuals for making reNgine awesome by fixing bugs, resolving
* [Suprita-25](https://github.com/Suprita-25)
* [TheBinitGhimire](https://github.com/TheBinitGhimire)
* [Vinay Leo](https://github.com/vinaynm)
* [Erdem Ozgen](https://github.com/ErdemOzgen)

*If you have created a Pull request, feel free to add your name here, because we know you are awesome and deserve thanks from the community!*

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include .env
COMPOSE_PREFIX_CMD := COMPOSE_DOCKER_CLI_BUILD=1

COMPOSE_ALL_FILES := -f docker-compose.yml
SERVICES := db web proxy redis celery celery-beat
SERVICES := db web proxy redis celery celery-beat ollama

# --------------------------

Expand Down
12 changes: 12 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ services:
- celery-beat
networks:
- rengine_network
ollama:
image: ollama/ollama
container_name: ollama
volumes:
- ollama_data:/root/.ollama
# ports:
# - "11434:11434"
networks:
- rengine_network
restart: always
# command: ["ollama", "run", "llama2-uncensored"]

networks:
rengine_network:
Expand All @@ -126,3 +137,4 @@ volumes:
github_repos:
wordlist:
scan_results:
ollama_data:
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,15 @@ services:
- scan_results:/usr/src/scan_results
networks:
- rengine_network

ollama:
image: ollama/ollama
container_name: ollama
volumes:
- ollama_data:/root/.ollama
ports:
- "11434:11434"
networks:
- rengine_network

networks:
rengine_network:
Expand All @@ -157,6 +165,7 @@ volumes:
wordlist:
scan_results:
static_volume:
ollama_data:

secrets:
proxy.ca:
Expand Down
4 changes: 4 additions & 0 deletions web/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
'tool/uninstall/',
UninstallTool.as_view(),
name='uninstall_tool'),
path(
'tool/ollama/',
OllamaManager.as_view(),
name='ollama_manager'),
path(
'rengine/update/',
RengineUpdateCheck.as_view(),
Expand Down
76 changes: 76 additions & 0 deletions web/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,82 @@
logger = logging.getLogger(__name__)


class OllamaManager(APIView):
def get(self, request):
"""
API to download Ollama Models
sends a POST request to download the model
"""
req = self.request
model_name = req.query_params.get('model')
response = {
'status': False
}
try:
pull_model_api = f'{OLLAMA_INSTANCE}/api/pull'
_response = requests.post(
pull_model_api,
json={
'name': model_name,
'stream': False
}
).json()
if _response.get('error'):
response['status'] = False
response['error'] = _response.get('error')
else:
response['status'] = True
except Exception as e:
response['error'] = str(e)
return Response(response)

def delete(self, request):
req = self.request
model_name = req.query_params.get('model')
delete_model_api = f'{OLLAMA_INSTANCE}/api/delete'
response = {
'status': False
}
try:
_response = requests.delete(
delete_model_api,
json={
'name': model_name
}
).json()
if _response.get('error'):
response['status'] = False
response['error'] = _response.get('error')
else:
response['status'] = True
except Exception as e:
response['error'] = str(e)
return Response(response)

def put(self, request):
req = self.request
model_name = req.query_params.get('model')
# check if model_name is in DEFAULT_GPT_MODELS
response = {
'status': False
}
use_ollama = True
if any(model['name'] == model_name for model in DEFAULT_GPT_MODELS):
use_ollama = False
try:
OllamaSettings.objects.update_or_create(
defaults={
'selected_model': model_name,
'use_ollama': use_ollama
},
id=1
)
response['status'] = True
except Exception as e:
response['error'] = str(e)
return Response(response)


class GPTAttackSuggestion(APIView):
def get(self, request):
req = self.request
Expand Down
20 changes: 20 additions & 0 deletions web/dashboard/migrations/0010_ollamasettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.4 on 2024-04-21 04:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0009_delete_openaikeys'),
]

operations = [
migrations.CreateModel(
name='OllamaSettings',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('selected_model', models.CharField(max_length=500)),
],
),
]
18 changes: 18 additions & 0 deletions web/dashboard/migrations/0011_ollamasettings_is_ollama.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2024-04-21 05:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0010_ollamasettings'),
]

operations = [
migrations.AddField(
model_name='ollamasettings',
name='is_ollama',
field=models.BooleanField(default=False),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2024-04-21 05:06

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0011_ollamasettings_is_ollama'),
]

operations = [
migrations.RenameField(
model_name='ollamasettings',
old_name='is_ollama',
new_name='is_openai',
),
]
22 changes: 22 additions & 0 deletions web/dashboard/migrations/0013_auto_20240421_0507.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.4 on 2024-04-21 05:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0012_rename_is_ollama_ollamasettings_is_openai'),
]

operations = [
migrations.RemoveField(
model_name='ollamasettings',
name='is_openai',
),
migrations.AddField(
model_name='ollamasettings',
name='is_ollama',
field=models.BooleanField(default=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2024-04-21 05:08

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0013_auto_20240421_0507'),
]

operations = [
migrations.RenameField(
model_name='ollamasettings',
old_name='is_ollama',
new_name='use_ollama',
),
]
9 changes: 9 additions & 0 deletions web/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class OpenAiAPIKey(models.Model):

def __str__(self):
return self.key


class OllamaSettings(models.Model):
id = models.AutoField(primary_key=True)
selected_model = models.CharField(max_length=500)
use_ollama = models.BooleanField(default=True)

def __str__(self):
return self.selected_model


class NetlasAPIKey(models.Model):
Expand Down
46 changes: 46 additions & 0 deletions web/reNgine/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,52 @@
FOUR_OH_FOUR_URL = '/404/'


###############################################################################
# OLLAMA DEFINITIONS
###############################################################################
OLLAMA_INSTANCE = 'http://ollama:11434'

DEFAULT_GPT_MODELS = [
{
'name': 'gpt-3',
'model': 'gpt-3',
'modified_at': '',
'details': {
'family': 'GPT',
'parameter_size': '~175B',
}
},
{
'name': 'gpt-3.5-turbo',
'model': 'gpt-3.5-turbo',
'modified_at': '',
'details': {
'family': 'GPT',
'parameter_size': '~7B',
}
},
{
'name': 'gpt-4',
'model': 'gpt-4',
'modified_at': '',
'details': {
'family': 'GPT',
'parameter_size': '~1.7T',
}
},
{
'name': 'gpt-4-turbo',
'model': 'gpt-4',
'modified_at': '',
'details': {
'family': 'GPT',
'parameter_size': '~1.7T',
}
}
]



# GPT Vulnerability Report Generator
VULNERABILITY_DESCRIPTION_SYSTEM_MESSAGE = """
You are a highly skilled penetration tester who has recently completed a penetration testing.
Expand Down
Loading

0 comments on commit 56da132

Please sign in to comment.