Replies: 3 comments 1 reply
-
Did you take a look at the per request modifier param in add routes? It allows modifying the config based on the request |
Beta Was this translation helpful? Give feedback.
1 reply
-
And thank you for writing Poe the poet! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Closing as there's currently a way to do this |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using
add_routes
and would like to set pass aRunnableConfig
asserver_config
to the chain that depends on the contents of the request object (such as request headers).The only way I see to do this today is by using
APIHandler
directly, but it would be nice to still benefit fromadd_routes
. One solution would be to makeadd_routes
accept an additional optional parameter like:Which is then used in each relevant route handler like so:
I've implemented this with a local fork of the server.py module and would be happy to contribute a PR if the maintainers agree that it's a good solution?
Another approach would be to decompose
add_routes
into smaller reusable units, so a user can create their ownAPIHandler
object (potentially with custom extensions such as decorating in invoke method to derive server_config from the request) and recompose the behavior that want around it. This would be more powerful but require a larger refactor to expand the API surface area.Is there another way to approach this that I've missed?
For more context, my use case is that I want to add metadata to LangSmith traces that depends on the request headers, but one could easily image wanting to set other RunnableConfig attributes in the same way to control chain behavior.
Beta Was this translation helpful? Give feedback.
All reactions