diff --git a/example_env.txt b/example_env.txt index 6345784..75dd7d1 100644 --- a/example_env.txt +++ b/example_env.txt @@ -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' diff --git a/main.py b/main.py index df58da7..c594fd0 100644 --- a/main.py +++ b/main.py @@ -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() diff --git a/modules/adapter.py b/modules/adapter.py index bede04c..b1d1c48 100644 --- a/modules/adapter.py +++ b/modules/adapter.py @@ -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 diff --git a/modules/agent.py b/modules/agent.py index 2226521..e3dfb13 100644 --- a/modules/agent.py +++ b/modules/agent.py @@ -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) diff --git a/modules/spotify.py b/modules/spotify.py index 46fea8d..269803b 100644 --- a/modules/spotify.py +++ b/modules/spotify.py @@ -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"), diff --git a/requirements.txt b/requirements_linux.txt similarity index 100% rename from requirements.txt rename to requirements_linux.txt diff --git a/requirements_windows.txt b/requirements_windows.txt new file mode 100644 index 0000000..d2a6f82 --- /dev/null +++ b/requirements_windows.txt @@ -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 \ No newline at end of file