OpenManus

一、miniconda環(huán)境

Miniconda 是一個輕量級的 Anaconda 發(fā)行版,它只包含了 Conda 包管理器和 Python,而 Anaconda 則包含了大量的科學計算和數(shù)據(jù)分析相關的庫。以下為你分別介紹在不同操作系統(tǒng)上安裝 Miniconda 的步驟:

Windows 系統(tǒng)

  1. 下載安裝包
    • 訪問 Miniconda 官方下載頁面。
    • 根據(jù)你的系統(tǒng)是 32 位還是 64 位,選擇對應的 Windows 安裝包進行下載。通常推薦 64 位版本。
  2. 運行安裝程序
    • 雙擊下載好的 .exe 文件,啟動安裝程序。
    • 在安裝向?qū)е?,按照提示逐步進行操作。
      • 選擇安裝路徑:可以選擇默認路徑,也可以自定義安裝位置。
      • 配置環(huán)境變量:建議勾選 “Add Miniconda3 to my PATH environment variable” 選項,這樣可以在命令提示符中直接使用 conda 命令。不過,官方文檔指出這種方式可能會影響其他軟件的運行,你也可以選擇在安裝完成后手動配置環(huán)境變量。
      • 選擇默認 Python 版本:根據(jù)自己的需求選擇合適的 Python 版本。
  3. 完成安裝
    • 等待安裝過程完成,點擊 “Finish” 結束安裝。
  4. 驗證安裝
    • 打開命令提示符,輸入以下命令:
conda --version

如果安裝成功,會顯示 Conda 的版本號。
  1. 創(chuàng)建環(huán)境
    修改conda下載鏡像為國內(nèi)鏡像(channels),修改環(huán)境下載依賴的目錄(envs_dirs),在conda安裝目錄找到.condarc文件,修改為如下內(nèi)容:
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 命令來創(chuàng)建一個 Python 版本為 3.12.0 的新環(huán)境,以下是詳細步驟及示例代碼。
在終端中輸入以下命令來創(chuàng)建一個名為 py312_env(你可以根據(jù)需求替換為自己想要的環(huán)境名稱),且 Python 版本為 3.12.0 的新環(huán)境:

conda create -n py312_env python=3.12.0
  • -n--name:用于指定新環(huán)境的名稱,這里指定為 py312_env。
  • python=3.12.0:明確指定要安裝的 Python 版本為 3.12.0。
  1. 確認環(huán)境
    執(zhí)行上述命令后,conda 會分析所需的依賴項,并顯示一個包含要安裝的包及其版本的列表,同時詢問你是否繼續(xù)安裝。你可以輸入 y 并按下回車鍵來確認安裝:
Proceed ([y]/n)? y
  1. 激活新環(huán)境
    創(chuàng)建完成后,需要激活這個新環(huán)境才能使用其中安裝的 Python 版本。不同操作系統(tǒng)的激活命令有所不同:
conda activate py312_env
  1. 停用環(huán)境
    當你完成工作后,可以使用以下命令停用當前激活的環(huán)境:
conda deactivate

二、安裝OpenManus

克隆倉庫:

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

安裝依賴:
pip install -r requirements.txt

OpenManus 需要配置使用的 LLM API,請按以下步驟設置:
在 config 目錄創(chuàng)建 config.toml 文件(可從示例復制):
copy config/config.example.toml config/config.toml
編輯 config/config.toml 添加 API 密鑰和自定義設置,使用國內(nèi)的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執(zhí)行搜索的時候,默認用的谷歌,但是國內(nèi)因為都知道的原因,根本訪問不了,所以需要把搜索引擎換成百度,將下面的代碼替換/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


我們輸入幾個問題試一下:
昨天突然發(fā)現(xiàn)北京的地上有冒頭的小草,贊美一下春天,保存到d盤下。

居然寫成了英文的,但是日期有誤:



第二個問題問北京天氣,需要聯(lián)網(wǎng)使用baidu搜索:



天氣信息準確

生成ppt測試:



執(zhí)行命令:pip install python-pptx
生成的文件如下:

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容