LangServe access POST data in path function fast api #327
-
Hello. I'm sending this to the langserve endpoint
Currently my langchain route is
I intend to use the all_conversation_chats array to build a ChatMessageHistory and feed into the chat prompt template to the LLM How do I access the In other words, when I sent a frontend request, of say, LangServe "automagically" knows to look for the input field. When there are other fields, how do I access them? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hello! If I understood correctly, you're trying to access the payload fields on the backend of langserve and then do something with that in the context of runnables? If so, I don't have any simpler examples than this right now that does some LCEL manipulation: https://github.com/langchain-ai/langserve/blob/main/examples/passthrough_dict/server.py I'll try to add something simpler. Take a look at LCEL docs in langchain to create whatever runnable you need https://python.langchain.com/docs/expression_language/get_started. Once the runnable is created and is exposed via add_routes, it's interface is pretty standard and you can include the Here's an example fro the README.md
If you're looking for more examples of chat backend: Conversational retrieval Chat with history persisted on backend: Chat with history persisted on backend and user information from headers You then have an option of either persisting some information in temporary caches on the front end. or you can add a regular fast API endpoint to fetch chat history for a given session |
Beta Was this translation helpful? Give feedback.
-
@eyurtsev Thanks for the response.
Yep, exactly!
That'll be great. Will revisit the links for better understanding of the examples. |
Beta Was this translation helpful? Give feedback.
-
@eyurtsev I'm not sure what I may be doing wrong in this case, trying to follow the example in the https://github.com/langchain-ai/langserve/blob/main/examples/passthrough_dict/server.py
And then in the server.py, I have this
When I send this payload
I get
|
Beta Was this translation helpful? Give feedback.
-
Solved! Thank you. By printing the values, it means I can even simply do this in the chain.
Not sure why that didn't occur to me earlier. I've been obsessed looking for a solution via the Runnable*, yet I could just return the values I want. Sigh! |
Beta Was this translation helpful? Give feedback.
Hello! If I understood correctly, you're trying to access the payload fields on the backend of langserve and then do something with that in the context of runnables?
If so, I don't have any simpler examples than this right now that does some LCEL manipulation: https://github.com/langchain-ai/langserve/blob/main/examples/passthrough_dict/server.py
I'll try to add something simpler. Take a look at LCEL docs in langchain to create whatever runnable you need https://python.langchain.com/docs/expression_language/get_started.
Once the runnable is created and is exposed via add_routes, it's interface is pretty standard and you can include the
input
to the runnables via aninput
field in the post…