Langchain ChatOllama持续抛出invalid format: expected "json"错误的求助
Langchain ChatOllama持续抛出invalid format: expected "json"错误的求助
我正在跟着基础的LangChain教程做本地RAG,写了一段非常简单的代码:
from langchain_ollama import ChatOllama import logging logging.basicConfig( level=logging.DEBUG, format='%(asctime)s.%(msecs)03d [%(levelname)s]: %(message)s', datefmt='%H:%M:%S' ) logging.info("### Starting up") llm = ChatOllama( model="llama3.1", ) response_message = llm.invoke( "What are you?" ) print(response_message.content)
不管我怎么调整写法,都会遇到这个错误:
Exception has occurred: ResponseError invalid format: expected "json" or a JSON schema File "C:\XXXX\local_rag\main.py", line 16, in <module> response_message = llm.invoke( ^^^^^^^^^^^ ollama._types.ResponseError: invalid format: expected "json" or a JSON schema
我试过好几种方案,包括使用messages数组、PromptTemplate、流式输出等,但每次都是同样的错误。不过直接调用Ollama的REST API是完全正常的,比如:
curl http://localhost:11434/api/chat -d '{ "model": "llama3.1", "messages": [ { "role": "user", "content": "why is the sky blue?" } ] }'
真心希望是我哪里犯了低级错误,求各位帮忙看看!
补充说明:
后来发现Ollama的版本会影响这个问题,另外按照评论里的建议设置llm.format = None也能解决这个问题。
备注:内容来源于stack exchange,提问作者Kam
相关产品推荐
相关产品推荐

