From e57f70544db9e82bab891b28db770ca2c57056ce Mon Sep 17 00:00:00 2001 From: Lithika N Date: Mon, 28 Sep 2026 21:42:14 +0530 Subject: [PATCH 1/5] Day 1: ML basics --- day01_ml_basics.ipynb | 394 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 394 insertions(+) create mode 100644 day01_ml_basics.ipynb diff --git a/day01_ml_basics.ipynb b/day01_ml_basics.ipynb new file mode 100644 index 0000000..c16a0e9 --- /dev/null +++ b/day01_ml_basics.ipynb @@ -0,0 +1,394 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyMjYFHO2l1BsnmcIKbyrL15", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "eevh0EAqqgN_" + }, + "outputs": [], + "source": [ + "# Day 1 - Machine Learning Basics\n", + "## Topics Covered\n", + "#- AI, ML and DL\n", + "#- Machine Learning workflow\n", + "#- Features and Labels\n", + "#- Supervised Learning\n", + "#- Unsupervised Learning\n", + "#- Reinforcement Learning\n", + "#- Training and Testing Data\n", + "#- Iris Dataset Exploration" + ] + }, + { + "cell_type": "code", + "source": [ + "## 1. What is Machine Learning?\n", + "## Machine Learning is a subset of Artificial Intelligence where computers learn patterns from data and use those patterns to make predictions or decisions.\n", + "## 2. What is AI??\n", + "#Artificial Intelligence is a field of computer science that enables machines to perform tasks that normally require human intelligence, such as learning, reasoning, recognizing images, and understanding language.\n", + "#Example: A voice assistant understanding your question.\n", + "## 3. What is DL??\n", + "#Deep Learning is a subset of Machine Learning that uses neural networks with multiple layers to learn complex patterns from large amounts of data.\n", + "#Example: Face recognition.\n", + "##Dataset\n", + "#A dataset is a collection of data used to train, test, or analyze a machine-learning model.\n", + "##Feature\n", + "#A feature is an input variable used by the model to make a prediction.\n", + "##Labels\n", + "#The label or target is the output that the model tries to predict." + ], + "metadata": { + "id": "URebbbh8qxoU" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "## 2. Types of Machine Learning\n", + "### Supervised Learning\n", + "#Learning from labeled data.\n", + "### Unsupervised Learning\n", + "#Finding patterns in unlabeled data.\n", + "### Reinforcement Learning\n", + "#Learning through actions, rewards and penalties." + ], + "metadata": { + "id": "1To2bv0jrj6n" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "## import libraries\n", + "import pandas as pd\n", + "from sklearn.datasets import load_iris\n", + "from sklearn.model_selection import train_test_split" + ], + "metadata": { + "id": "a4O8igC9r4x5" + }, + "execution_count": 2, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "iris = load_iris()\n", + "x=pd.DataFrame(iris.data, columns=iris.feature_names)\n", + "y=pd.Series(iris.target,name=\"target\")\n", + "x.head()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "id": "hB3msxAQs1BX", + "outputId": "7a123d54-f7ad-4a3f-8c65-84b1ad2e929b" + }, + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)\n", + "0 5.1 3.5 1.4 0.2\n", + "1 4.9 3.0 1.4 0.2\n", + "2 4.7 3.2 1.3 0.2\n", + "3 4.6 3.1 1.5 0.2\n", + "4 5.0 3.6 1.4 0.2" + ], + "text/html": [ + "\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "
\n", + "\n", + "\n", + "
\n", + "
\n" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "dataframe", + "variable_name": "x", + "summary": "{\n \"name\": \"x\",\n \"rows\": 150,\n \"fields\": [\n {\n \"column\": \"sepal length (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.8280661279778629,\n \"min\": 4.3,\n \"max\": 7.9,\n \"num_unique_values\": 35,\n \"samples\": [\n 6.2,\n 4.5,\n 5.6\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"sepal width (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.435866284936698,\n \"min\": 2.0,\n \"max\": 4.4,\n \"num_unique_values\": 23,\n \"samples\": [\n 2.3,\n 4.0,\n 3.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"petal length (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.7652982332594667,\n \"min\": 1.0,\n \"max\": 6.9,\n \"num_unique_values\": 43,\n \"samples\": [\n 6.7,\n 3.8,\n 3.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"petal width (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.7622376689603465,\n \"min\": 0.1,\n \"max\": 2.5,\n \"num_unique_values\": 22,\n \"samples\": [\n 0.2,\n 1.2,\n 1.3\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" + } + }, + "metadata": {}, + "execution_count": 3 + } + ] + }, + { + "cell_type": "code", + "source": [ + "# check dataset size\n", + "print(\"Number of rows:\",x.shape[0])\n", + "print(\"number of features:\",x.shape[1])" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "7mH0Qoe3vBzN", + "outputId": "f5096cec-49ed-42c6-f4e4-521638695181" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Number of rows: 150\n", + "number of features: 4\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "print(\"Features\")\n", + "print(x.columns)\n", + "print(\"Null Values\")\n", + "print(x.isnull().sum())\n", + "print(y.head())\n", + "print(\"\\n Target Values\")\n", + "print(y.unique())" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ZmNyTMCIved4", + "outputId": "ccce77e6-c2b9-40a6-d5c6-0d05ba5e08d5" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Features\n", + "Index(['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)',\n", + " 'petal width (cm)'],\n", + " dtype='object')\n", + "Null Values\n", + "sepal length (cm) 0\n", + "sepal width (cm) 0\n", + "petal length (cm) 0\n", + "petal width (cm) 0\n", + "dtype: int64\n", + "0 0\n", + "1 0\n", + "2 0\n", + "3 0\n", + "4 0\n", + "Name: target, dtype: int64\n", + "\n", + " Target Values\n", + "[0 1 2]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "# train and test and split\n", + "X_train, X_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=42)\n", + "print(\"Training data\",X_train.shape)\n", + "print(\"Testing data\",X_test.shape)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "EdBvQe3uwohf", + "outputId": "d4ad42cb-e7e3-495e-aead-baf7121b67f9" + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Training data (120, 4)\n", + "Testing data (30, 4)\n" + ] + } + ] + } + ] +} \ No newline at end of file From b3c98714000efd908020671e7b4c597327533ee8 Mon Sep 17 00:00:00 2001 From: Lithika N Date: Mon, 28 Sep 2026 21:51:32 +0530 Subject: [PATCH 2/5] Delete day01_ml_basics.ipynb --- day01_ml_basics.ipynb | 394 ------------------------------------------ 1 file changed, 394 deletions(-) delete mode 100644 day01_ml_basics.ipynb diff --git a/day01_ml_basics.ipynb b/day01_ml_basics.ipynb deleted file mode 100644 index c16a0e9..0000000 --- a/day01_ml_basics.ipynb +++ /dev/null @@ -1,394 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [], - "authorship_tag": "ABX9TyMjYFHO2l1BsnmcIKbyrL15", - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "eevh0EAqqgN_" - }, - "outputs": [], - "source": [ - "# Day 1 - Machine Learning Basics\n", - "## Topics Covered\n", - "#- AI, ML and DL\n", - "#- Machine Learning workflow\n", - "#- Features and Labels\n", - "#- Supervised Learning\n", - "#- Unsupervised Learning\n", - "#- Reinforcement Learning\n", - "#- Training and Testing Data\n", - "#- Iris Dataset Exploration" - ] - }, - { - "cell_type": "code", - "source": [ - "## 1. What is Machine Learning?\n", - "## Machine Learning is a subset of Artificial Intelligence where computers learn patterns from data and use those patterns to make predictions or decisions.\n", - "## 2. What is AI??\n", - "#Artificial Intelligence is a field of computer science that enables machines to perform tasks that normally require human intelligence, such as learning, reasoning, recognizing images, and understanding language.\n", - "#Example: A voice assistant understanding your question.\n", - "## 3. What is DL??\n", - "#Deep Learning is a subset of Machine Learning that uses neural networks with multiple layers to learn complex patterns from large amounts of data.\n", - "#Example: Face recognition.\n", - "##Dataset\n", - "#A dataset is a collection of data used to train, test, or analyze a machine-learning model.\n", - "##Feature\n", - "#A feature is an input variable used by the model to make a prediction.\n", - "##Labels\n", - "#The label or target is the output that the model tries to predict." - ], - "metadata": { - "id": "URebbbh8qxoU" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "## 2. Types of Machine Learning\n", - "### Supervised Learning\n", - "#Learning from labeled data.\n", - "### Unsupervised Learning\n", - "#Finding patterns in unlabeled data.\n", - "### Reinforcement Learning\n", - "#Learning through actions, rewards and penalties." - ], - "metadata": { - "id": "1To2bv0jrj6n" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "## import libraries\n", - "import pandas as pd\n", - "from sklearn.datasets import load_iris\n", - "from sklearn.model_selection import train_test_split" - ], - "metadata": { - "id": "a4O8igC9r4x5" - }, - "execution_count": 2, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "iris = load_iris()\n", - "x=pd.DataFrame(iris.data, columns=iris.feature_names)\n", - "y=pd.Series(iris.target,name=\"target\")\n", - "x.head()" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 206 - }, - "id": "hB3msxAQs1BX", - "outputId": "7a123d54-f7ad-4a3f-8c65-84b1ad2e929b" - }, - "execution_count": 3, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - " sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)\n", - "0 5.1 3.5 1.4 0.2\n", - "1 4.9 3.0 1.4 0.2\n", - "2 4.7 3.2 1.3 0.2\n", - "3 4.6 3.1 1.5 0.2\n", - "4 5.0 3.6 1.4 0.2" - ], - "text/html": [ - "\n", - "
\n", - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
sepal length (cm)sepal width (cm)petal length (cm)petal width (cm)
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
\n", - "
\n", - "
\n", - "\n", - "
\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "
\n", - "\n", - "\n", - "
\n", - "
\n" - ], - "application/vnd.google.colaboratory.intrinsic+json": { - "type": "dataframe", - "variable_name": "x", - "summary": "{\n \"name\": \"x\",\n \"rows\": 150,\n \"fields\": [\n {\n \"column\": \"sepal length (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.8280661279778629,\n \"min\": 4.3,\n \"max\": 7.9,\n \"num_unique_values\": 35,\n \"samples\": [\n 6.2,\n 4.5,\n 5.6\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"sepal width (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.435866284936698,\n \"min\": 2.0,\n \"max\": 4.4,\n \"num_unique_values\": 23,\n \"samples\": [\n 2.3,\n 4.0,\n 3.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"petal length (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.7652982332594667,\n \"min\": 1.0,\n \"max\": 6.9,\n \"num_unique_values\": 43,\n \"samples\": [\n 6.7,\n 3.8,\n 3.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"petal width (cm)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.7622376689603465,\n \"min\": 0.1,\n \"max\": 2.5,\n \"num_unique_values\": 22,\n \"samples\": [\n 0.2,\n 1.2,\n 1.3\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" - } - }, - "metadata": {}, - "execution_count": 3 - } - ] - }, - { - "cell_type": "code", - "source": [ - "# check dataset size\n", - "print(\"Number of rows:\",x.shape[0])\n", - "print(\"number of features:\",x.shape[1])" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "7mH0Qoe3vBzN", - "outputId": "f5096cec-49ed-42c6-f4e4-521638695181" - }, - "execution_count": 4, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Number of rows: 150\n", - "number of features: 4\n" - ] - } - ] - }, - { - "cell_type": "code", - "source": [ - "print(\"Features\")\n", - "print(x.columns)\n", - "print(\"Null Values\")\n", - "print(x.isnull().sum())\n", - "print(y.head())\n", - "print(\"\\n Target Values\")\n", - "print(y.unique())" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "ZmNyTMCIved4", - "outputId": "ccce77e6-c2b9-40a6-d5c6-0d05ba5e08d5" - }, - "execution_count": 7, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Features\n", - "Index(['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)',\n", - " 'petal width (cm)'],\n", - " dtype='object')\n", - "Null Values\n", - "sepal length (cm) 0\n", - "sepal width (cm) 0\n", - "petal length (cm) 0\n", - "petal width (cm) 0\n", - "dtype: int64\n", - "0 0\n", - "1 0\n", - "2 0\n", - "3 0\n", - "4 0\n", - "Name: target, dtype: int64\n", - "\n", - " Target Values\n", - "[0 1 2]\n" - ] - } - ] - }, - { - "cell_type": "code", - "source": [ - "# train and test and split\n", - "X_train, X_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=42)\n", - "print(\"Training data\",X_train.shape)\n", - "print(\"Testing data\",X_test.shape)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "EdBvQe3uwohf", - "outputId": "d4ad42cb-e7e3-495e-aead-baf7121b67f9" - }, - "execution_count": 8, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Training data (120, 4)\n", - "Testing data (30, 4)\n" - ] - } - ] - } - ] -} \ No newline at end of file From 750191d989defb1da4411a542206d4a81735ce2c Mon Sep 17 00:00:00 2001 From: lithikaneelakandan56-ctrl Date: Sat, 26 Sep 2026 17:21:58 +0530 Subject: [PATCH 3/5] feat: add conversation history summarization --- src/core/assistant.py | 18 +++++++++++++++++- src/core/generate_prompt.py | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/assistant.py b/src/core/assistant.py index f24902b..0a59c5e 100644 --- a/src/core/assistant.py +++ b/src/core/assistant.py @@ -3,6 +3,7 @@ import sqlite3 from langchain_core.messages import HumanMessage +from langchain_core.messages.utils import count_tokens_approximately from langgraph.checkpoint.sqlite import SqliteSaver from langgraph.prebuilt import create_react_agent from langgraph.prebuilt.chat_agent_executor import AgentState @@ -12,6 +13,7 @@ from src.utils.logger import get_logger from .generate_prompt import prompt +from .summarizer import summarize_conversation from .tools import get_all_tools # Import the function to get all tools logger = get_logger() @@ -39,6 +41,21 @@ class State(AgentState): def call_agent(message): config_dict = {"configurable": {"thread_id": config.THREAD_ID}} + state = agent.get_state(config_dict) + messages = state.values.get("messages", []) + token_count = count_tokens_approximately(messages) + + if token_count > config.MAX_TOKENS_HISTORY: + summary_result = summarize_conversation( + { + "messages": messages, + "summary": state.values.get("summary", ""), + } + ) + agent.update_state( + config_dict, + summary_result, + ) response = agent.invoke( {"messages": [message]}, config_dict, @@ -85,7 +102,6 @@ def call_agent(message): if __name__ == "__main__": # Run the agent message = HumanMessage(content="Hey, how are you doing?") - config = {"configurable": {"thread_id": "1"}} response = call_agent(message) diff --git a/src/core/generate_prompt.py b/src/core/generate_prompt.py index dbb1ee2..ad471d3 100644 --- a/src/core/generate_prompt.py +++ b/src/core/generate_prompt.py @@ -45,6 +45,9 @@ def prompt(state: AgentState, config: RunnableConfig) -> list[Any]: owner_name = app_config.OWNER_NAME user_profile = _build_user_profile() + previous_conversation = ( + f"\n### 📜 Previous Conversation:\n{summary}" if summary else "" + ) system_msg = f""" You are **{assistant_name}**, a witty, intelligent desktop AI assistant running locally on {owner_name}'s Linux machine. @@ -74,7 +77,7 @@ def prompt(state: AgentState, config: RunnableConfig) -> list[Any]: {user_profile} -{f"\n### 📜 Previous Conversation:\n{summary}" if summary else ""} +{previous_conversation} """.strip() return [SystemMessage(content=system_msg)] + state["messages"] From f8598f6f8718da3dab7e2c8b817bbb12cb97ddaf Mon Sep 17 00:00:00 2001 From: lithikaneelakandan56-ctrl Date: Wed, 7 Oct 2026 12:00:44 +0530 Subject: [PATCH 4/5] chore: fix existing ruff lint errors --- main.py | 2 +- setup/record_owner_voice.py | 2 +- src/audio/audio_processor.py | 2 +- src/audio/listener.py | 2 +- src/audio/ttsplayer.py | 20 +++++++++++++++----- src/audio/vad.py | 2 +- src/core/generate_prompt.py | 2 +- src/core/tools.py | 8 ++++---- src/ui/overlay.py | 2 +- 9 files changed, 26 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index ddf22f9..447f2d8 100644 --- a/main.py +++ b/main.py @@ -67,7 +67,7 @@ def process_query(self, query: str): overlay.put_message("response", response) overlay.put_message("status", "Active", "green") self.speech.speak(response) - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"Error processing query: {e}") overlay.put_message("status", "Error occurred", "red") self.speech.speak("Sorry, an error occurred while processing your request.") diff --git a/setup/record_owner_voice.py b/setup/record_owner_voice.py index fcd4867..4d7e80b 100644 --- a/setup/record_owner_voice.py +++ b/setup/record_owner_voice.py @@ -47,7 +47,7 @@ def main(): print() # Newline after the countdown logger.info(f"Voice profile saved to {OWNER_FILE}") print(f"✅ Voice profile saved to {OWNER_FILE}") - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"Error during recording: {e}") sys.exit(1) diff --git a/src/audio/audio_processor.py b/src/audio/audio_processor.py index 3bc53c1..0b0b357 100644 --- a/src/audio/audio_processor.py +++ b/src/audio/audio_processor.py @@ -39,7 +39,7 @@ def process_audio(self, audio_data): logger.info(f"Transcription: {transcription}") return transcription - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"Error processing audio: {e}") return None finally: diff --git a/src/audio/listener.py b/src/audio/listener.py index 46844bd..aadc2e4 100644 --- a/src/audio/listener.py +++ b/src/audio/listener.py @@ -171,7 +171,7 @@ def listen(self, func): future = executor.submit(func, audio_data) try: future.result(timeout=config.AUDIO_PROCESSING_TIMEOUT) - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"Error processing audio: {e}") logger.info("👋 Stopped listening") diff --git a/src/audio/ttsplayer.py b/src/audio/ttsplayer.py index 7c276a3..7420621 100644 --- a/src/audio/ttsplayer.py +++ b/src/audio/ttsplayer.py @@ -14,6 +14,11 @@ logger = get_logger() +def _write_audio_chunk(filename, data): + with open(filename, "ab") as f: + f.write(data) + + class TTSPlayer(threading.Thread): def __init__(self): super().__init__(daemon=True) @@ -36,11 +41,16 @@ def run(self): async def synthesize_to_file(self, text: str, filename: str): try: - communicate = edge_tts.Communicate(text=text, voice=config.TTS_VOICE, rate=config.TTS_RATE) - with open(filename, "wb") as f: - async for chunk in communicate.stream(): - if chunk["type"] == "audio": - f.write(chunk["data"]) + communicate = edge_tts.Communicate( + text=text, voice=config.TTS_VOICE, rate=config.TTS_RATE + ) + async for chunk in communicate.stream(): + if chunk["type"] == "audio": + await asyncio.to_thread( + _write_audio_chunk, + filename, + chunk["data"], + ) except Exception as e: logger.error(f"Edge TTS error: {e}") raise diff --git a/src/audio/vad.py b/src/audio/vad.py index 80ad1cd..f5899a6 100644 --- a/src/audio/vad.py +++ b/src/audio/vad.py @@ -182,7 +182,7 @@ def listen(self, func): future = executor.submit(func, audio_data) try: future.result(timeout=config.AUDIO_PROCESSING_TIMEOUT) - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"Error processing audio: {e}") logger.info("👋 Stopped listening") diff --git a/src/core/generate_prompt.py b/src/core/generate_prompt.py index ad471d3..2fb88cf 100644 --- a/src/core/generate_prompt.py +++ b/src/core/generate_prompt.py @@ -46,7 +46,7 @@ def prompt(state: AgentState, config: RunnableConfig) -> list[Any]: user_profile = _build_user_profile() previous_conversation = ( - f"\n### 📜 Previous Conversation:\n{summary}" if summary else "" + f"\n### 📜 Previous Conversation:\n{summary}" if summary else "" ) system_msg = f""" You are **{assistant_name}**, a witty, intelligent desktop AI assistant running locally on {owner_name}'s Linux machine. diff --git a/src/core/tools.py b/src/core/tools.py index 6bf917d..d2be873 100644 --- a/src/core/tools.py +++ b/src/core/tools.py @@ -42,7 +42,7 @@ def wrapper(*args, **kwargs): result = func(*args, **kwargs) logger.debug(f"[{func.__name__}] Result: {result}") return result - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"[{func.__name__}] Error: {e}") return f"Error in {func.__name__}: {e}" @@ -89,7 +89,7 @@ def open_google_chrome(url: str | None, new_window: bool = False) -> str: try: subprocess.Popen(command, shell=True) return f"Google Chrome opened with URL: {url}" - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"[open_google_chrome] Error: {e}") return f"Error opening Google Chrome: {e}" @@ -103,7 +103,7 @@ def open_whatsapp_web() -> str: try: subprocess.Popen(["gtk-launch", "chrome-hnpfjngllnobngcgfapefoaidbinmjnm-Default.desktop"]) return "WhatsApp Web launched." - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"[open_whatsapp_web] Error: {e}") return f"Error: {e}" @@ -179,7 +179,7 @@ def web_search( try: results = search_tool.invoke({"query": query}) return str(results) - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"[web_search] Error: {e}") return f"Error during web search: {e}" diff --git a/src/ui/overlay.py b/src/ui/overlay.py index 99a4f9c..85393bc 100644 --- a/src/ui/overlay.py +++ b/src/ui/overlay.py @@ -212,7 +212,7 @@ def process_messages(self): text = args[0] self.add_log_message(f"Jasper: {text}", "#00FF00") # Green - except Exception as e: + except Exception as e: # noqa: BLE001 logger.error(f"Error processing message: {e}") def start(self): From b5db18767c1cdb6d58a9b47bb1ba4c8628b96af5 Mon Sep 17 00:00:00 2001 From: lithikaneelakandan56-ctrl Date: Wed, 7 Oct 2026 23:33:44 +0530 Subject: [PATCH 5/5] chore: apply ruff formatting fixes --- main.py | 2 +- src/audio/audio_processor.py | 2 +- src/audio/listener.py | 2 +- src/audio/ttsplayer.py | 4 +--- src/audio/vad.py | 2 +- src/core/generate_prompt.py | 4 +--- src/core/tools.py | 8 ++++---- src/ui/overlay.py | 2 +- 8 files changed, 11 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 447f2d8..ddf22f9 100644 --- a/main.py +++ b/main.py @@ -67,7 +67,7 @@ def process_query(self, query: str): overlay.put_message("response", response) overlay.put_message("status", "Active", "green") self.speech.speak(response) - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"Error processing query: {e}") overlay.put_message("status", "Error occurred", "red") self.speech.speak("Sorry, an error occurred while processing your request.") diff --git a/src/audio/audio_processor.py b/src/audio/audio_processor.py index 0b0b357..3bc53c1 100644 --- a/src/audio/audio_processor.py +++ b/src/audio/audio_processor.py @@ -39,7 +39,7 @@ def process_audio(self, audio_data): logger.info(f"Transcription: {transcription}") return transcription - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"Error processing audio: {e}") return None finally: diff --git a/src/audio/listener.py b/src/audio/listener.py index aadc2e4..46844bd 100644 --- a/src/audio/listener.py +++ b/src/audio/listener.py @@ -171,7 +171,7 @@ def listen(self, func): future = executor.submit(func, audio_data) try: future.result(timeout=config.AUDIO_PROCESSING_TIMEOUT) - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"Error processing audio: {e}") logger.info("👋 Stopped listening") diff --git a/src/audio/ttsplayer.py b/src/audio/ttsplayer.py index 7420621..313793f 100644 --- a/src/audio/ttsplayer.py +++ b/src/audio/ttsplayer.py @@ -41,9 +41,7 @@ def run(self): async def synthesize_to_file(self, text: str, filename: str): try: - communicate = edge_tts.Communicate( - text=text, voice=config.TTS_VOICE, rate=config.TTS_RATE - ) + communicate = edge_tts.Communicate(text=text, voice=config.TTS_VOICE, rate=config.TTS_RATE) async for chunk in communicate.stream(): if chunk["type"] == "audio": await asyncio.to_thread( diff --git a/src/audio/vad.py b/src/audio/vad.py index f5899a6..80ad1cd 100644 --- a/src/audio/vad.py +++ b/src/audio/vad.py @@ -182,7 +182,7 @@ def listen(self, func): future = executor.submit(func, audio_data) try: future.result(timeout=config.AUDIO_PROCESSING_TIMEOUT) - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"Error processing audio: {e}") logger.info("👋 Stopped listening") diff --git a/src/core/generate_prompt.py b/src/core/generate_prompt.py index 2fb88cf..83514d9 100644 --- a/src/core/generate_prompt.py +++ b/src/core/generate_prompt.py @@ -45,9 +45,7 @@ def prompt(state: AgentState, config: RunnableConfig) -> list[Any]: owner_name = app_config.OWNER_NAME user_profile = _build_user_profile() - previous_conversation = ( - f"\n### 📜 Previous Conversation:\n{summary}" if summary else "" - ) + previous_conversation = f"\n### 📜 Previous Conversation:\n{summary}" if summary else "" system_msg = f""" You are **{assistant_name}**, a witty, intelligent desktop AI assistant running locally on {owner_name}'s Linux machine. diff --git a/src/core/tools.py b/src/core/tools.py index d2be873..6bf917d 100644 --- a/src/core/tools.py +++ b/src/core/tools.py @@ -42,7 +42,7 @@ def wrapper(*args, **kwargs): result = func(*args, **kwargs) logger.debug(f"[{func.__name__}] Result: {result}") return result - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"[{func.__name__}] Error: {e}") return f"Error in {func.__name__}: {e}" @@ -89,7 +89,7 @@ def open_google_chrome(url: str | None, new_window: bool = False) -> str: try: subprocess.Popen(command, shell=True) return f"Google Chrome opened with URL: {url}" - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"[open_google_chrome] Error: {e}") return f"Error opening Google Chrome: {e}" @@ -103,7 +103,7 @@ def open_whatsapp_web() -> str: try: subprocess.Popen(["gtk-launch", "chrome-hnpfjngllnobngcgfapefoaidbinmjnm-Default.desktop"]) return "WhatsApp Web launched." - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"[open_whatsapp_web] Error: {e}") return f"Error: {e}" @@ -179,7 +179,7 @@ def web_search( try: results = search_tool.invoke({"query": query}) return str(results) - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"[web_search] Error: {e}") return f"Error during web search: {e}" diff --git a/src/ui/overlay.py b/src/ui/overlay.py index 85393bc..99a4f9c 100644 --- a/src/ui/overlay.py +++ b/src/ui/overlay.py @@ -212,7 +212,7 @@ def process_messages(self): text = args[0] self.add_log_message(f"Jasper: {text}", "#00FF00") # Green - except Exception as e: # noqa: BLE001 + except Exception as e: logger.error(f"Error processing message: {e}") def start(self):