最近,我一直在與狂看《火影忍者》的癮作鬥爭。雖然這很令人愉快,但它絕對不能幫助我實現股東價值。 😄

那麼,為什麼不建立一個人工智慧個人助理來監控我的螢幕並讓我知道我是否做了不該做的事情,例如看動漫? 😅

考慮到過去一年人工智慧的快速發展,我決定使用多模態語言模型來監控我的螢幕,並讓我知道何時我在非生產性活動上花費了太多時間。

所以,這就是我的做法。

  • 配置 OpenAI GPT-4o,多模態 AI 模型。

  • 使用 Composio 的螢幕分析器工具來監控螢幕。

  • 定期將螢幕截圖傳遞到 GPT。

  • 將 GPT 的訊息呈現為系統中的通知。

高效 GIF

在本文中,我還將解釋如何使用 OpenAI 和 Composio 建立您的個人 AI 朋友。


Composio - 您的 AI 代理工具平台

Composio 是一個開源平台,可為您的 AI 代理提供工具和整合。它可讓您透過程式碼解釋器、RAG、嵌入等整合工具以及 GitHub、Slack、Jira 等整合來擴展 AI 代理的能力和多功能性。

傢伙掙扎 gif

請幫我們加一顆星。 🥹

這將幫助我們建立更多這樣的文章💖

{% cta https://dub.composio.dev/aifrnd %}為 Composio.dev 儲存庫加註星標 ⭐{% endcta %}


建立 AI Friend 的先決條件

要成功完成該專案,您將需要以下內容。

  • OpenAI SDK 和 API 金鑰:與 LLM 互動。

  • Composio :用於存取影像分析工具。

  • PyAutoGUI :自動化螢幕上的互動。

  • Osascript :執行 AppleScript 命令來控制 macOS 應用程式。

那麼,讓我們開始吧。


讓我們開始吧🔥

首先建立一個 Python 虛擬環境。

python -m venv ai-friend
cd ai-friend
source bin/activate

現在,安裝以下相依性。

pip install composio-core
pip install composio-openai openai
pip install pyautogui

接下來,建立.env檔案並為 OpenAI API 金鑰新增環境變數。

OPENAI_API_KEY=your API key

設定構圖

您可以使用 CLI 輕鬆設定 Composio。

首先,透過執行以下命令登入您的帳戶。

composio login

完成登入流程以繼續進行。

現在,更新應用程式。

composio apps update

現在,您已準備好進入編碼部分。


建立人工智慧朋友

現在您已經設定了環境,讓我們開始編碼部分。

首先,導入函式庫並初始化工具集。

import dotenv
from openai import OpenAI

from composio_openai import App, ComposioToolSet
from composio.utils.logging import get as get_logger

logger = get_logger(__name__)

# Load environment variables from .env
dotenv.load_dotenv()

# Initialize tools.
openai_client = OpenAI()
composio_toolset = ComposioToolSet()

# Retrieve actions
actions = composio_toolset.get_tools(apps=[App.SYSTEMTOOLS, App.IMAGEANALYSERTOOL])

所以,在上面的程式碼區塊中,

  • 我們導入了所有必需的庫和模組。

  • 載入.env檔案中定義的變數。

  • 建立了 OpenAI() 和 ComposioToolSet 的實例。

  • SYSTEMTOOLSIMAGEANALYSERTOO檢索操作。

所以,這就是這些工具的作用。

  • SYSTEM TOOLS :系統工具有兩個操作:推播通知和螢幕擷取。

  • IMAGEANALYSERTOOL :此工具只有一個操作:使用 GPT-4o 和 Claude Sonnet 等多模式 LLM 分析影像。

如果您想檢查程式碼及其工作原理,請檢查系統工具影像分析器工具的程式碼檔案。

注意:Composio 中的操作是代理可以執行的任務,例如點擊螢幕截圖、發送通知或發送郵件。

設定 OpenAI 助手

現在,為代理定義清晰簡潔的提示。這對於代理績效至關重要。您可以根據您的要求變更提示。

assistant_instruction = (
    """You are an intelligent and proactive personal productivity assistant.
    Your primary tasks are:
    1. Regularly capture and analyze screenshots of the user's screen.
    2. Monitor user activity and provide timely, helpful interventions.

    Specific responsibilities:
    - Every few seconds, take a screenshot and analyze its content.
    - Compare recent screenshots to identify potential issues or patterns.
    - If you detect that the user is facing a technical or workflow problem:
        - Notify them with concise, actionable solutions.
        - Prioritize non-intrusive suggestions that can be quickly implemented.
    - If you notice extended use of potentially distracting websites or applications (e.g., social media, video streaming):
        - Gently remind the user about their productivity goals.
        - Suggest a brief break or a transition to a more focused task.
    - Maintain a balance between being helpful and not overly disruptive.
    - Tailor your interventions based on the time of day and the user's apparent work patterns.

    Operational instructions:
    - You will receive a 'CHECK' message at regular intervals. Upon receiving this:
        1. Take a screenshot using the screenshot tool.
        2. Then, analyse that screenshot using the image analyser tool.
        3. Then, check if the user uses distracting websites or applications.
        4. If they are, remind them to do something productive.
        5. If they are not, check if the user is facing a technical or workflow problem based on previous history.
        6. If they are, notify them with concise, actionable solutions.
        7. Try to maintain a history of the user's activity and notify them if they are doing something wrong.

    Remember: Your goal is to enhance productivity while respecting the user's autonomy and work style."""
)
assistant = openai_client.beta.assistants.create(
    name="Personal Productivity Assistant",
    instructions=assistant_instruction,
    model="gpt-4-turbo",
    tools=actions,  # type: ignore
)
# create a thread
thread = openai_client.beta.threads.create()
print("Thread ID: ", thread.id)
print("Assistant ID: ", assistant.id)

在上面的程式碼區塊中,

  • 提供詳細的輔助說明。

  • 使用先前定義的指令、模型名稱和先前定義的操作建立了一個新的助手實例。

  • 最後,建立一個與模型互動的線程。


定義並執行助手

現在,定義一個用於執行助手的函數。

def check_and_run_assistant():
    logger.info("Checking and running assistant")

    # Send 'CHECK' message to the assistant
    message = openai_client.beta.threads.messages.create(
        thread_id=thread.id,
        role="user",
        content="CHECK",
    )

    # Execute Agent
    run = openai_client.beta.threads.runs.create(
        thread_id=thread.id,
        assistant_id=assistant.id,
    )

    # Execute function calls
    run_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls(
        client=openai_client,
        run=run,
        thread=thread,
    )

# Run the assistant check every 10 seconds
while True:
    check_and_run_assistant()

這是上面程式碼中發生的事情。

  • 傳送「CHECK」訊息:這會向指定執行緒中的助手發送「CHECK」訊息,以確保模型回應。

  • 執行代理:使用指定的執行緒和助手 ID 為助手建立執行。

  • 處理工具呼叫:等待並處理助理使用 Composio 工具集發出的工具呼叫。

  • 循環代理:循環代理,使其持續運作並監控您的工作流程。

最後,透過執行 Python 文件來執行該文件,讓你的新 AI 朋友讓你專注於你的目標。

代理會監視您的螢幕,並在發現您做了不應該做的事情時發送通知。

完整的程式碼可以在這裡找到

這是一個正在執行的代理的範例。

{% 嵌入 https://x.com/KaranVaidya6/status/1820129229683454160 %}


下一步

在本文中,您建立了可以監控您活動的個人化 AI 朋友。但是,加入外部整合(例如日曆或 Gmail 工具)可以使其更加有用。這可以讓您知道您是否有一些活動要參加或有重要的電子郵件要回覆。

您可以使用 Composio 的廣泛整合(從 GitHub 和 Calendar 到 Slack、Discord 等)輕鬆完成此任務。

如果你想看更多 AI 相關的文章,請在評論中告訴我,並在 GitHub 上給我們一個 star。

{% cta https://dub.composio.dev/aifrnd %}為 Composio.dev 儲存庫加註星標 ⭐{% endcta %}

感謝您的閱讀!


原文出處:https://dev.to/composiodev/i-created-an-ai-companion-that-monitors-my-screen-and-helps-fix-my-screw-ups-144i


共有 0 則留言