OpenManus

作者: 梅西爱骑车 | 来源:发表于2025-03-10 15:54 被阅读0次

    一、miniconda环境

    Miniconda 是一个轻量级的 Anaconda 发行版,它只包含了 Conda 包管理器和 Python,而 Anaconda 则包含了大量的科学计算和数据分析相关的库。以下为你分别介绍在不同操作系统上安装 Miniconda 的步骤:

    Windows 系统

    1. 下载安装包
      • 访问 Miniconda 官方下载页面
      • 根据你的系统是 32 位还是 64 位,选择对应的 Windows 安装包进行下载。通常推荐 64 位版本。
    2. 运行安装程序
      • 双击下载好的 .exe 文件,启动安装程序。
      • 在安装向导中,按照提示逐步进行操作。
        • 选择安装路径:可以选择默认路径,也可以自定义安装位置。
        • 配置环境变量:建议勾选 “Add Miniconda3 to my PATH environment variable” 选项,这样可以在命令提示符中直接使用 conda 命令。不过,官方文档指出这种方式可能会影响其他软件的运行,你也可以选择在安装完成后手动配置环境变量。
        • 选择默认 Python 版本:根据自己的需求选择合适的 Python 版本。
    3. 完成安装
      • 等待安装过程完成,点击 “Finish” 结束安装。
    4. 验证安装
      • 打开命令提示符,输入以下命令:
    conda --version
    
    如果安装成功,会显示 Conda 的版本号。
    1. 创建环境
      修改conda下载镜像为国内镜像(channels),修改环境下载依赖的目录(envs_dirs),在conda安装目录找到.condarc文件,修改为如下内容:
    channels:
      - https://mirrors.aliyun.com/anaconda/pkgs/main
      - https://mirrors.aliyun.com/anaconda/pkgs/r
      - https://mirrors.aliyun.com/anaconda/pkgs/msys2
    show_channel_urls: true
    
    envs_dirs:
      - D:\work\code\miniconda\envs
    

    你可以使用 conda 命令来创建一个 Python 版本为 3.12.0 的新环境,以下是详细步骤及示例代码。
    在终端中输入以下命令来创建一个名为 py312_env(你可以根据需求替换为自己想要的环境名称),且 Python 版本为 3.12.0 的新环境:

    conda create -n py312_env python=3.12.0
    
    • -n--name:用于指定新环境的名称,这里指定为 py312_env
    • python=3.12.0:明确指定要安装的 Python 版本为 3.12.0。
    1. 确认环境
      执行上述命令后,conda 会分析所需的依赖项,并显示一个包含要安装的包及其版本的列表,同时询问你是否继续安装。你可以输入 y 并按下回车键来确认安装:
    Proceed ([y]/n)? y
    
    1. 激活新环境
      创建完成后,需要激活这个新环境才能使用其中安装的 Python 版本。不同操作系统的激活命令有所不同:
    conda activate py312_env
    
    1. 停用环境
      当你完成工作后,可以使用以下命令停用当前激活的环境:
    conda deactivate
    

    二、安装OpenManus

    克隆仓库:

    git clone https://github.com/mannaandpoem/OpenManus.git
    cd OpenManus
    

    安装依赖:
    pip install -r requirements.txt

    OpenManus 需要配置使用的 LLM API,请按以下步骤设置:
    在 config 目录创建 config.toml 文件(可从示例复制):
    copy config/config.example.toml config/config.toml
    编辑 config/config.toml 添加 API 密钥和自定义设置,使用国内的Qwen地址:

    # Global LLM configuration
    [llm]
    model = "qwen-plus"
    base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
    api_key = "sk-9edfe8758ac94d848e295*****"
    max_tokens = 4096
    temperature = 0.0
    
    # Optional configuration for specific LLM models
    [llm.vision]
    model = "qwen-plus"
    base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
    api_key = "sk-9edfe8758ac94d848ead********"
    

    这里有点需要注意,OpenManus执行搜索的时候,默认用的谷歌,但是国内因为都知道的原因,根本访问不了,所以需要把搜索引擎换成百度,将下面的代码替换/app/tool/google_search.py即可:

    import asyncio
    from typing import List
     
    from baidusearch.baidusearch import search
     
    from app.tool.base import BaseTool
     
     
    class GoogleSearch(BaseTool):
        name: str = "baidu_search"
        description: str = """Perform a Baidu search and return a list of relevant links.
    Use this tool when you need to find information on the web, get up-to-date data, or research specific topics.
    The tool returns a list of URLs that match the search query.
    """
        parameters: dict = {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "(required) The search query to submit to Baidu.",
                },
                "num_results": {
                    "type": "integer",
                    "description": "(optional) The number of search results to return. Default is 10.",
                    "default": 10,
                },
            },
            "required": ["query"],
        }
     
        async def execute(self, query: str, num_results: int = 10) -> List[str]:
            """
            Execute a Baidu search and return a list of URLs.
            Args:
                query (str): The search query to submit to Baidu.
                num_results (int, optional): The number of search results to return. Default is 10.
            Returns:
                List[str]: A list of URLs matching the search query.
            """
            # Run the search in a thread pool to prevent blocking
            loop = asyncio.get_event_loop()
            links = await loop.run_in_executor(
                None, lambda: [result['url'] for result in search(query, num_results=num_results)]
            )
     
            return links
    
    安装百度搜索
    pip install baidusearch

    最后,命令运行 OpenManus:

    python main.py
    

    我们输入几个问题试一下:
    昨天突然发现北京的地上有冒头的小草,赞美一下春天,保存到d盘下。

    居然写成了英文的,但是日期有误:



    第二个问题问北京天气,需要联网使用baidu搜索:



    天气信息准确

    生成ppt测试:



    执行命令:pip install python-pptx
    生成的文件如下:

    相关文章

      网友评论

          本文标题:OpenManus

          本文链接:https://www.haomeiwen.com/subject/srvymjtx.html