Spaces:
Configuration error
Configuration error
stagbrook-tech
commited on
Commit
·
ea7fd90
1
Parent(s):
b33b252
Initial commit
Browse files- README.md +82 -12
- models/model_config.py +10 -0
- monitoring/grafana_dashboard.json +22 -0
- monitoring/prometheus_config.yaml +8 -0
- scripts/execute_command.py +30 -0
- scripts/fine_tune.py +64 -0
- scripts/test_file.txt +1 -0
- scripts/web_scrape.py +23 -0
- server/app.py +24 -0
- workflows/airflow_dags.py +32 -0
README.md
CHANGED
@@ -1,12 +1,82 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# HarmonyAI
|
2 |
+
|
3 |
+
HarmonyAI is a powerful, self-improving AI system designed to understand and execute commands with human-like comprehension and intention. It continuously self-evaluates and optimizes its capabilities, focusing on generating financial success through ethical, innovative software solutions.
|
4 |
+
|
5 |
+
## Directory Structure
|
6 |
+
|
7 |
+
\```
|
8 |
+
harmonyai/
|
9 |
+
├── dataset/
|
10 |
+
│ └── commands_dataset.csv
|
11 |
+
├── scripts/
|
12 |
+
│ ├── execute_command.py
|
13 |
+
│ ├── fine_tune.py
|
14 |
+
│ └── web_scrape.py
|
15 |
+
├── models/
|
16 |
+
│ └── model_config.py
|
17 |
+
├── server/
|
18 |
+
│ └── app.py
|
19 |
+
├── workflows/
|
20 |
+
│ └── airflow_dags.py
|
21 |
+
├── monitoring/
|
22 |
+
│ ├── prometheus_config.yaml
|
23 |
+
│ └── grafana_dashboard.json
|
24 |
+
└── README.md
|
25 |
+
\```
|
26 |
+
|
27 |
+
## Components
|
28 |
+
|
29 |
+
### Dataset
|
30 |
+
|
31 |
+
The dataset includes a variety of commands, intents, effective methods, permissions, safety checks, self-improvement directives, and user interaction examples.
|
32 |
+
|
33 |
+
### Scripts
|
34 |
+
|
35 |
+
- `execute_command.py`: Handles the execution of commands sent to HarmonyAI.
|
36 |
+
- `fine_tune.py`: Fine-tunes the selected models using the prepared dataset.
|
37 |
+
- `web_scrape.py`: Scrapes websites for data to be used in fine-tuning the model.
|
38 |
+
|
39 |
+
### Models
|
40 |
+
|
41 |
+
- `model_config.py`: Configuration for the models used by HarmonyAI.
|
42 |
+
|
43 |
+
### Server
|
44 |
+
|
45 |
+
- `app.py`: Flask server to handle command execution requests.
|
46 |
+
|
47 |
+
### Workflows
|
48 |
+
|
49 |
+
- `airflow_dags.py`: Apache Airflow DAGs for workflow automation.
|
50 |
+
|
51 |
+
### Monitoring
|
52 |
+
|
53 |
+
- `prometheus_config.yaml`: Configuration for Prometheus monitoring.
|
54 |
+
- `grafana_dashboard.json`: Configuration for Grafana dashboard.
|
55 |
+
|
56 |
+
## Setup
|
57 |
+
|
58 |
+
1. **Run the setup script**:
|
59 |
+
\```
|
60 |
+
bash setup_harmonyai_auto.sh
|
61 |
+
\```
|
62 |
+
|
63 |
+
2. **Fine-tune the model**:
|
64 |
+
\```
|
65 |
+
python ~/harmonyai/scripts/fine_tune.py
|
66 |
+
\```
|
67 |
+
|
68 |
+
3. **Start the server**:
|
69 |
+
\```
|
70 |
+
python ~/harmonyai/server/app.py
|
71 |
+
\```
|
72 |
+
|
73 |
+
4. **Run Airflow**:
|
74 |
+
\```
|
75 |
+
airflow initdb
|
76 |
+
airflow webserver -p 8080
|
77 |
+
airflow scheduler
|
78 |
+
\```
|
79 |
+
|
80 |
+
5. **Monitor using Prometheus and Grafana**:
|
81 |
+
- Follow the configurations in `prometheus_config.yaml` and `grafana_dashboard.json`.
|
82 |
+
|
models/model_config.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
model_config.py
|
3 |
+
---------------
|
4 |
+
Configuration for the models used by HarmonyAI.
|
5 |
+
"""
|
6 |
+
|
7 |
+
MODEL_NAME = "redpajama/incite-chat-3b-v1"
|
8 |
+
|
9 |
+
# Additional model configuration settings can be added here
|
10 |
+
|
monitoring/grafana_dashboard.json
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"dashboard": {
|
3 |
+
"id": null,
|
4 |
+
"title": "HarmonyAI Monitoring",
|
5 |
+
"tags": [],
|
6 |
+
"timezone": "browser",
|
7 |
+
"panels": [
|
8 |
+
{
|
9 |
+
"type": "graph",
|
10 |
+
"title": "CPU Usage",
|
11 |
+
"targets": [
|
12 |
+
{
|
13 |
+
"expr": "rate(node_cpu_seconds_total[5m])",
|
14 |
+
"interval": "",
|
15 |
+
"refId": "A"
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"datasource": "Prometheus"
|
19 |
+
}
|
20 |
+
]
|
21 |
+
}
|
22 |
+
}
|
monitoring/prometheus_config.yaml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
global:
|
2 |
+
scrape_interval: 15s
|
3 |
+
|
4 |
+
scrape_configs:
|
5 |
+
- job_name: "flask_server"
|
6 |
+
static_configs:
|
7 |
+
- targets: ["localhost:5000"]
|
8 |
+
|
scripts/execute_command.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
execute_command.py
|
3 |
+
-------------------
|
4 |
+
This script handles the execution of commands sent to HarmonyAI.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import requests
|
8 |
+
|
9 |
+
def is_safe(command, script):
|
10 |
+
# Implement safety checks here
|
11 |
+
return True
|
12 |
+
|
13 |
+
def send_command_to_server(command, script):
|
14 |
+
response = requests.post("http://localhost:5000/execute", json={"command": command, "script": script})
|
15 |
+
return response.json()
|
16 |
+
|
17 |
+
def execute_command(command, script):
|
18 |
+
if is_safe(command, script):
|
19 |
+
result = send_command_to_server(command, script)
|
20 |
+
print(result)
|
21 |
+
else:
|
22 |
+
print("Command is not safe to execute.")
|
23 |
+
|
24 |
+
# Example usage
|
25 |
+
command = "Go through my email, find the website I signed up for, and cancel my subscription."
|
26 |
+
script = """#!/bin/bash
|
27 |
+
# Script to search emails and cancel subscription
|
28 |
+
python search_emails.py --action cancel_subscription"""
|
29 |
+
execute_command(command, script)
|
30 |
+
|
scripts/fine_tune.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
fine_tune.py
|
3 |
+
------------
|
4 |
+
This script fine-tunes the selected models using the prepared dataset.
|
5 |
+
"""
|
6 |
+
|
7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, Trainer, TrainingArguments
|
8 |
+
import pandas as pd
|
9 |
+
import torch
|
10 |
+
|
11 |
+
# Load dataset
|
12 |
+
df = pd.read_csv("../dataset/commands_dataset.csv")
|
13 |
+
commands = df["command"].tolist()
|
14 |
+
intents = df["intent"].tolist()
|
15 |
+
methods = df["effective_method"].tolist()
|
16 |
+
checks = df["safety_check"].tolist()
|
17 |
+
permissions = df["permissions"].tolist()
|
18 |
+
|
19 |
+
class CommandsDataset(torch.utils.data.Dataset):
|
20 |
+
def __init__(self, tokenizer, commands, intents, methods, checks, permissions, max_length=512):
|
21 |
+
self.tokenizer = tokenizer
|
22 |
+
self.commands = commands
|
23 |
+
self.intents = intents
|
24 |
+
self.methods = methods
|
25 |
+
self.checks = checks
|
26 |
+
self.permissions = permissions
|
27 |
+
self.max_length = max_length
|
28 |
+
|
29 |
+
def __len__(self):
|
30 |
+
return len(self.commands)
|
31 |
+
|
32 |
+
def __getitem__(self, idx):
|
33 |
+
input_text = f"Command: {self.commands[idx]} Intent: {self.intents[idx]} Method: {self.methods[idx]} Safety Check: {self.checks[idx]} Permissions: {self.permissions[idx]}"
|
34 |
+
encoding = self.tokenizer(input_text, truncation=True, padding="max_length", max_length=self.max_length, return_tensors="pt")
|
35 |
+
return {key: val.squeeze() for key, val in encoding.items()}
|
36 |
+
|
37 |
+
# Load tokenizer and model
|
38 |
+
tokenizer = AutoTokenizer.from_pretrained("redpajama/incite-chat-3b-v1")
|
39 |
+
model = AutoModelForCausalLM.from_pretrained("redpajama/incite-chat-3b-v1")
|
40 |
+
|
41 |
+
# Prepare dataset
|
42 |
+
dataset = CommandsDataset(tokenizer, commands, intents, methods, checks, permissions)
|
43 |
+
|
44 |
+
# Training arguments
|
45 |
+
training_args = TrainingArguments(
|
46 |
+
output_dir="./results",
|
47 |
+
num_train_epochs=3,
|
48 |
+
per_device_train_batch_size=2,
|
49 |
+
per_device_eval_batch_size=2,
|
50 |
+
warmup_steps=10,
|
51 |
+
weight_decay=0.01,
|
52 |
+
logging_dir="./logs",
|
53 |
+
)
|
54 |
+
|
55 |
+
# Trainer
|
56 |
+
trainer = Trainer(
|
57 |
+
model=model,
|
58 |
+
args=training_args,
|
59 |
+
train_dataset=dataset,
|
60 |
+
)
|
61 |
+
|
62 |
+
# Fine-tune the model
|
63 |
+
trainer.train()
|
64 |
+
|
scripts/test_file.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
test content
|
scripts/web_scrape.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
web_scrape.py
|
3 |
+
-------------
|
4 |
+
This script scrapes websites for data to be used in fine-tuning the model.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import requests
|
8 |
+
from bs4 import BeautifulSoup
|
9 |
+
|
10 |
+
def scrape_site(url):
|
11 |
+
response = requests.get(url)
|
12 |
+
if response.status_code == 200:
|
13 |
+
soup = BeautifulSoup(response.content, "html.parser")
|
14 |
+
# Implement data extraction logic here
|
15 |
+
return soup.get_text()
|
16 |
+
return ""
|
17 |
+
|
18 |
+
# Example usage
|
19 |
+
url = "https://example.com"
|
20 |
+
data = scrape_site(url)
|
21 |
+
with open("../data/scraped_data.txt", "w") as file:
|
22 |
+
file.write(data)
|
23 |
+
|
server/app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
app.py
|
3 |
+
------
|
4 |
+
Flask server to handle command execution requests.
|
5 |
+
"""
|
6 |
+
|
7 |
+
from flask import Flask, request, jsonify
|
8 |
+
import subprocess
|
9 |
+
|
10 |
+
app = Flask(__name__)
|
11 |
+
|
12 |
+
@app.route("/execute", methods=["POST"])
|
13 |
+
def execute():
|
14 |
+
data = request.json
|
15 |
+
script = data["script"]
|
16 |
+
with open("temp_script.sh", "w") as file:
|
17 |
+
file.write(script)
|
18 |
+
subprocess.run(["chmod", "+x", "temp_script.sh"])
|
19 |
+
result = subprocess.run(["./temp_script.sh"], capture_output=True, text=True)
|
20 |
+
return jsonify({"output": result.stdout, "error": result.stderr})
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
app.run(port=5000)
|
24 |
+
|
workflows/airflow_dags.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
airflow_dags.py
|
3 |
+
---------------
|
4 |
+
Apache Airflow DAGs for workflow automation.
|
5 |
+
"""
|
6 |
+
|
7 |
+
from airflow import DAG
|
8 |
+
from airflow.operators.python_operator import PythonOperator
|
9 |
+
from datetime import datetime
|
10 |
+
|
11 |
+
default_args = {
|
12 |
+
"owner": "airflow",
|
13 |
+
"start_date": datetime(2023, 1, 1),
|
14 |
+
"retries": 1,
|
15 |
+
}
|
16 |
+
|
17 |
+
dag = DAG(
|
18 |
+
"harmonyai_workflow",
|
19 |
+
default_args=default_args,
|
20 |
+
description="HarmonyAI workflow automation",
|
21 |
+
schedule_interval="@daily",
|
22 |
+
)
|
23 |
+
|
24 |
+
def example_task():
|
25 |
+
print("Executing example task")
|
26 |
+
|
27 |
+
task = PythonOperator(
|
28 |
+
task_id="example_task",
|
29 |
+
python_callable=example_task,
|
30 |
+
dag=dag,
|
31 |
+
)
|
32 |
+
|