Windows下ollama + local_LLM + 自编的Agent
Download Ollama on Windows , 到这里直接下载安装 OllamaSetup.exe , 不要irm方式, 后面虽然可以任何身份安装,但还是右键的 以管理员身份,他自动安装找目录,建立PATH ,
C:\Users\Administrators----\AppData\Roaming\Microsoft\Windows\Start Menu\Programs , 中间有问答,设置上下文的长度等(暂时不管,后续改设置,代码中应该也行),这样的窗口出现不用管,启动后自动运行后台,Task manager可以见进程Ollama,
第一次在powershell中Ollama serve可以启动 服务,检测是否启动?
(base) PS C:\Users\Administrator---->ollama --version;ollama list
ollama version is 0.32.1
NAME ID SIZE MODIFIED
qwen2.5:7b 845dbda0ea48 4.7 GB 3 days ago (没pull前这里是没有的)
ollama不要用conda方式安装,因为比较“installer直接安装“,conda的没优化好。后,开始进Conda ENV必须 建立新ENV、python版本不能低了。
(base) PS C:\Users\Administrator---->conda create -n ollama_agent python=3.11 -y
(base) PS C:\Users\Administrator---->conda activate ollama_agent
(ollama_agent)> pip install langchain langchain-core langchain-ollama langchain-community ollama pydantic pydantic-core openai jupyter notebook (应该一次过,注意网络不要乱跑,限制其活动)
LLM pull安装
(base)>ollama pull qwen2.5:7b 这里不用在ENV下,可以任意terminal 去安装大模型,
代码测试,
如果是ollama自启动的进程关了,terminal单独的独立的窗口启动服务Ollama serve,
(base) PS C:\Users\Administrator---->Ollama serve
检测是否显示 ? source=routes.go:2004 msg="Listening on 127.0.0.1:11434 (version 0.32.1)"
应答后,窗口会显示客户端访问后的 运行记录,
彩色的一些状态标识,
编程测试
没涉及读写文件
文件操作测试 (单独的 llmagent目录下放这些代码)
这里代码中通过 WORKSPACE_DIR = Path("./sandbox_workspace").resolve(), 自动建立目录后,读写文件在这个沙盒中,超过自动报警。
my_ai_project/
│
├── main_agent_script.py <-- You save and run your Python code here
└── sandbox_workspace/ <-- Automatically created by the script!
├── calculator.py <-- Code written by the AI agent goes here ,创建的, 一条问答下
└── analytics.py <-- Other agent files go here ,读后再复写的, 第2条问答下