-
Here's my code:
Everything is working except I want the source documents and metadata returned. If I set as_json=True in StreamingResponse.from_chain it returns a ton of "token"s but it also includes the sources and metadata, but it's an unexpected response format. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The JSON response looks like this (maybe it's correct except the error at the end: {"token":" "}{"token":" I"}{"token":"'"}{"token":"m"}{"token":" happy"}{"token":" to"}{"token":" help"}{"token":" you"}{"token":" with"}{"token":" your"}{"token":" question"}{"token":"!"}{"token":" However"}{"token":","}{"token":" I"}{"token":" must"}{"token":" inform"}{"token":" you"}{"token":" that"}{"token":" M"}{"token":"oby"}{"token":" Dick"}{"token":" does"}{"token":" not"}{"token":" actually"}{"token":" kill"}{"token":" anyone"}{"token":" in"}{"token":" the"}{"token":" novel"}{"token":"."}{"token":" While"}{"token":" A"}{"token":"hab"}{"token":" is"}{"token":" obs"}{"token":"essed"}{"token":" with"}{"token":" hunting"}{"token":" and"}{"token":" killing"}{"token":" the"}{"token":" white"}{"token":" wh"}{"token":"ale"}{"token":","}{"token":" no"}{"token":" one"}{"token":" else"}{"token":" on"}{"token":" the"}{"token":" crew"}{"token":" is"}{"token":" har"}{"token":"med"}{"token":" or"}{"token":" killed"}{"token":" by"}{"token":" M"}{"token":"oby"}{"token":" Dick"}{"token":" directly"}{"token":"."}{"token":" In"}{"token":" fact"}{"token":","}{"token":" many"}{"token":" of"}{"token":" the"}{"token":" characters"}{"token":" on"}{"token":" the"}{"token":" ship"}{"token":" surv"}{"token":"ive"}{"token":" their"}{"token":" encounter"}{"token":" with"}{"token":" the"}{"token":" wh"}{"token":"ale"}{"token":" and"}{"token":" even"}{"token":" return"}{"token":" home"}{"token":" safely"}{"token":" after"}{"token":" their"}{"token":" journey"}{"token":"."}{"token":"\n"}{"token":"So"}{"token":" to"}{"token":" answer"}{"token":" your"}{"token":" question"}{"token":" directly"}{"token":","}{"token":" there"}{"token":" is"}{"token":" no"}{"token":" chapter"}{"token":" in"}{"token":" which"}{"token":" M"}{"token":"oby"}{"token":" Dick"}{"token":" k"}{"token":"ills"}{"token":" everyone"}{"token":"."}{"token":" The"}{"token":" novel"}{"token":"'"}{"token":"s"}{"token":" focus"}{"token":" is"}{"token":" more"}{"token":" on"}{"token":" A"}{"token":"hab"}{"token":"'"}{"token":"s"}{"token":" ob"}{"token":"session"}{"token":" and"}{"token":" his"}{"token":" un"}{"token":"wa"}{"token":"ver"}{"token":"ing"}{"token":" determ"}{"token":"ination"}{"token":" to"}{"token":" h"}{"token":"unt"}{"token":" down"}{"token":" and"}{"token":" kill"}{"token":" the"}{"token":" white"}{"token":" wh"}{"token":"ale"}{"token":","}{"token":" rather"}{"token":" than"}{"token":" any"}{"token":" actual"}{"token":" violence"}{"token":" or"}{"token":" harm"}{"token":" inf"}{"token":"lic"}{"token":"ted"}{"token":" by"}{"token":" the"}{"token":" wh"}{"token":"ale"}{"token":" itself"}{"token":"."}{"token":"\n"}{"token":"I"}{"token":" hope"}{"token":" this"}{"token":" helps"}{"token":" clarify"}{"token":" things"}{"token":" for"}{"token":" you"}{"token":"!"}{"token":" Let"}{"token":" me"}{"token":" know"}{"token":" if"}{"token":" you"}{"token":" have"}{"token":" any"}{"token":" other"}{"token":" questions"}{"token":"."}{"token":"","source_documents":[{"page_content":"Chapter 41. Moby Dick.\n\nI, Ishmael, was one of that crew; my shouts had gone up with the rest; my oath had been welded with theirs; and stronger I shouted, and more did I hammer and clinch my oath, because of the dread in my soul. A wild, mystical, sympathetical feeling was in me; Ahab’s quenchless feud seemed mine. With greedy ears I learned the history of that murderous monster against whom I and all the others had taken our oaths of violence and revenge.","metadata":{"source":"/Users/rah/titleDownloads/2c169b4c-8e8d-4dd4-8b57-82d5a21e4a1b/fae7a981-6f18-423d-b8e1-a7b0c73101fc.html"}},{"page_content":"Chapter 41. Moby Dick.\n\nI, Ishmael, was one of that crew; my shouts had gone up with the rest; my oath had been welded with theirs; and stronger I shouted, and more did I hammer and clinch my oath, because of the dread in my soul. A wild, mystical, sympathetical feeling was in me; Ahab’s quenchless feud seemed mine. With greedy ears I learned the history of that murderous monster against whom I and all the others had taken our oaths of violence and revenge.","metadata":{"source":"/Users/rah/titleDownloads/2c169b4c-8e8d-4dd4-8b57-82d5a21e4a1b/47.html"}},{"page_content":"it. All that most maddens and torments; all that stirs up the lees of things; all truth with malice in it; all that cracks the sinews and cakes the brain; all the subtle demonisms of life and thought; all evil, to crazy Ahab, were visibly personified, and made practically assailable in Moby Dick. He piled upon the whale’s white hump the sum of all the general rage and hate felt by his whole race from Adam down; and then, as if his chest had been a mortar, he burst his hot heart’s shell upon it.","metadata":{"source":"/Users/rah/titleDownloads/2c169b4c-8e8d-4dd4-8b57-82d5a21e4a1b/fae7a981-6f18-423d-b8e1-a7b0c73101fc.html"}},{"page_content":"it. All that most maddens and torments; all that stirs up the lees of things; all truth with malice in it; all that cracks the sinews and cakes the brain; all the subtle demonisms of life and thought; all evil, to crazy Ahab, were visibly personified, and made practically assailable in Moby Dick. He piled upon the whale’s white hump the sum of all the general rage and hate felt by his whole race from Adam down; and then, as if his chest had been a mortar, he burst his hot heart’s shell upon it.","metadata":{"source":"/Users/rah/titleDownloads/2c169b4c-8e8d-4dd4-8b57-82d5a21e4a1b/47.html"}}]}One output key expected, got dict_keys(['answer', 'source_documents', 'generated_question']) So, maybe it's supposed to do this but I get "Unrecognized response type; displaying content as text.", using Swagger to test, and there is the "One output key expected, got dict_keys(['answer', 'source_documents', 'generated_question'])" at the end of the response that concerns me. |
Beta Was this translation helpful? Give feedback.
-
I fixed the "One output key expected" error by simply adding the output_key parameter to the ConversationSummaryBufferMemory:
Now, how do I get valid JSON back? Or is this the way JSON is streamed in response, but Swaggar just can't handle it? |
Beta Was this translation helpful? Give feedback.
Ok, now I have finally resolved it, by adding the correct media_type to the StreamingResponse: