Linux中使用Qwen模型:Qwen Code CLI工具
目录
- Linux中使用Qwen模型:Qwen Code CLI工具
- 1)环境安装
- (1)安装Node.js
- (2)安装Qwen Code CLI
- 2)API 配置
- (1)获取API Key
- (2)设置环境变量:API和模型
- 3)使用Qwen Code CLI
- (1)运行Qwen Code CLI
- (2)使用Qwen Code CLI
.
Linux中使用Qwen模型:Qwen Code CLI工具
.
在Linux中使用Qwen模型,可以安装Qwen Code 命令行工具来使用。
Qwen Code 是一款改编自 Gemini CLI 的命令行 AI 工作流工具(更多详细信息,请参阅本文档),针对 Qwen3-Coder 模型进行了优化,并增强了解析器支持和工具支持。
.
1)环境安装
(1)安装Node.js
Qwen Code 要求 Node.js 版本 >= 20
安装或升级 Node.js:使用 nvm 管理,环境变量可以添加到~/.bashrc中永久生效。
# 安装nvm
curl -o install_nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh
bash install_nvm.sh# 生效nvm环境
export NVM_DIR="$HOME/.nvm"
source "$NVM_DIR/nvm.sh"# 安装Node.js 20
nvm install 20
nvm use 20
验证是否安装成功:
node -v
npm -v
(2)安装Qwen Code CLI
安装:(运行时执行qwen即可)
# 方式 1:全局安装(推荐)
npm install -g @qwen-code/qwen-code# 方式 2:源码安装(可选)
git clone https://github.com/QwenLM/qwen-code.git
cd qwen-code
npm install
npm install -g .
验证是否安装成功:
qwen --version
.
2)API 配置
设置您的 Qwen API 密钥(在 Qwen Code 项目中,您也可以在 .env
文件中设置您的 API 密钥)。.env
文件应放置在当前项目的根目录中。
(1)获取API Key
-
中国大陆用户,请前往 https://bailian.console.aliyun.com/ 或 https://modelscope.cn/docs/model-service/API-Inference/intro 申请 API 密钥
-
非中国大陆用户,请前往 https://modelstudio.console.alibabacloud.com/ 申请 API 密钥
我参考了阿里云百炼–API认证获取:https://bailian.console.aliyun.com/?tab=api#/api 进行认证获取API Key。
(2)设置环境变量:API和模型
中国大陆,可以通过阿里云百炼平台使用Qwen3-Coder。
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
export OPENAI_MODEL="qwen3-coder-plus" # 或其他模型名
中国大陆,ModelScope 每天提供 2,000 次免费模型推理 API 调用
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://api-inference.modelscope.cn/v1"
export OPENAI_MODEL="Qwen/Qwen3-Coder-480B-A35B-Instruct" # 或其他模型
非中国大陆,可以通过阿里云modelstuido平台使用Qwen模型。
export OPENAI_API_KEY="your_api_key_here"
export OPENAI_BASE_URL="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
export OPENAI_MODEL="qwen3-coder-plus" # 或其他模型名
.
3)使用Qwen Code CLI
(1)运行Qwen Code CLI
# 进入安装目录运行qwen
cd your-path/qwen-code
qwen
如果前面没设置API Key和模型变量,这里同样可以设置:
API Key: <your_api_key> Base URL: <your_base_url> Model: "qwen3-coder-plus" # 或其他模型名
(2)使用Qwen Code CLI
出现以下内容,即可通过在命令行输入问题,使用Qwen Code CLI进行交互了。
██╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗
╚██╗ ██╔═══██╗██║ ██║██╔════╝████╗ ██║╚██╗ ██║ ██║██║ █╗ ██║█████╗ ██╔██╗ ██║██╔╝ ██║▄▄ ██║██║███╗██║██╔══╝ ██║╚██╗██║
██╔╝ ╚██████╔╝╚███╔███╔╝███████╗██║ ╚████║
╚═╝ ╚══▀▀═╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═══╝Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. /help for more information.Using 1 QWEN.md file
╭─────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Type your message or @path/to/file |
╰─────────────────────────────────────────────────────────────────────────────────────────────╯~/qwen-code no sandbox (see qwen3-coder-plus (100% context left| ✖ 1 error (ctrl+o for
(main*) /docs) details)
简单示例:输入问题“qwen3-coder-plus是一个什么类型的模型?”
╭────────────────────────────────────────────╮
│ > qwen3-coder-plus是一个什么类型的模型? │
╰────────────────────────────────────────────╯✦ qwen3-coder-plus 是阿里巴巴通义千问系列中的一个代码生成模型。它是 qwen3 系列模型的增强版本,专门针对代码生成任务进行了优化和加强。相比基础版本,它可能在代码理解、多语言支持、复杂逻辑推理以及生成代码的质量和准确性方面有显著提升。如果你正在使用或开发基于该模型的应用,可以告诉我具体的需求或问题,我会尽力提供帮助。Using 1 QWEN.md file
╭──────────────────────────────────────────────────────────╮
│ > Type your message or @path/to/file │
╰──────────────────────────────────────────────────────────╯
.
声明:资源可能存在第三方来源,若有侵权请联系删除!