Replies: 3 comments 3 replies
-
🤖 Hey @kcole93! Good to see you back here. Hope you're doing well and your coding adventures are exciting as always. Let's dive into this new issue! To modify the output schema of the In your case, you want to include the context and the URLs pointing to the origin of the source documents. To achieve this, you can modify your Here's an example of how you can modify your def format_docs(docs):
formatted_docs = "\n\n".join(doc.page_content for doc in docs)
urls = [doc.url for doc in docs] # assuming each doc has a 'url' attribute
return formatted_docs, urls Then, you can modify your rag_chain_from_docs = (
RunnablePassthrough.assign(context=(lambda x: format_docs(x["context"])[0]))
| custom_rag_prompt
| llm
| StrOutputParser()
| RunnablePassthrough.assign(urls=(lambda x: format_docs(x["context"])[1]))
) In this code, Please note that this is a simplified example and you might need to adjust it according to your specific requirements and the structure of your documents. As for including the context in the output, you can do this by modifying the rag_chain_with_source = RunnableParallel(
{"context": retriever, "question": RunnablePassthrough(), "urls": RunnablePassthrough()}
).assign(answer=rag_chain_from_docs) In this code, I hope this helps! If you have any further questions, feel free to ask. For more information on how to use output parsers in LangChain, you can refer to the LangChain documentation. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm running into the same problem, did you figure out a solution? the solution proposed by dosubot doesn't help because the chain is already returning the context, but the langserve APIHandler is not passing the context along with the answer. |
Beta Was this translation helpful? Give feedback.
-
I'm having the same problem |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to wrap my head around how to modify the schema of the output returned by the
invoke
endpoint exposed by LangServe.I believe this is the relevant portion of my
chain.py
file inside my LangServe app:The response from returned from this chain by the API has the shape of:
I want to return not just the question and answer, but also context -- more specifically, I want to process the context returned to extract values from the source documents' metadata (urls pointing to their origin), and return this as either output or metadata for each call to the invoke endpoint. So far, I haven't been able to understand how to modify the schema of the output.
I'd appreciate any tips on where changes can be made to the output's schema! Thanks!
Beta Was this translation helpful? Give feedback.
All reactions