參考:Datawhale wow agent day12
適用於 python 3.9+
pip install metagpt==0.8.0
根據Metagpt教程。
步驟#
-
創建 python 3.9 的虛擬環境:conda create -n metagpt python=3.9 && conda activate metagpt
-
pip install metagpt
-
metagpt --init-config 生成 yaml 文件。在 config 的文件夾下的 config2.yaml 裡填寫 API 配置。
我這裡是本地配置 ollama:
llm:
api_type: 'ollama'
base_url: 'http://192.168.0.70:11434/api'
model: 'qwen2:7b'repair_llm_output: true
代碼中 192.168.0.70 就是部署了大模型的電腦的 IP,
請根據實際情況進行替換
檢驗#
from metagpt.config2 import Config
def print_llm_config():
# 加載默認配置
config = Config.default()
# 獲取LLM配置
llm_config = config.llm
# 打印LLM配置的詳細信息
if llm_config:
print(f"API類型: {llm_config.api_type}")
print(f"API密鑰: {llm_config.api_key}")
print(f"模型: {llm_config.model}")
else:
print("沒有配置LLM")
if __name__ == "__main__":
print_llm_config()