various updates
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
import json
|
||||
import os
|
||||
import smtplib
|
||||
import ssl
|
||||
import subprocess
|
||||
from email.message import EmailMessage
|
||||
from pathlib import Path
|
||||
from typing import Iterable, TypedDict, cast
|
||||
|
||||
import requests
|
||||
from dotenv import dotenv_values, load_dotenv
|
||||
from openai import OpenAI
|
||||
from openai.types.chat import ChatCompletionMessageParam, ChatCompletionToolUnionParam
|
||||
|
||||
|
||||
class AWS_SES_DOTENV(TypedDict):
|
||||
USER: str
|
||||
PASSWORD: str
|
||||
ENDPOINT: str
|
||||
TLS_PORT: str
|
||||
SENDER: str
|
||||
RECEIVER: str
|
||||
class NTFY_DOTENV(TypedDict):
|
||||
TOKEN: str
|
||||
|
||||
|
||||
class ToolCallController:
|
||||
@@ -209,39 +204,30 @@ def smartctl(device_path: str) -> str:
|
||||
return output
|
||||
|
||||
|
||||
def load_ses_creds() -> AWS_SES_DOTENV:
|
||||
def load_ntfy_creds() -> NTFY_DOTENV:
|
||||
ses_dotenv_location = Path(os.getenv("HOME", "/root"), ".env/aws_ses")
|
||||
print(f"Loading env from {ses_dotenv_location}")
|
||||
raw_values = dotenv_values(ses_dotenv_location)
|
||||
if raw_values:
|
||||
aws_ses_config = cast(AWS_SES_DOTENV, raw_values)
|
||||
ntfy_config = cast(NTFY_DOTENV, raw_values)
|
||||
# print(f"AWS SES Credentials loaded: {aws_ses_config}")
|
||||
return aws_ses_config
|
||||
print("No email credentials supplied. Exiting.")
|
||||
return ntfy_config
|
||||
print("No ntfy credentials supplied. Exiting.")
|
||||
exit(1)
|
||||
|
||||
|
||||
def alert_user(message: str) -> str:
|
||||
ses_config = load_ses_creds()
|
||||
port = int(ses_config["TLS_PORT"])
|
||||
user = ses_config["USER"]
|
||||
password = ses_config["PASSWORD"]
|
||||
sender = ses_config["SENDER"]
|
||||
receiver = ses_config["RECEIVER"]
|
||||
ntfy_creds = load_ntfy_creds()
|
||||
|
||||
# Create a secure SSL context
|
||||
context = ssl.create_default_context()
|
||||
|
||||
msg = EmailMessage()
|
||||
msg["Subject"] = "Agent Disk Report"
|
||||
msg["From"] = sender
|
||||
msg["To"] = receiver
|
||||
msg.set_content(message)
|
||||
|
||||
with smtplib.SMTP_SSL(ses_config["ENDPOINT"], port, context=context) as server:
|
||||
server.login(user, password)
|
||||
result = server.send_message(msg)
|
||||
print(result)
|
||||
requests.post(
|
||||
"https://ntfy.reeseapps.com/servers",
|
||||
data=message,
|
||||
headers={
|
||||
"Authorization": f"Bearer {ntfy_creds['TOKEN']}",
|
||||
"Title": "Agent Disk Report",
|
||||
"Priority": "default",
|
||||
},
|
||||
)
|
||||
|
||||
return "Sent."
|
||||
|
||||
@@ -322,13 +308,14 @@ def run_conversation(user_message: str, max_tool_calls=10):
|
||||
if __name__ == "__main__":
|
||||
load_dotenv()
|
||||
api_key = os.getenv("OPENAI_API_KEY", "")
|
||||
client = OpenAI(base_url="https://llama-think.reeselink.com", api_key=api_key)
|
||||
client = OpenAI(base_url="https://aipi.reeseapps.com", api_key=api_key)
|
||||
# Example usage
|
||||
print(
|
||||
run_conversation(
|
||||
"Check the btrfs pools on this system. Take the appropriate action if any pools aren't "
|
||||
"healthy. Don't run scrubs unless necessary. Also check the btrfs pool space and report "
|
||||
"if any are getting full. At the very end of performing your checks send a single, "
|
||||
"concise message to the user explaining what you did and what concerns you might have."
|
||||
"concise message to the user via the alert_user tool explaining what you did and "
|
||||
"what concerns you might have."
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user