教程摘要
本教程将带领你完成从环境配置到模型部署的全流程,让你能够:
- 在 AutoDL 平台上快速搭建训练环境
- 使用 LLaMA-Factory 进行大模型微调
- 将训练好的模型导出并部署为 API 服务
- 通过简单的 Python 代码实现与模型的对话
无需深度学习背景,跟着教程一步步操作,即可打造属于你的专属 AI 助手!
bash /root/LLaMA-Factory/chuli/转移.sh
bash /root/LLaMA-Factory/chuli/单多轮脚本/DD.sh
bash /root/LLaMA-Factory/chuli/one.sh
在 Web 界面中:
001
检查点设置:
001
在 Web 界面中:
创建导出目录:
/root/autodl-tmp/xxx
xxx
开始导出:
/root/autodl-tmp/xxx
修改 api.sh
:
model_name_or_path
改为 /root/autodl-tmp/xxx
template
改为 webui 中高级设置中的提示模板新建终端并运行:
bash /root/LLaMA-Factory/api.sh
http://0.0.0.0:6006
表示输出成功
import openai
import sys
api_key = "EMPTY"
openai.api_base = "你的AUtodl自定义服务里面的网址/v1"
def chat_with_gpt3_5(messages):
response = openai.ChatCompletion.create(
model="xxx",
messages=messages,
api_key=api_key,
stream=True # 启用流式输出
)
full_response = ""
for chunk in response:
if 'choices' in chunk and len(chunk['choices']) > 0:
content = chunk['choices'][0].get('delta', {}).get('content', '')
if content:
print(content, end='', flush=True)
full_response += content
print()
return full_response
conversation = [
{"role": "system", "content": "你是一个聪明的AI"}
]
while True:
user_input = input("You: ")
if user_input.lower() == '退出':
print("Assistant: 再见!")
break
conversation.append({"role": "user", "content": user_input})
print("Assistant: ", end='', flush=True)
assistant_message = chat_with_gpt3_5(conversation)
conversation.append({"role": "assistant", "content": assistant_message})
你的AUtodl自定义服务里面的网址
替换为 webui 的网址