>  기사  >  백엔드 개발  >  내 화면을 모니터링하고 문제를 해결하는 데 도움이 되는 AI 동반자를 만들었습니다 ✨

내 화면을 모니터링하고 문제를 해결하는 데 도움이 되는 AI 동반자를 만들었습니다 ✨

PHPz
PHPz원래의
2024-08-09 07:46:02746검색

최근 나루토를 몰아보는 중독으로 인해 어려움을 겪고 있습니다. 즐겁기는 하지만 주주 가치를 전달하는 데는 확실히 도움이 되지 않습니다. ?

그러면 내 화면을 모니터링하고 애니메이션 시청과 같이 해서는 안 될 일을 과도하게 하고 있는지 알려주는 AI 개인 비서를 구축해 보는 것은 어떨까요? ?

지난해 AI의 급속한 발전을 고려하여 다중 모달 언어 모델을 사용하여 화면을 모니터링하고 비생산적인 활동에 너무 많은 시간을 소비하고 있을 때 알려 주기로 결정했습니다.

그래서 제가 한 방법은 이렇습니다.

  • OpenAI GPT-4o, 멀티모달 AI 모델을 구성하세요.
  • Composio의 화면 분석 도구를 사용하여 화면을 모니터링하세요.
  • 정기적으로 스크린샷을 GPT에 전달하세요.
  • GPT의 메시지를 시스템 알림으로 렌더링합니다.

I Created an AI Companion that Monitors My Screen and Helps Fix My Screw Ups ✨

이 글에서는 OpenAI와 Composio를 사용하여 개인 AI 친구를 구축하는 방법도 설명하겠습니다.


Composio - AI 에이전트 툴링 플랫폼

Composio는 AI 에이전트에 도구와 통합 기능을 제공하는 오픈 소스 플랫폼입니다. 코드 해석기, RAG, 임베딩과 같은 통합 도구와 GitHub, Slack, Jira 등과 같은 통합을 통해 AI 에이전트의 능력과 다양성을 확장할 수 있습니다.

I Created an AI Companion that Monitors My Screen and Helps Fix My Screw Ups ✨

별을 도와주세요. ?

이런 기사를 더 많이 만들면 도움이 될까요?

Composio.dev 저장소에 별표 표시 ⭐


AI 친구 만들기의 전제 조건

프로젝트를 성공적으로 완료하려면 다음이 필요합니다.

  • OpenAI SDK 및 API 키: LLM과 상호작용합니다.
  • Composio: 이미지 분석 도구에 접근합니다.
  • PyAutoGUI: 화면에서의 상호작용을 자동화합니다.
  • Osascript: macOS 애플리케이션 제어를 위해 AppleScript 명령을 실행합니다.

자, 시작해 보겠습니다.


시작해 볼까요?

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

이제 코딩 부분으로 이동할 준비가 되었습니다.


AI 친구 만들기

이제 환경 설정이 완료되었으니 코딩 부분으로 넘어가겠습니다.

먼저 라이브러리를 가져오고 도구 세트를 초기화합니다.

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의 인스턴스를 생성했습니다.
  • SYSTEMTOOLS 및 IMAGEANALYSERTOO에서 작업을 검색했습니다.

이러한 도구의 역할은 다음과 같습니다.

  • 시스템 도구: 시스템 도구에는 푸시 알림과 화면 캡처라는 두 가지 작업이 있습니다.
  • 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를 사용하여 어시스턴트에 대한 실행을 생성합니다.
  • Handle Tool Calls: Composio 툴셋을 사용하여 어시스턴트가 수행한 도구 호출을 기다리고 처리합니다.
  • 에이전트 루프: 에이전트를 루프하여 워크플로를 지속적으로 실행하고 모니터링합니다.

마지막으로 Python 파일을 실행하고 새로운 AI 친구가 목표에 집중할 수 있도록 하여 파일을 실행하세요.

에이전트는 귀하의 화면을 모니터링하며 귀하가 해서는 안 될 행동을 하는 것을 발견하면 알림을 보냅니다.

전체 코드는 여기에서 확인할 수 있습니다

다음은 에이전트의 작동 예시입니다.


다음 단계

이 기사에서는 귀하의 활동을 모니터링하는 맞춤형 AI 친구를 구축했습니다. 그러나 캘린더나 Gmail 도구와 같은 외부 통합을 추가하면 더욱 유용해질 수 있습니다. 이를 통해 참석해야 할 이벤트가 있는지 또는 응답해야 할 중요한 이메일이 있는지 알 수 있습니다.

GitHub, Calendar부터 Slack, Discord 등에 이르기까지 Composio의 광범위한 통합을 통해 쉽게 수행할 수 있습니다.

더 많은 AI 관련 글을 보고 싶으시다면 댓글로 알려주시고 GitHub에 별표를 남겨주세요.

Composio.dev 저장소에 별표 표시 ⭐

읽어주셔서 감사합니다! <script> // Detect dark theme var iframe = document.getElementById('tweet-1820129229683454160-179'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1820129229683454160&theme=dark" } </script>

위 내용은 내 화면을 모니터링하고 문제를 해결하는 데 도움이 되는 AI 동반자를 만들었습니다 ✨의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.