auto-dev icon indicating copy to clipboard operation
auto-dev copied to clipboard

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

Open yshuai opened this issue 2 years ago • 8 comments

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等等, 都不能格式化,我看到右侧的聊天记录里,返回数据被套了一层'',不知道是不是返回格式有问题。

相关版本信息:

  • OS: Windows10
  • autodev Version: intellij-autodev-1.8.1-241
  • IDEA Version [pycharm 2024.1]

yshuai avatar Apr 15 '24 20:04 yshuai

  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 方式没有经过严格测试。

phodal avatar Apr 16 '24 01:04 phodal

  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的格式不管我怎么换,都是报错,返回的在字符串里面的格式可以正确格式化吗?

yshuai avatar Apr 16 '24 02:04 yshuai

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

phodal avatar Apr 16 '24 03:04 phodal

  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:false和steam: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

yshuai avatar Apr 16 '24 03:04 yshuai

如果出错的时候,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

phodal avatar Apr 16 '24 04:04 phodal

如果出错的时候,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

yshuai avatar Apr 16 '24 04:04 yshuai

我使用的是最新的版本。

skytraveler avatar Feb 19 '25 09:02 skytraveler

持续404

skytraveler avatar Feb 19 '25 09:02 skytraveler