Skip to content

Commit

Permalink
adding code
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Mar 19, 2024
1 parent 29859f5 commit 7141a42
Show file tree
Hide file tree
Showing 14 changed files with 898 additions and 0 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Build, Test, and Release

on:
pull_request:
branches:
- main
types:
- closed

jobs:
release-build:
runs-on: ubuntu-latest
permissions:
contents: write # This line adds write permissions for this job

steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y
- name: Bump version in setup.py
if: github.event.pull_request.merged == true
id: bump_version
run: |
python bump_version.py
- name: Upload new version as artifact
uses: actions/upload-artifact@v2
with:
name: new-version-artifact
path: new_version.txt

- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Commit and push version bump
run: |
git add setup.py
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Bump version [ci skip]"
git push origin main
- name: Install build tool
run: |
python -m pip install --upgrade pip build
- name: Build release distributions
run: |
python -m build --sdist --wheel .
- name: Upload release distributions
uses: actions/upload-artifact@v3
with:
name: release-dists
path: dist/

pypi-docker-publish:
runs-on: ubuntu-latest
environment: neutron
needs: release-build
permissions:
id-token: write
contents: write

steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Retrieve release distributions
uses: actions/download-artifact@v3
with:
name: release-dists
path: dist/

- name: Publish release distributions to PyPI
if: github.event.pull_request.merged == true
uses: pypa/gh-action-pypi-publish@release/v1

- name: Download new version artifact
uses: actions/download-artifact@v2
with:
name: new-version-artifact
path: ./

- name: Set new version variable
id: set_version_var
run: |
echo "NEW_VERSION=$(<new_version.txt)" >> $GITHUB_ENV

- name: Create GitHub Release
if: github.event.pull_request.merged == true
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.NEW_VERSION }}
release_name: Release ${{ env.NEW_VERSION }}
draft: false
prerelease: false
body: |
Release Notes:
- Initial release
- name: Upload Release Assets
if: github.event.pull_request.merged == true
run: |
for asset in dist/*; do
gh release upload ${{ env.NEW_VERSION }} $asset
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist
neutron_ai.egg-info
*.pyc
__pycache__
.ruff_cache
*.so
build
24 changes: 24 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BSD 2-Clause License

Copyright (c) 2023, berylliumsec

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 changes: 145 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,146 @@
# Neutron

Welcome to Neutron.

![Neutron](/images/neutron.png)

## Galaxy

- [Neutron](#Neutron)
- [Galaxy](#galaxy)
- [Acknowledgement](#acknowledgement)
- [Why Neutron?](#why-Neutron)
- [Compatibility](#compatibility)
- [System dependencies and installation](#system-dependencies)
- [Upgrading](#upgrading)
- [Usage.](#usage)



## Acknowledgement

**First i would like to thank the All-Mighty God who is the source of all knowledge, without Him, this would not be possible.**

**Disclaimer: AI can make mistakes, consider cross-checking suggestions.**

## [Click Here to Watch Neutron in Action](https://youtu.be/v5X8TNPsMbM)

## Why Neutron?

The purpose of Neutron is straightforward: to provide security professionals with access to a free AI assistant that can be invoked directly from their command line interface.

## Compatibility

Neutron has been extensively tested and optimized for Linux platforms. As of now, its functionality on Windows or macOS is not guaranteed, and it may not operate as expected.

## System dependencies

- Storage: A minimum of 50GB is recommended.

- RAM: A minimum of 32GB RAM memory is recommended.

- Graphics Processing Unit (GPU): While not mandatory, having at least 24GB of GPU memory is recommended for optimal performance.


**PYPI based distribution requirement(s)**

- Python3: Version 3.10 or later is required for compatibility with all used libraries.
- PyTorch: A machine learning library for Python, used for computations and serving as a foundation for the Transformers library.
- Transformers library by Hugging Face: Provides state-of-the-art machine learning techniques for natural language processing tasks. Required for models and tilities used in NLP operations.
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python type hints.
- Uvicorn: An ASGI server for Python, needed to run FastAPI applications.
- Pydantic: Data validation and settings management using Python type annotations, utilized within FastAPI applications.
- Langchain Community and Core libraries : Utilized for specific functionalities related to embeddings, vector stores, and more in the context of language processing.
- Regular Expressions (re module in Python Standard Library): Utilized for string operations
- Requests library

To install the above dependencies:

```bash
pip install fastapi uvicorn pydantic torch transformers regex argparse typing-extensions langchain_community langchain_core

```

**PIP**:

```
pip install neutron-ai
```

## Upgrading

For optimal performance and to ensure access to the most recent advancements, we consistently release updates and refinements to our models. Neutron will proactively inform you of any available updates to the package or the models upon each execution.

PIP:

```bash
pip install neutron-ai --upgrade
```

## Usage.

### Server

``` bash
usage: server.py [-h] [--host HOST] [--port PORT]

Run the FastAPI server.

options:
-h, --help show this help message and exit
--host HOST The hostname to listen on. Default is 0.0.0.0.
--port PORT The port of the webserver. Default is 8000.
```

The server can be invoked using the following command after installation using pip:

```
neutron-server 0.0.0.0 8000
```

### Client

```bash
usage: client.py [-h] [--server_url SERVER_URL] question

Send a question to the AI server.

positional arguments:
question The question to ask the AI server.

options:
-h, --help show this help message and exit
--server_url SERVER_URL
The URL of the AI server, defaults to http://localhost:8000
```

The client can be invoked using the following command after installation using pip:

```bash
neutron-client "your question"
```


To use Neutron AI directly from the command line using a shorter alias for example AN, add the following function to your .bashrc or .zshrc:

```bash
function AN() {
local query=\"$*\"
neutron-client \"\$query\"
}
```
After adding, restart your terminal or run 'source ~/.bashrc' (or 'source ~/.zshrc') to apply the changes.

Then after starting the server, you can ask your questions like so:

```bash
AN your question
```

### Authentication

To use a password for the server and client simply add it to your ENVs before you run the server and the client like so:

```bash
export NEUTRON_TOKEN="YOUR_SECRET"
```
Binary file added images/neutron.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.ruff]
ignore = ["E501", "E722", "F401"]
fixable = ["ALL"]
exclude = ["src/__init__.py"]
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fastapi
uvicorn
pydantic
torch
transformers
regex
argparse
typing-extensions
langchain_community
langchain_core
47 changes: 47 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from setuptools import find_packages, setup

setup(
name="neutron-ai",
version="1.0.0b1",
description="AI Powered Ethical Hacking Assistant",
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
author="David I",
author_email="david@berylliumsec.com",
url="https://github.com/berylliumsec/neutron",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Security",
"Topic :: Text Processing :: Linguistic",
],
license="BSD",
keywords="AI, Ethical Hacking",
package_dir={"": "src"},
packages=find_packages(where="src"),
package_data={
"neutron": ["images/*"], # Make sure this reflects the actual structure
},
install_requires=[
"torch>=1.0.1",
"transformers>=4.34.0",
"fastapi",
"uvicorn",
"pydantic",
# Add any other dependencies as necessary
],
entry_points={
"console_scripts": [
# Allows users to type 'neutron-client' in the command line to interact with the server
"neutron-client=neutron.client:main",
# Allows users to start the server by typing 'neutron-server'
"neutron-server=neutron.server:main",
],
},
python_requires=">=3.10",
)
Empty file added src/neutron/__init__.py
Empty file.

0 comments on commit 7141a42

Please sign in to comment.