Skip to content

Commit

Permalink
Merge pull request #2 from stratosphereips/patch-1-documentation
Browse files Browse the repository at this point in the history
Add action badges to README, tests and fix actions CI
  • Loading branch information
verovaleros authored Feb 13, 2024
2 parents 6026801 + 1faff02 commit 9857fd9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# hermeneisGPT
[![Auto Tag](https://github.com/stratosphereips/hermeneisGPT/actions/workflows/autotag.yml/badge.svg)](https://github.com/stratosphereips/hermeneisGPT/actions/workflows/autotag.yml)
[![Validate Python](https://github.com/stratosphereips/hermeneisGPT/actions/workflows/validate_python.yml/badge.svg)](https://github.com/stratosphereips/hermeneisGPT/actions/workflows/validate_python.yml)
[![Validate Yaml](https://github.com/stratosphereips/hermeneisGPT/actions/workflows/validate_yaml.yml/badge.svg)](https://github.com/stratosphereips/hermeneisGPT/actions/workflows/validate_yaml.yml)


HermeneisGPT is a framework to translate hacking messages from Russian to English using LLM models.
36 changes: 21 additions & 15 deletions hermeneisGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@
logger.addHandler(console_handler)


def load_and_parse_config(yaml_config_path):
try:
with open(yaml_config_path, 'r', encoding="utf-8") as configuration_yaml:
yaml_config = yaml.safe_load(configuration_yaml)
logger.info("Loaded data from YAML file: %s", yaml_config_path)
except Exception as e:
logger.error("Error reading YAML file: %s", e)
raise

config = {
'type': yaml_config['personality']['type'],
'prompt': yaml_config['personality']['prompt'],
'model': yaml_config['personality']['model'],
'temperature': yaml_config['personality']['temperature'],
'max_tokens': yaml_config['personality']['max_tokens'],
'log': yaml_config['personality']['log']
}

return config

def main():
"""
Take a message input and use the data from the yaml file to translate
Expand All @@ -57,21 +77,7 @@ def main():
args = parser.parse_args()

# Read YAML Configuration file
try:
with open(args.yaml_config, 'r', encoding="utf-8") as configuration_yaml:
yaml_config = yaml.safe_load(configuration_yaml)
logger.info("Loaded data from YAML file: %s", args.yaml_config)
except Exception as e:
logger.error("Error reading YAML file: %s", e)
raise

# Parse configuration parameters
config_type = yaml_config['personality']['type']
config_prompt = yaml_config['personality']['prompt']
config_model = yaml_config['personality']['model']
config_temp = yaml_config['personality']['temperature']
config_max_tokens = yaml_config['personality']['max_tokens']
config_log = yaml_config['personality']['log']
config = load_and_parse_config(args.yaml_config)

# TODO Add main logic here

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYAML
55 changes: 55 additions & 0 deletions tests/test_hermeneisGPT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# pylint: disable=missing-docstring
import sys
import pytest
import logging
from os import path
from unittest.mock import patch

sys.path.append( path.dirname(path.dirname( path.abspath(__file__) ) ))
from hermeneisGPT import load_and_parse_config


def test_load_and_parse_config_success(tmp_path):
directory = tmp_path / "sub"
directory.mkdir()
path = directory / "config.yaml"
path.write_text("""
personality:
type: test_type
prompt: test_prompt
model: test_model
temperature: 0.5
max_tokens: 100
log: output.log
""", encoding='utf-8')

# Patch 'logging.Logger.info' and 'logging.Logger.error'
with patch.object(logging.Logger, 'info') as mock_info, \
patch.object(logging.Logger, 'error') as mock_error:
config = load_and_parse_config(str(path))

# Check if 'info' was called at least once
mock_info.assert_called()
# Check if 'error' was not called, indicating no errors occurred
mock_error.assert_not_called()
assert config == {
'type': 'test_type',
'prompt': 'test_prompt',
'model': 'test_model',
'temperature': 0.5,
'max_tokens': 100,
'log': 'output.log'
}


# Example of a failure to load due to file not found or other IO issues
def test_load_and_parse_config_failure(tmp_path):
non_existent_file_path = tmp_path / "does_not_exist.yaml"

# Patch 'logging.Logger.error'
with patch.object(logging.Logger, 'error') as mock_error, \
pytest.raises(FileNotFoundError):
load_and_parse_config(str(non_existent_file_path))

# Check if 'error' was called at least once
mock_error.assert_called_once()

0 comments on commit 9857fd9

Please sign in to comment.