refactor with OS detection

now does os detection and does not try to invoke windows specific tools on non-windows systems. will need to create more than one requirement.txt folder

also added variable env value for character prompts
This commit is contained in:
maglore9900 2024-10-02 13:19:56 -04:00
parent 1bb256ce47
commit b57734309e
7 changed files with 69 additions and 22 deletions

View File

@ -3,8 +3,8 @@ OPENAI_API_KEY=''
LLM_TYPE='openai'
OPENAI_MODEL='gpt-4o-mini'
#OLLAMA_MODEL will take any model you can load in ollama
OLLAMA_MODEL='llama'
OLLAMA_URL='http://10.0.0.231:11434'
OLLAMA_MODEL='gemma2'
OLLAMA_URL='http://localhost:11434'
spotify_client_id = ''
spotify_client_secret = ''
spotify_redirect_uri = 'http://localhost:8888/callback'

20
main.py
View File

@ -1,13 +1,31 @@
from modules import agent
import asyncio
import environ
import os
env = environ.Env()
environ.Env.read_env()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
graph = agent.Agent()
if os.name == "nt":
print("windows")
op = "windows"
elif os.name == "posix":
# Further check to differentiate between Linux and macOS
if 'linux' in os.uname().sysname.lower():
print("linux")
op = "linux"
elif 'darwin' in os.uname().sysname.lower():
op = "macos"
else:
exit("Unknown operating system.")
else:
exit("Unknown operating system.")
graph = agent.Agent(env,op)
while True:
text = graph.spk.listen()

View File

@ -1,11 +1,11 @@
import environ
# import environ
from langchain_core.prompts import ChatPromptTemplate
env = environ.Env()
environ.Env.read_env()
# env = environ.Env()
# environ.Env.read_env()
class Adapter:
def __init__(self):
def __init__(self, env):
self.llm_text = env("LLM_TYPE")
if self.llm_text.lower() == "openai":
from langchain_openai import OpenAIEmbeddings, OpenAI

View File

@ -11,27 +11,27 @@ import subprocess
class Agent:
def __init__(self):
self.ad = adapter.Adapter()
self.sp = spotify.Spotify()
def __init__(self, env, op):
self.ad = adapter.Adapter(env)
self.sp = spotify.Spotify(env)
self.ap = app_launcher.AppLauncher()
self.wf = windows_focus.WindowFocusManager()
self.llm = self.ad.llm_chat
self.spk = speak.Speak(model="whisper")
self.prompt = hub.pull("hwchase17/openai-functions-agent")
# self.char_prompt = prompts.brain
self.char_prompt = prompts.max
self.char = env("CHARACTER").lower()
self.char_prompt = getattr(prompts, self.char, "You are a helpful assistant. User Query: {query}")
tools = [self.set_timer, self.spotify, self.journal_mode]
if op == "windows":
tools.append(self.app_launcher)
tools.append(self.windows_focus)
self.query_agent_runnable = create_openai_tools_agent(
llm=self.llm,
tools=[
self.spotify,
self.app_launcher,
self.windows_focus,
self.journal_mode,
self.set_timer,
],
tools=tools,
prompt=self.prompt,
)
self.graph = StateGraph(self.AgentState)

View File

@ -5,8 +5,8 @@ from requests.exceptions import ConnectionError, HTTPError
import time
import functools
env = environ.Env()
environ.Env.read_env()
# env = environ.Env()
# environ.Env.read_env()
def handle_spotify_errors_and_device(func):
@functools.wraps(func)
@ -35,7 +35,13 @@ def handle_spotify_errors_and_device(func):
return wrapper
class Spotify:
def __init__(self):
def __init__(self, env):
spotify_client_id = env("spotify_client_id", default=None)
spotify_client_secret = env("spotify_client_secret", default=None)
spotify_redirect_uri = env("spotify_redirect_uri", default=None)
if not (spotify_client_id and spotify_client_secret and spotify_redirect_uri):
print("Spotify environment variables missing. Skipping Spotify initialization.")
return
self.auth_manager = SpotifyOAuth(
client_id=env("spotify_client_id"),
client_secret=env("spotify_client_secret"),

23
requirements_windows.txt Normal file
View File

@ -0,0 +1,23 @@
speechrecognition
pyaudio
pyttsx3
python-environ
openai
langgraph==0.0.37
langchainhub==0.1.15
langchain_experimental
sentence_transformers
langchain_openai
faiss-cpu
pypdf
langsmith
unstructured
python-docx
python-vlc
plyer
noisereduce
faster-whisper
tk
pillow
pydub
spotipy