我正在尝试返回 llama_index 的结果
index.query(query, streaming=True)
.
但不知道该怎么做。
这个显然不行。
index = GPTSimpleVectorIndex.load_from_disk(index_file)
return index.query(query, streaming=True)
错误信息:
TypeError: cannot pickle 'generator' object
.
这个也不是。
def stream_chat(query: str, index):
for chunk in index.query(query, streaming=True):
print(chunk)
content = chunk["response"]
if content is not None:
yield content
# in another function
index = GPTSimpleVectorIndex.load_from_disk(index_file)
return StreamingResponse(stream_chat(query, index), media_type="text/html")
错误信息:
TypeError: 'StreamingResponse' object is not iterable
.
谢谢!
好吧,我明白了。
答案是
return StreamingResponse(index.query(query, streaming=True).response_gen)
你能给我详细的答案吗