unit-mesh / auto-dev

🧙‍AutoDev: The AI-powered coding wizard(AI 驱动编程助手) with multilingual support 🌐, auto code generation 🏗️, and a helpful bug-slaying assistant 🐞! Customizable prompts 🎨 and a magic Auto Dev/Testing/Document/Agent feature 🧪 included! 🚀
https://ide.unitmesh.cc/
Mozilla Public License 2.0
2.72k stars 314 forks source link

ollama的本地大模型返回的数据不能格式化 #148

Closed yshuai closed 4 months ago

yshuai commented 4 months ago

Describe the bug ollama的本地大模型返回的数据不能格式化

To Reproduce Steps to reproduce the behavior:

  1. 我在本地用ollama搭建了本地deepseek-coder:6.7b 模型

  2. 尝试用了apifox创建快捷请求测试接口 http://localhost:11434/api/chat,可以正常返回数据。 image

  3. 把消息数据写在messageKeys时会报错,不能正常返回数据。 image

  4. 把消息数据写在messages时能正常返回数据,但不能格式化。 image 5.我尝试了多种response的匹配格式,$.message.content$..content等等, 都不能格式化,我看到右侧的聊天记录里,返回数据被套了一层'',不知道是不是返回格式有问题。

相关版本信息:

phodal commented 4 months ago
  1. messages 那里写错了,应该是 { "customFields": { "model":"deepseek-coder:6.7b", "stream": true}, "messageKeys": { "content": "content" }},详细参考一下文档:https://ide.unitmesh.cc/custom/llm-server#custom-llm-server-example
  2. 建议使用 stream 方式,非 stream 方式没有经过严格测试。
yshuai commented 4 months ago
  1. messages 那里写错了,应该是 { "customFields": { "model":"deepseek-coder:6.7b", "stream": true}, "messageKeys": { "content": "content" }},详细参考一下文档:https://ide.unitmesh.cc/custom/llm-server#custom-llm-server-example
  2. 建议使用 stream 方式,非 stream 方式没有经过严格测试。
  1. 现在复制粘贴了你贴的数据试了一遍,也是报错的,我应该也测试过你说的这种情况。 image

  2. 你说的这个文档,我看了好几遍了,能正常返回数据,而且我还换了好几种匹配格式测试,request的格式我应该没写错。response的格式不管我怎么换,都是报错,返回的在字符串里面的格式可以正确格式化吗?

phodal commented 4 months ago
  1. request 里还是少了 role,看文档:https://ide.unitmesh.cc/custom/llm-server#custom-llm-server-example
  2. response 格式看上去不对吧? $.choices[0].delta.content 是 OpenAI 返回的,你可以找个在线工具测试一下:https://jsonpath.com
yshuai commented 4 months ago
  1. request 里还是少了 role,看文档:https://ide.unitmesh.cc/custom/llm-server#custom-llm-server-example
  2. response 格式看上去不对吧? $.choices[0].delta.content 是 OpenAI 返回的,你可以找个在线工具测试一下:https://jsonpath.com

以下steam:falsesteam:true的结果一样,截图时截错了,就不改图了。

  1. 我从apifox测试的,role:user时能正常访问,在autodev里面测的时候,就会报400错误。 image

  2. 使用role:role时能返回数据,但是还是不能格式化。 image

  3. 我写的response的匹配没写错。$..content$.message.content这俩匹配结果都是一样的。 image

  4. 你看一下,这个json字符串包裹在''里面,格式正确吗? image

  5. 你这个文档的Custom response format标题里面的response格式就是错的。 image

phodal commented 4 months ago

如果出错的时候,LLM 返回结果是在 '' 里的:

https://github.com/unit-mesh/auto-dev/blob/3e890afd1d1fc8e1853481bf89c0d6c6e45c13bd/src/main/kotlin/cc/unitmesh/devti/llms/custom/ResponseBodyCallback.kt#L114

正确的错误返回应该是:Invalid sse format! 'Hello! xxxxxx'

如果 API 返回的信息都在 line 里,说明可能 '' 里可能是你的 LLM 返回的内容 —— 因为 LLM 复读了。 试试改完配置,再 New Chat

yshuai commented 4 months ago

如果出错的时候,LLM 返回结果是在 '' 里的:

https://github.com/unit-mesh/auto-dev/blob/3e890afd1d1fc8e1853481bf89c0d6c6e45c13bd/src/main/kotlin/cc/unitmesh/devti/llms/custom/ResponseBodyCallback.kt#L114

正确的错误返回应该是:Invalid sse format! 'Hello! xxxxxx'

如果 API 返回的信息都在 line 里,说明可能 '' 里可能是你的 LLM 返回的内容 —— 因为 LLM 复读了。 试试改完配置,再 New Chat

多谢解答,解决了,改完配置后,重启了一遍ollama,然后再把 自定义响应类型SSE改成JSON后,可以正常返回数据了。ollama 的stream只能用false,true就变成一个字一个字的回复了。 image