基于ollama部署微调模型
目标
基于ollama部署微调模型
修改gguf文件名
将之前的 model-unsloth.Q4_K_M.gguf 重命名为 echarts.gguf
创建一个Modelflie.txt
输入 FROM {绝对路径}\echarts.gguf
注意,wsl是将windows主机上的硬盘映射到了 /mnt 目录,因此需要做相应的修改,和否则无法检测。
安装echarts.gguf
ollama create echarts -f Modelflie.txt 将新模型的别名更改为echarts

命令台进行测试
ollama run echarts 运行这个命令,开始对话。

将AI给出的代码放入在线调试。

有一些不尽如人意,可能是没有给出数据的缘故。
API调试
修改传入参数,将model改为echarts,API访问成功。

编写Java代码
编写一个 askLocalEchartsModel 方法,传入prompt,固定model为微调后的Echarts模型。
按照API工具编写一个POST请求,得到返回值,并提取返回值,作为函数结果返回。
public static String askLocalEchartsModel(String prompt) throws IOException {
// 定义固定的URL
String urlString = "http://localhost:11434/api/generate";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置请求方法为POST
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json; utf-8");
conn.setRequestProperty("Accept", "application/json");
conn.setDoOutput(true);
// 创建要发送的JSON对象
JSONObject jsonInput = new JSONObject();
jsonInput.put("model", "Echarts");
jsonInput.put("prompt", prompt);
jsonInput.put("stream", false);
// 将JSON输入写入请求的输出流
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInput.toString().getBytes("utf-8");
os.write(input, 0, input.length);
}
// 读取响应内容
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
// 解析JSON响应并提取response字段
JSONObject jsonResponse = new JSONObject(response.toString());
return jsonResponse.getString("response");
}
}
结果
模型的训练结果不太如人意,深度学习模型为黑盒无法深入其中进行修改。
考虑使用向量数据库进行学习,达到增加模型专业知识的效果。
2083

被折叠的 条评论
为什么被折叠?



