我受够了拖延症,所以开发了这个人工智能工具来提高我的工作效率!🫡
由 Mux 主办的 DEV 全球展示挑战赛:展示你的项目!
太长不看
最近我一直在拖延,沉迷于刷 Netflix,漫无目的地浏览社交媒体等等。
最终,我决定克服拖延症。还有什么比编写一个人工智能代理更好的方法呢?它可以督促我按计划行事,并定期提醒我是否应该开始沉迷于媒体消费。
我的做法是这样的。
- 配置 OpenAI GPT-4o,多模态 AI 模型。
- 使用屏幕分析工具监控屏幕。
- 定期将屏幕截图传递给 GPT。
- 将 GPT 生成的消息渲染为系统中的通知。
Composio——您的AI代理工具平台
以下是关于我们公司的简要介绍。
Composio 是一个开源工具基础设施,用于构建强大可靠的 AI 应用。我们提供 100 多种工具和集成方案,涵盖 CRM、HRM、销售、生产力、开发和社交媒体等各个行业领域。
他们还提供本地工具,例如代码分析器、RAG、SQL 等。
请给我们一颗星吧!🥹
这将有助于我们创作更多类似的文章💖
技术栈
要成功完成该项目,您需要以下物品。
- 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
要创建 OpneAI API 密钥,请访问官方网站并在控制面板中创建 API 密钥。
设置 Composio
您可以使用 CLI 轻松设置 Composio。
首先,运行以下命令登录您的帐户。
composio login
这将引导您登录/注册 Composio。
登录后,屏幕上会出现一个带有密钥的图标。
复制并粘贴到终端中。
现在,请更新应用程序。
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 的实例。
SYSTEMTOOLS从和中检索操作IMAGEANALYSERTOO。
那么,这些工具的功能如下。
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()
以上代码的运行过程如下。
- 发送“检查”消息:此操作会向指定线程中的助手发送“检查”消息,以确保模型有响应。
- 执行代理:使用指定的线程和助手 ID 为助手创建运行。
- 处理工具调用:等待并处理助手使用 Composio 工具集发出的工具调用。
- 循环运行代理:让代理循环运行,以便持续运行并监控您的工作流程。
最后,运行 Python 文件来执行该文件,让你的新 AI 朋友帮助你专注于你的目标。
该代理会监控您的屏幕,并在发现您进行不应进行的操作时发送通知。
完整的代码可以在这里找到。
以下是该代理运行的示例。👇
后续步骤
本文中,您创建了一个可以监控您活动的个性化 AI 助手。但是,添加外部集成,例如日历或 Gmail 工具,会更加实用。这样,您就可以知道是否有需要参加的活动或需要回复的重要邮件。
借助 Composio 的广泛集成,您可以轻松实现这一点,从 GitHub 和 Calendar 到 Slack、Discord 等等。
如果你想看更多人工智能相关的文章,请在评论区留言,并在 GitHub 上给我们点个赞。
感谢阅读!
文章来源:https://dev.to/composiodev/i-got-tired-of-procrastination-so-i-built-this-ai-tool-to-make-me-productive-32ld





