adding more function to shka and pytagoras
Browse files- req.txt +2 -1
- satellites/atlasSat/atlas.py +3 -2
- satellites/base_satellite.py +2 -2
- satellites/lilithSat/lilith.py +3 -3
- satellites/pythagorasSat/pythagoras.py +116 -1
- satellites/shakaSat/shaka.py +99 -2
- satellites/yorkSat/york.py +3 -1
- tests/shaka_test.py +11 -0
req.txt
CHANGED
|
@@ -8,5 +8,6 @@ scipy
|
|
| 8 |
scikit-learn
|
| 9 |
pandas
|
| 10 |
psutil
|
| 11 |
-
|
|
|
|
| 12 |
|
|
|
|
| 8 |
scikit-learn
|
| 9 |
pandas
|
| 10 |
psutil
|
| 11 |
+
python-dotenv
|
| 12 |
+
beautifulsoup4
|
| 13 |
|
satellites/atlasSat/atlas.py
CHANGED
|
@@ -6,6 +6,7 @@ from satellites.base_satellite import VegapunkSatellite
|
|
| 6 |
import logging
|
| 7 |
import subprocess
|
| 8 |
import time
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
role = "Sécurité et Automatisation"
|
|
@@ -16,8 +17,8 @@ class Atlas(VegapunkSatellite):
|
|
| 16 |
self.monitored_directories = []
|
| 17 |
self.email_config ={}
|
| 18 |
self.external_systems = {}
|
| 19 |
-
logging.basicConfig(filename='atlas.log', level=logging.INFO)
|
| 20 |
-
|
| 21 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 22 |
task_type = task.get("type")
|
| 23 |
if task_type == "monitor_directory":
|
|
|
|
| 6 |
import logging
|
| 7 |
import subprocess
|
| 8 |
import time
|
| 9 |
+
from utils.logger import get_logger
|
| 10 |
|
| 11 |
|
| 12 |
role = "Sécurité et Automatisation"
|
|
|
|
| 17 |
self.monitored_directories = []
|
| 18 |
self.email_config ={}
|
| 19 |
self.external_systems = {}
|
| 20 |
+
# logging.basicConfig(filename='atlas.log', level=logging.INFO)
|
| 21 |
+
self.logger = get_logger("atlas")
|
| 22 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 23 |
task_type = task.get("type")
|
| 24 |
if task_type == "monitor_directory":
|
satellites/base_satellite.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
from abc import ABC, abstractmethod
|
| 4 |
from typing import Dict, Any
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
class VegapunkSatellite(ABC):
|
|
|
|
|
|
|
|
|
|
| 1 |
from abc import ABC, abstractmethod
|
| 2 |
from typing import Dict, Any
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
|
| 6 |
|
| 7 |
class VegapunkSatellite(ABC):
|
satellites/lilithSat/lilith.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from satellites.base_satellite import VegapunkSatellite
|
| 2 |
from typing import Dict, Any, List
|
| 3 |
-
import logging
|
| 4 |
import random
|
|
|
|
| 5 |
|
| 6 |
role = " Explorer des solution non conventionnel , creatove,voir risqué"
|
| 7 |
|
|
@@ -14,9 +14,9 @@ class Lilith(VegapunkSatellite):
|
|
| 14 |
self.idea_categories = ["Technologie", "Art", "Science", "Société", "Environnement"]
|
| 15 |
self.innovation_levels = ["Incrémentale", "Radicale", "Disruptive"]
|
| 16 |
self.unconventional_approaches = ["Pensée inversée", "Analogies lointaines", "Combinaison aléatoire","Contraintes extrêmes"]
|
| 17 |
-
logging.basicConfig(filename='lilith_log.txt', level=logging.INFO)
|
| 18 |
self.external_apis = {}
|
| 19 |
-
|
| 20 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 21 |
task_type = task.get("type")
|
| 22 |
if task_type == "generate_idea":
|
|
|
|
| 1 |
from satellites.base_satellite import VegapunkSatellite
|
| 2 |
from typing import Dict, Any, List
|
|
|
|
| 3 |
import random
|
| 4 |
+
from utils.logger import get_logger
|
| 5 |
|
| 6 |
role = " Explorer des solution non conventionnel , creatove,voir risqué"
|
| 7 |
|
|
|
|
| 14 |
self.idea_categories = ["Technologie", "Art", "Science", "Société", "Environnement"]
|
| 15 |
self.innovation_levels = ["Incrémentale", "Radicale", "Disruptive"]
|
| 16 |
self.unconventional_approaches = ["Pensée inversée", "Analogies lointaines", "Combinaison aléatoire","Contraintes extrêmes"]
|
| 17 |
+
# logging.basicConfig(filename='lilith_log.txt', level=logging.INFO)
|
| 18 |
self.external_apis = {}
|
| 19 |
+
self.logger = get_logger("lilith")
|
| 20 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 21 |
task_type = task.get("type")
|
| 22 |
if task_type == "generate_idea":
|
satellites/pythagorasSat/pythagoras.py
CHANGED
|
@@ -6,8 +6,20 @@ import matplotlib.pyplot as plt
|
|
| 6 |
import io
|
| 7 |
import base64
|
| 8 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import logging
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
role = "mathématiques, statistiques et analyse de données"
|
|
@@ -16,6 +28,13 @@ fonction = "Effectuer des calculs complexes et analyser des ensembles de donnée
|
|
| 16 |
class Pythagoras(VegapunkSatellite):
|
| 17 |
def __init__(self):
|
| 18 |
super().__init__(name="Pythagoras", specialty="Role")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
self.mathematical_constants = {
|
| 20 |
"pi": np.pi,
|
| 21 |
"e": np.e,
|
|
@@ -23,6 +42,7 @@ class Pythagoras(VegapunkSatellite):
|
|
| 23 |
}
|
| 24 |
self.resources = {}
|
| 25 |
self.external_apis = {}
|
|
|
|
| 26 |
|
| 27 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 28 |
task_type = task.get('type')
|
|
@@ -32,8 +52,17 @@ class Pythagoras(VegapunkSatellite):
|
|
| 32 |
return self._analyze_dataset(task.get('data'))
|
| 33 |
elif task_type == "statistical_test":
|
| 34 |
return self._perform_statistical_test(task.get('test_type'), task.get('data'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
else:
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def _perform_calculation(self, operation: str, values: List[float]) -> Dict[str, Any]:
|
| 39 |
if not operation or not values:
|
|
@@ -111,6 +140,92 @@ class Pythagoras(VegapunkSatellite):
|
|
| 111 |
except Exception as e:
|
| 112 |
return {"error": f"Erreur lors du test statistique: {str(e)}"}
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
def communicate_with_stellar(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
| 115 |
print(f"{self.name} envoie un message à Stellar: {message}")
|
| 116 |
return {"Statut": "Message reçu", "message": "Stellar a bien reçu le message de Pythagoras"}
|
|
|
|
| 6 |
import io
|
| 7 |
import base64
|
| 8 |
import random
|
| 9 |
+
from utils.logger import get_logger
|
| 10 |
+
import pandas as pd
|
| 11 |
+
from bs4 import BeautifulSoup
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
from dotenv import load_dotenv
|
| 15 |
+
import requests
|
| 16 |
import logging
|
| 17 |
|
| 18 |
+
load_dotenv()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
|
| 24 |
|
| 25 |
role = "mathématiques, statistiques et analyse de données"
|
|
|
|
| 28 |
class Pythagoras(VegapunkSatellite):
|
| 29 |
def __init__(self):
|
| 30 |
super().__init__(name="Pythagoras", specialty="Role")
|
| 31 |
+
self.llm_api_key = os.getenv("LLM_API_KEY")
|
| 32 |
+
self.llm_api_url = "https://api.openai.com/v1/chat/completions" # Example using OpenAI's API
|
| 33 |
+
self.research_databases = {
|
| 34 |
+
"scientific": "https://api.example-scientific-db.com/search",
|
| 35 |
+
"news": "https://api.example-news-db.com/search",
|
| 36 |
+
"general": "https://api.example-general-db.com/search"
|
| 37 |
+
}
|
| 38 |
self.mathematical_constants = {
|
| 39 |
"pi": np.pi,
|
| 40 |
"e": np.e,
|
|
|
|
| 42 |
}
|
| 43 |
self.resources = {}
|
| 44 |
self.external_apis = {}
|
| 45 |
+
self.logger = get_logger("pythagoras")
|
| 46 |
|
| 47 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 48 |
task_type = task.get('type')
|
|
|
|
| 52 |
return self._analyze_dataset(task.get('data'))
|
| 53 |
elif task_type == "statistical_test":
|
| 54 |
return self._perform_statistical_test(task.get('test_type'), task.get('data'))
|
| 55 |
+
if task_type == "analyze_data":
|
| 56 |
+
result = self.analyze_data_2(task["data"])
|
| 57 |
+
elif task_type == "conduct_research":
|
| 58 |
+
result = self.conduct_research(task["topic"], task.get("depth", "medium"))
|
| 59 |
+
elif task_type == "extract_information":
|
| 60 |
+
result = self.extract_information(task["content"], task.get("keywords", []))
|
| 61 |
else:
|
| 62 |
+
result = f"Tâche non reconnue : {task_type}"
|
| 63 |
+
|
| 64 |
+
self.log_activity(f"Tâche traitée : {task_type}, Résultat : {result}")
|
| 65 |
+
return {"result": result}
|
| 66 |
|
| 67 |
def _perform_calculation(self, operation: str, values: List[float]) -> Dict[str, Any]:
|
| 68 |
if not operation or not values:
|
|
|
|
| 140 |
except Exception as e:
|
| 141 |
return {"error": f"Erreur lors du test statistique: {str(e)}"}
|
| 142 |
|
| 143 |
+
def analyze_data_2(self, data: List[Dict[str, Any]]) -> Dict[str, Any]:
|
| 144 |
+
df = pd.DataFrame(data)
|
| 145 |
+
analysis = {
|
| 146 |
+
"summary": df.describe().to_dict(),
|
| 147 |
+
"correlations": df.corr().to_dict(),
|
| 148 |
+
"trends": self._detect_trends(df),
|
| 149 |
+
"outliers": self._detect_outliers(df)
|
| 150 |
+
}
|
| 151 |
+
return analysis
|
| 152 |
+
|
| 153 |
+
def conduct_research(self, topic: str, depth: str = "medium") -> Dict[str, Any]:
|
| 154 |
+
research_results = {}
|
| 155 |
+
for db_name, db_url in self.research_databases.items():
|
| 156 |
+
research_results[db_name] = self._search_database(db_url, topic, depth)
|
| 157 |
+
|
| 158 |
+
summary = self._summarize_research(topic, research_results)
|
| 159 |
+
return {
|
| 160 |
+
"topic": topic,
|
| 161 |
+
"depth": depth,
|
| 162 |
+
"results": research_results,
|
| 163 |
+
"summary": summary
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
def extract_information(self, content: str, keywords: List[str] = []) -> Dict[str, Any]:
|
| 167 |
+
prompt = f"Extraire les informations clés du texte suivant, en se concentrant sur les mots-clés {keywords} si fournis : {content}"
|
| 168 |
+
extracted_info = self._query_llm(prompt)
|
| 169 |
+
|
| 170 |
+
return {
|
| 171 |
+
"original_content_length": len(content),
|
| 172 |
+
"extracted_information": extracted_info,
|
| 173 |
+
"keywords_used": keywords
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
def _detect_trends(self, df: pd.DataFrame) -> Dict[str, Any]:
|
| 177 |
+
trends = {}
|
| 178 |
+
for column in df.select_dtypes(include=[np.number]).columns:
|
| 179 |
+
trend = stats.linregress(range(len(df)), df[column])
|
| 180 |
+
trends[column] = {
|
| 181 |
+
"slope": trend.slope,
|
| 182 |
+
"intercept": trend.intercept,
|
| 183 |
+
"r_value": trend.rvalue,
|
| 184 |
+
"p_value": trend.pvalue,
|
| 185 |
+
"trend": "increasing" if trend.slope > 0 else "decreasing"
|
| 186 |
+
}
|
| 187 |
+
return trends
|
| 188 |
+
|
| 189 |
+
def _detect_outliers(self, df: pd.DataFrame) -> Dict[str, List[Any]]:
|
| 190 |
+
outliers = {}
|
| 191 |
+
for column in df.select_dtypes(include=[np.number]).columns:
|
| 192 |
+
z_scores = np.abs(stats.zscore(df[column]))
|
| 193 |
+
outliers[column] = df[column][z_scores > 3].tolist()
|
| 194 |
+
return outliers
|
| 195 |
+
|
| 196 |
+
def _search_database(self, db_url: str, topic: str, depth: str) -> List[Dict[str, Any]]:
|
| 197 |
+
# Simuler une recherche dans une base de données externe
|
| 198 |
+
# Dans une implémentation réelle, cela ferait un appel API à la base de données
|
| 199 |
+
return [
|
| 200 |
+
{"title": f"Résultat 1 pour {topic}", "summary": f"Résumé du résultat 1 pour {topic}"},
|
| 201 |
+
{"title": f"Résultat 2 pour {topic}", "summary": f"Résumé du résultat 2 pour {topic}"}
|
| 202 |
+
]
|
| 203 |
+
|
| 204 |
+
def _summarize_research(self, topic: str, research_results: Dict[str, List[Dict[str, Any]]]) -> str:
|
| 205 |
+
# Utiliser le LLM pour résumer les résultats de recherche
|
| 206 |
+
research_summary = json.dumps(research_results)
|
| 207 |
+
prompt = f"Résumez les résultats de recherche suivants sur le sujet '{topic}' : {research_summary}"
|
| 208 |
+
return self._query_llm(prompt)
|
| 209 |
+
|
| 210 |
+
def _query_llm(self, prompt: str) -> str:
|
| 211 |
+
headers = {
|
| 212 |
+
"Authorization": f"Bearer {self.llm_api_key}",
|
| 213 |
+
"Content-Type": "application/json"
|
| 214 |
+
}
|
| 215 |
+
data = {
|
| 216 |
+
"model": "gpt-3.5-turbo",
|
| 217 |
+
"messages": [{"role": "user", "content": prompt}]
|
| 218 |
+
}
|
| 219 |
+
try:
|
| 220 |
+
response = requests.post(self.llm_api_url, headers=headers, json=data)
|
| 221 |
+
response.raise_for_status()
|
| 222 |
+
return response.json()['choices'][0]['message']['content']
|
| 223 |
+
except requests.RequestException as e:
|
| 224 |
+
return f"Erreur lors de la requête LLM : {str(e)}"
|
| 225 |
+
|
| 226 |
+
def log_activity(self, activity: str):
|
| 227 |
+
logging.info(activity)
|
| 228 |
+
|
| 229 |
def communicate_with_stellar(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
| 230 |
print(f"{self.name} envoie un message à Stellar: {message}")
|
| 231 |
return {"Statut": "Message reçu", "message": "Stellar a bien reçu le message de Pythagoras"}
|
satellites/shakaSat/shaka.py
CHANGED
|
@@ -4,7 +4,14 @@ import nltk
|
|
| 4 |
from nltk.tokenize import word_tokenize
|
| 5 |
from nltk.corpus import stopwords
|
| 6 |
import string
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import logging
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
role = "logique, éthique et analyse"
|
| 10 |
fonction = "Vérifier la cohérence des informations et filtrer les informations non éthiques"
|
|
@@ -13,7 +20,19 @@ class Shaka(VegapunkSatellite):
|
|
| 13 |
def __init__(self):
|
| 14 |
super().__init__(name="Shaka", specialty=role)
|
| 15 |
self.nlp = self._initialize_nlp_tools()
|
| 16 |
-
logging.basicConfig(filename='shaka.log', level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def _initialize_nlp_tools(self):
|
| 19 |
resources = ["stopwords", "punctuation", "averaged_perceptron_tagger", "wordnet", "punkt_tab"]
|
|
@@ -36,8 +55,19 @@ class Shaka(VegapunkSatellite):
|
|
| 36 |
return self._analyse_text(task['content'])
|
| 37 |
elif task_type == 'raisonnement_logique':
|
| 38 |
return self._logical_reasoning(task['hypothese'], task['question'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def _analyse_text(self, texte: str) -> Dict[str, Any]:
|
| 43 |
try:
|
|
@@ -66,6 +96,73 @@ class Shaka(VegapunkSatellite):
|
|
| 66 |
("pertinentes" if relevance_score > 0.5 else "peu pertinentes") + " à la question."
|
| 67 |
}
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
def communicate_with_stellar(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
| 70 |
print(f"{self.name} envoie un message à Stellar: {message}")
|
| 71 |
return {"Statut": "Message reçu", "message": "Stellar a bien reçu le message"}
|
|
|
|
| 4 |
from nltk.tokenize import word_tokenize
|
| 5 |
from nltk.corpus import stopwords
|
| 6 |
import string
|
| 7 |
+
from utils.logger import get_logger
|
| 8 |
+
import requests
|
| 9 |
+
import os
|
| 10 |
+
import json
|
| 11 |
import logging
|
| 12 |
+
from dotenv import load_dotenv
|
| 13 |
+
|
| 14 |
+
load_dotenv()
|
| 15 |
|
| 16 |
role = "logique, éthique et analyse"
|
| 17 |
fonction = "Vérifier la cohérence des informations et filtrer les informations non éthiques"
|
|
|
|
| 20 |
def __init__(self):
|
| 21 |
super().__init__(name="Shaka", specialty=role)
|
| 22 |
self.nlp = self._initialize_nlp_tools()
|
| 23 |
+
# logging.basicConfig(filename='shaka.log', level=logging.INFO)
|
| 24 |
+
self.llm_api_key = os.getenv("LLM_API_KEY")
|
| 25 |
+
self.llm_api_url = "https://api.openai.com/v1/chat/completions" # Example using OpenAI's API
|
| 26 |
+
self.fact_check_api = "https://factchecktools.googleapis.com/v1alpha1/claims:search"
|
| 27 |
+
self.fact_check_api_key = os.getenv("FACT_CHECK_API_KEY")
|
| 28 |
+
self.ethical_filter_active = True
|
| 29 |
+
self.ethical_guidelines = [
|
| 30 |
+
"Ne pas promouvoir la violence ou des activités illégales",
|
| 31 |
+
"Éviter les discriminations basées sur la race, le genre, la religion, etc.",
|
| 32 |
+
"Respecter la vie privée et les données personnelles",
|
| 33 |
+
"Promouvoir l'honnêteté et la transparence",
|
| 34 |
+
"Éviter la désinformation et les fake news"]
|
| 35 |
+
self.logger = get_logger("shaka")
|
| 36 |
|
| 37 |
def _initialize_nlp_tools(self):
|
| 38 |
resources = ["stopwords", "punctuation", "averaged_perceptron_tagger", "wordnet", "punkt_tab"]
|
|
|
|
| 55 |
return self._analyse_text(task['content'])
|
| 56 |
elif task_type == 'raisonnement_logique':
|
| 57 |
return self._logical_reasoning(task['hypothese'], task['question'])
|
| 58 |
+
elif task_type == "ethical_check":
|
| 59 |
+
result = self.check_ethics(task["content"])
|
| 60 |
+
elif task_type == "fact_check":
|
| 61 |
+
result = self.verify_facts(task["claim"])
|
| 62 |
+
elif task_type == "provide_recommendations":
|
| 63 |
+
result = self.provide_ethical_recommendations(task["content"])
|
| 64 |
+
elif task_type == "toggle_ethical_filter":
|
| 65 |
+
result = self.toggle_ethical_filter()
|
| 66 |
else:
|
| 67 |
+
result = f"Tâche non reconnue : {task_type}"
|
| 68 |
+
|
| 69 |
+
self.log_activity(f"Tâche traitée : {task_type}, Résultat : {result}")
|
| 70 |
+
return {"result": result}
|
| 71 |
|
| 72 |
def _analyse_text(self, texte: str) -> Dict[str, Any]:
|
| 73 |
try:
|
|
|
|
| 96 |
("pertinentes" if relevance_score > 0.5 else "peu pertinentes") + " à la question."
|
| 97 |
}
|
| 98 |
|
| 99 |
+
def check_ethics(self, content: str) -> Dict[str, Any]:
|
| 100 |
+
if not self.ethical_filter_active:
|
| 101 |
+
return {"status": "Le filtre éthique est désactivé", "content": content}
|
| 102 |
+
|
| 103 |
+
prompt = f"Analysez le contenu suivant et déterminez s'il est éthique selon ces directives : {self.ethical_guidelines}. Contenu : '{content}'"
|
| 104 |
+
response = self._query_llm(prompt)
|
| 105 |
+
is_ethical = "éthique" in response.lower() and "non éthique" not in response.lower()
|
| 106 |
+
|
| 107 |
+
return {
|
| 108 |
+
"content": content,
|
| 109 |
+
"is_ethical": is_ethical,
|
| 110 |
+
"analysis": response
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
def verify_facts(self, claim: str) -> Dict[str, Any]:
|
| 114 |
+
# Utilisation de l'API Google Fact Check Tools (nécessite une clé API valide)
|
| 115 |
+
params = {
|
| 116 |
+
"key": self.fact_check_api_key,
|
| 117 |
+
"query": claim
|
| 118 |
+
}
|
| 119 |
+
try:
|
| 120 |
+
response = requests.get(self.fact_check_api, params=params)
|
| 121 |
+
response.raise_for_status()
|
| 122 |
+
fact_checks = response.json().get("claims", [])
|
| 123 |
+
if fact_checks:
|
| 124 |
+
return {
|
| 125 |
+
"claim": claim,
|
| 126 |
+
"fact_check_result": fact_checks[0].get("claimReview", [])[0].get("textualRating", "Inconnu"),
|
| 127 |
+
"source": fact_checks[0].get("claimReview", [])[0].get("publisher", {}).get("name", "Inconnu")
|
| 128 |
+
}
|
| 129 |
+
else:
|
| 130 |
+
return {"claim": claim, "fact_check_result": "Aucune vérification trouvée"}
|
| 131 |
+
except requests.RequestException as e:
|
| 132 |
+
return {"claim": claim, "error": f"Erreur lors de la vérification des faits : {str(e)}"}
|
| 133 |
+
|
| 134 |
+
def provide_ethical_recommendations(self, content: str) -> Dict[str, Any]:
|
| 135 |
+
prompt = f"Le contenu suivant a été jugé non éthique : '{content}'. Proposez une version alternative qui respecte ces directives éthiques : {self.ethical_guidelines}"
|
| 136 |
+
response = self._query_llm(prompt)
|
| 137 |
+
return {
|
| 138 |
+
"original_content": content,
|
| 139 |
+
"ethical_recommendation": response
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
def toggle_ethical_filter(self) -> Dict[str, Any]:
|
| 143 |
+
self.ethical_filter_active = not self.ethical_filter_active
|
| 144 |
+
status = "activé" if self.ethical_filter_active else "désactivé"
|
| 145 |
+
return {"message": f"Le filtre éthique est maintenant {status}"}
|
| 146 |
+
|
| 147 |
+
def _query_llm(self, prompt: str) -> str:
|
| 148 |
+
headers = {
|
| 149 |
+
"Authorization": f"Bearer {self.llm_api_key}",
|
| 150 |
+
"Content-Type": "application/json"
|
| 151 |
+
}
|
| 152 |
+
data = {
|
| 153 |
+
"model": "gpt-3.5-turbo",
|
| 154 |
+
"messages": [{"role": "user", "content": prompt}]
|
| 155 |
+
}
|
| 156 |
+
try:
|
| 157 |
+
response = requests.post(self.llm_api_url, headers=headers, json=data)
|
| 158 |
+
response.raise_for_status()
|
| 159 |
+
return response.json()['choices'][0]['message']['content']
|
| 160 |
+
except requests.RequestException as e:
|
| 161 |
+
return f"Erreur lors de la requête LLM : {str(e)}"
|
| 162 |
+
|
| 163 |
+
def log_activity(self, activity: str):
|
| 164 |
+
logging.info(activity)
|
| 165 |
+
|
| 166 |
def communicate_with_stellar(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
| 167 |
print(f"{self.name} envoie un message à Stellar: {message}")
|
| 168 |
return {"Statut": "Message reçu", "message": "Stellar a bien reçu le message"}
|
satellites/yorkSat/york.py
CHANGED
|
@@ -2,6 +2,7 @@ import psutil
|
|
| 2 |
import time
|
| 3 |
from typing import Dict, Any, List
|
| 4 |
from satellites.base_satellite import VegapunkSatellite
|
|
|
|
| 5 |
import logging
|
| 6 |
|
| 7 |
role = "Gestion des ressources et maintenance système"
|
|
@@ -19,8 +20,9 @@ class York(VegapunkSatellite):
|
|
| 19 |
"network": 75,
|
| 20 |
}
|
| 21 |
self.maintenance_schedule = {}
|
| 22 |
-
logging.basicConfig(filename='york.log', level=logging.INFO)
|
| 23 |
self.external_apis = {}
|
|
|
|
| 24 |
|
| 25 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 26 |
task_type = task.get("type")
|
|
|
|
| 2 |
import time
|
| 3 |
from typing import Dict, Any, List
|
| 4 |
from satellites.base_satellite import VegapunkSatellite
|
| 5 |
+
from utils.logger import get_logger
|
| 6 |
import logging
|
| 7 |
|
| 8 |
role = "Gestion des ressources et maintenance système"
|
|
|
|
| 20 |
"network": 75,
|
| 21 |
}
|
| 22 |
self.maintenance_schedule = {}
|
| 23 |
+
# logging.basicConfig(filename='york.log', level=logging.INFO)
|
| 24 |
self.external_apis = {}
|
| 25 |
+
from utils.logger import get_logger
|
| 26 |
|
| 27 |
def process_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
|
| 28 |
task_type = task.get("type")
|
tests/shaka_test.py
CHANGED
|
@@ -21,6 +21,17 @@ def test_shaka():
|
|
| 21 |
|
| 22 |
logic_result = shaka.process_task(test_logic)
|
| 23 |
print("Résultat de la tâche de logique:", logic_result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
print("Connexion au Punkrecord")
|
| 26 |
shaka.update_from_punkrecord()
|
|
|
|
| 21 |
|
| 22 |
logic_result = shaka.process_task(test_logic)
|
| 23 |
print("Résultat de la tâche de logique:", logic_result)
|
| 24 |
+
# Ajout de tâches à la file d'attente
|
| 25 |
+
shaka.add_task({"type": "ethical_check",
|
| 26 |
+
"content": "Les gens devraient toujours dire la vérité, même si cela peut blesser quelqu'un."})
|
| 27 |
+
shaka.add_task({"type": "fact_check", "claim": "La Terre est plate."})
|
| 28 |
+
shaka.add_task({"type": "provide_recommendations", "content": "Tous les immigrants devraient être expulsés."})
|
| 29 |
+
shaka.add_task({"type": "toggle_ethical_filter"})
|
| 30 |
+
|
| 31 |
+
# Traitement des tâches
|
| 32 |
+
while task := shaka.get_next_task():
|
| 33 |
+
result = shaka.process_task(task)
|
| 34 |
+
print(f"Résultat de la tâche : {result}")
|
| 35 |
|
| 36 |
print("Connexion au Punkrecord")
|
| 37 |
shaka.update_from_punkrecord()
|